示例#1
0
	def send_text_to_me(self, text):
		try:
			for chat_id in self.config['telegram']['chats_id']:
				self.add_log("Trying Sending Message to Chat #{}: {}".format(chat_id, text))
				self.telepy.send_message(chat_id=chat_id, text=text)
				self.add_log("Telegram message correctly sended to chat id #{}: {}".format(chat_id, text))
				lcd_print('Telegram Message')
		except Exception as e:
			self.manage_exception(e)
示例#2
0
	def post_instagram(self, text):
		self.add_log("Trying post on Instagram: {}".format(timestamp()))
		pic_ok, image = self.take_picture()
		if pic_ok:
			with instapy(self.config['instagram']['username'], self.config['instagram']['password']) as instagram:
				instagram.upload(image, text)
				self.add_log("Post on Instagram: {} - {}".format(text, timestamp()))
				lcd_print('Instagram Post')
		else:
			self.add_log("Taken picture error - {}".format(timestamp()))
示例#3
0
def movement_alert(hydra, sensor_value):
    move_config = hydra.config['sensors']['movement']
    category = ev_movement(move_config, sensor_value)
    if category == 5 and move_config['active']:
        lcd_print('Movement alert\nactive')
        time.sleep(2)
        if hydra.config['telegram']['active']:
            hydra.send_text_to_me(get_phrase(category, 'mov'))
            hydra.send_picture_to_me()
        if hydra.config['twitter']['active']:
            hydra.post_twitter(get_phrase(category, 'mov'))
        print('Sleeping for 5 seconds')
        time.sleep(5)
示例#4
0
	def send_picture_to_me(self):
		ok, image_path = self.take_picture()
		if ok:
			try:
				for chat_id in self.config['telegram']['chats_id']:
					self.add_log("Trying Sending Photo to Chat #{}".format(chat_id))
					self.telepy.send_photo(chat_id=chat_id, photo=open(image_path, 'rb'))
					self.add_log("Telegram photo correctly sended to chat id #{}".format(chat_id))
					lcd_print('Photo Sended')
			except Exception as e:
				self.manage_exception(e)
		else:
			self.add_log("Picture to Telegram error - {}".format(timestamp()))
示例#5
0
	def post_twitter(self, text):
		try:
			self.add_log("Trying Posting on Twitter: {}".format(text))
			if len(text)<140:
				self.tweepy.update_status(text)
				self.add_log('Post on Twitter: {} - {}'.format(timestamp(), text))
				lcd_print('Twitter Post')
				return True
			else:
				print ("Text > 140 characters")
				return False
		except Exception as e:
			self.manage_exception('Twitter ' + str(e))
示例#6
0
	def take_picture(self):
		self.add_log("Trying to take a picture: {}".format(timestamp()))
		video_capture = cv2.VideoCapture(0)
		if not video_capture.isOpened():
			# raise Exception("Could not open video device")
			return False, None
		ret, frame = video_capture.read()
		video_capture.release()
		# im = Image.fromarray(crop_center(frame[:,:,::-1],350,350))
		im = Image.fromarray(frame[:,:,::-1])
		picture_name = "pictures/{}.png".format(self.photo_id)
		im.save(picture_name)
		self.photo_id += 1
		self.add_log("Picture {} taken: {}".format(self.photo_id, timestamp()))
		lcd_print('Picture Sended')
		return True, picture_name
示例#7
0
文件: main.py 项目: kwsp/COVID-LCD
def main():
    # Initialise GPIO pins
    print("Initialising GPIO")
    gpio_init()

    # Initialise display
    print("Initialising LCD")
    lcd_init()

    print("Getting covid data")
    #covid_data = covid_api.CovidData.from_worldometer_country()
    covid_data = covid_api.CovidData.from_api()
    last_update = time.time()

    while True:
        print("Printing data on LCD display")
        lcd_print(
            "US Cases:{:7}".format(covid_data.cases),
            "US Today:{:7}".format(covid_data.today),
        )

        time.sleep(4)

        lcd_print(
            "US Death:{:7}".format(covid_data.deaths),
            "US Recov:{:7}".format(covid_data.recovered),
        )

        new_time = time.time()
        if new_time - last_update > API_UPDATE_INTERVAL:
            print("Getting covid data")
            try:
                #covid_data = covid_api.CovidData.from_worldometer_country()
                covid_data = covid_api.CovidData.from_api()
            except Exception as e:
                print(
                    "Parsing worldometer failed, Caught exception: {}".format(
                        e))
                covid_data = covid_api.CovidData.na()

            last_update = new_time
        else:
            time.sleep(4)
