Example #1
0
    def _messagetests(self, d):
        '''
		Run tests on a message to see if a specific one has been passed.
		If so, mark the test passed.

		:param bytes d: a data packet from the queue

		'''
        if 'TERM' in str(d):
            printM('Got TERM message...', sender=self.sender)
            t.TEST['c_TERM'][1] = True
            self.alive = False

        elif 'ALARM' in str(d):
            printM('Got ALARM message with time %s' %
                   (helpers.fsec(helpers.get_msg_time(d))),
                   sender=self.sender)
            t.TEST['c_ALARM'][1] = True

        elif 'RESET' in str(d):
            printM('Got RESET message with time %s' %
                   (helpers.fsec(helpers.get_msg_time(d))),
                   sender=self.sender)
            t.TEST['c_RESET'][1] = True

        elif 'IMGPATH' in str(d):
            printM('Got IMGPATH message with time %s' %
                   (helpers.fsec(helpers.get_msg_time(d))),
                   sender=self.sender)
            printM('and path %s' % (helpers.get_msg_path(d)),
                   sender=self.sender)
            t.TEST['c_IMGPATH'][1] = True
Example #2
0
	def _when_img(self, d):
		'''
		Send a tweet with an image in when you get an ``IMGPATH`` message.

		:param bytes d: queue message
		'''
		if self.tweet_images:
			imgpath = helpers.get_msg_path(d)
			imgtime = helpers.fsec(helpers.get_msg_time(d))
			message = '%s %s UTC' % (self.message1, imgtime.strftime(self.fmt)[:22])
			response = None
			if os.path.exists(imgpath):
				with open(imgpath, 'rb') as image:
					try:
						printM('Uploading image to Twitter %s' % (imgpath), self.sender)
						response = self.twitter.upload_media(media=image)
						time.sleep(5.1)
						printM('Sending tweet...', sender=self.sender)
						response = self.twitter.update_status(status=message, media_ids=response['media_id'],
																lat=rs.inv[0][0].latitude, long=rs.inv[0][0].longitude,
																geo_enabled=True, display_coordinates=True)
																# location will only stick to tweets on accounts that have location enabled in Settings
						printM('Tweeted with image: %s' % (message), sender=self.sender)
						url = 'https://twitter.com/%s/status/%s' % (response['user']['screen_name'], response['id_str'])
						printM('Tweet URL: %s' % url)
					except Exception as e:
						printE('could not send multimedia tweet - %s' % (e))
						try:
							printM('Waiting 5 seconds and trying to send tweet again...', sender=self.sender)
							time.sleep(5.1)
							self.auth()
							printM('Uploading image to Twitter (2nd try) %s' % (imgpath), self.sender)
							response = self.twitter.upload_media(media=image)
							time.sleep(5.1)
							printM('Sending tweet...', sender=self.sender)
							response = self.twitter.update_status(status=message, media_ids=response['media_id'],
																	lat=rs.inv[0][0].latitude, long=rs.inv[0][0].longitude,
																	geo_enabled=True, display_coordinates=True)
																	# location will only stick to tweets on accounts that have location enabled in Settings
							printM('Tweeted with image: %s' % (message), sender=self.sender)
							url = 'https://twitter.com/%s/status/%s' % (response['user']['screen_name'], response['id_str'])
							printM('Tweet URL: %s' % url)

						except Exception as e:
							printE('could not send multimedia tweet (2nd try) - %s' % (e))
							response = None

			else:
				printM('Could not find image: %s' % (imgpath), sender=self.sender)
Example #3
0
    def _when_img(self, d):
        '''
		Send a telegram image in when you get an ``IMGPATH`` message.

		:param bytes d: queue message
		'''
        if self.send_images:
            imgpath = helpers.get_msg_path(d)
            response = None
            if os.path.exists(imgpath):
                with open(imgpath, 'rb') as image:
                    try:
                        if not self.testing:
                            printM(
                                'Uploading image to Telegram %s' % (imgpath),
                                self.sender)
                            response = self.telegram.sendPhoto(
                                chat_id=self.chat_id, photo=image)
                            printM('Sent image', sender=self.sender)
                        else:
                            printM('Image ready to send - %s' % (imgpath),
                                   self.sender)
                            TEST['c_telegramimg'][1] = True
                    except Exception as e:
                        printE('Could not send image - %s' % (e))
                        try:
                            if not self.testing:
                                printM(
                                    'Waiting 5 seconds and trying to send again...',
                                    sender=self.sender)
                                time.sleep(5.1)
                                self.auth()
                                printM(
                                    'Uploading image to Telegram (2nd try) %s'
                                    % (imgpath), self.sender)
                                response = self.telegram.sendPhoto(
                                    chat_id=self.chat_id, photo=image)
                                printM('Sent image', sender=self.sender)
                            else:
                                # if you are here in testing mode, there is a problem
                                TEST['c_telegramimg'][1] = False
                        except Exception as e:
                            printE('Could not send image - %s' % (e))
                            response = None
            else:
                printM('Could not find image: %s' % (imgpath),
                       sender=self.sender)