示例#8
0
def main():
    d = identify.Identify()
    lcd.lcd_init()

    if d == -1:
        lcd.lcd_print("No Face Found")
        time.sleep(1)
        return 1

    if d == -2:
        lcd.lcd_print("No Internet Connection")
        return 1

    name = d['name']
    gender = d['gender']
    age = findAge(d['age'])
    smile = isSmiling(d['smile'])
    glasses = d['glasses']
    confidence = d['confidence']
    emotion = findMaxEmotion(d['emotion'])

    lcd.lcd_string("Uploading Data...")
    
    with open("index.xml", 'r+') as f:
        line = f.readline()
        index = int(line)

    fb = firebase.FirebaseApplication(URL)
    imageName = str(index)+".jpg"

    result = fb.put('/',index,{'name':name, 'gender':gender ,'age':age, 'smile':smile, 'glasses':glasses, 'confidence':confidence, 'emotion':emotion})

    status = 1

    try:
        status = subprocess.check_call(["./storage.sh",imageName])
    except:
        pass
    
    while status!=0:
        try:
            status = subprocess.check_call(["./storage.sh",imageName])
        except:
            pass

    index += 1
    with open("index.xml", 'w+') as f:
        f.write(str(index))

    lcd.lcd_string(name)
    if smile == "Yes":
        smile = "Smiling"
    else:
        smile = "Not Smiling"
    printString = "Age Range:" + str(age) + " " + str(gender) + " " + str(smile) + " " + str(glasses) + " Emotion:" + str(emotion)
    lcd.lcd_print(printString,2)
    lcd.lcd_clear()
    return 0
示例#9
0
	def run(self):
		lcd_print('Initializing\nhydra')
		self.add_log("Initializing Hydra - {}".format(timestamp()))
		ip = 'Local IP:\n' + self.get_ip()
		self.db.insert_log(ip)
		lcd_print(ip)
		time.sleep(5)
		self.set_config()
		i = 0
		self.add_log("Running - {}".format(timestamp()))
		lcd_print('hydra running')
		while self.active:
			self.set_config()
			success, sensors = self.read_serial()
			if success:
				self.db.insert_sensors(sensors)
			self.hydra.post_humidity(self, sensors['H'])
			self.hydra.post_temperature(self, sensors['T'])
			self.hydra.post_light(self, sensors['L'])
			self.hydra.post_ambient(self, sensors['A'])
			self.hydra.movement_alert(self, sensors['M'])
			i += 1
			time.sleep(1)
		self.add_log("Kernel disabled - {}".format(timestamp()))
def doTask():
    lcd.lcd_print("Taking Picture")
    takePicture()
    #time.sleep(1)
    newUser.main()
import newUser
import time
import lcd

THRESHOLD = 100


def takePicture():
    vc = cv2.VideoCapture(0)
    rval, frame = vc.read()
    if rval == True:
        cv2.imwrite("image.jpg", frame)


def doTask():
    lcd.lcd_print("Taking Picture")
    takePicture()
    #time.sleep(1)
    newUser.main()


if __name__ == "__main__":
    lcd.lcd_init()
    proximity.proximity_init()
    distance = proximity.proximity_getDistance()
    while True:
        if distance <= THRESHOLD:
            doTask()
        distance = proximity.proximity_getDistance()
        lcd.lcd_print("Waiting...")
        time.sleep(1)
示例#12
0
	def manage_exception(self, e):
		text = '({}) Error: {}'.format(timestamp(), str(e))
		self.add_log(text)
		self.send_text_to_me(text)
		lcd_print('Error Logged')
示例#13
0
	def lcd_print(self, text):		
		lcd_print(text)