Last active
December 8, 2018 03:05
-
-
Save silvernoo/476646eb71a3c1485a7e5af0f2618375 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import math | |
import time | |
import datetime | |
import math | |
import json | |
import requests | |
from demo_opts import get_device | |
from luma.core.render import canvas | |
import RPi.GPIO as GPIO | |
import time | |
json_file = "/www/gen.txt" | |
r = 10 | |
counter = 0 | |
data = {} | |
def main(): | |
global counter | |
while True: | |
with canvas(device) as draw: | |
margin = 4 | |
cy = r | |
cy2 = device.height - r | |
cx = device.width - r | |
data2 = updateData(sum) | |
draw.text((0, 0), "AQI:" + | |
str(data2['aqi'][0]), fill="white") | |
wind_deg=data2['wind_deg'][0] | |
ex=cx+r*math.cos(wind_deg*math.pi/180) | |
ey=cy+r*math.sin(wind_deg*math.pi/180) | |
draw.line((cx, cy, ex, ey), fill="white") | |
draw.ellipse((cx - 2, cy - 2, cx + 2, cy + 2), fill="white") | |
draw.text((0, 12), "TEMP:" + str(data2['tmp'][0]) +"("+str(data2['fl'][0])+")" + ("-" if int(data2['fl'][0]) <= -5 and int(data2['wind_spd'][0]) >= 8 else "+"), fill="white") | |
draw.text((0, 24), str(data2['aria2Status']) , fill="white") | |
someone = bool(data2['someone']) | |
if someone: | |
draw.ellipse((cx - 2, cy2 - 2, cx + 2, cy2 + 2), fill="white") | |
requests.get('https://api.telegram.org/bot<TOKEN>/sendMessage?chat_id=-<CHAT_ID>&text=Someone%20at%20home', proxies=dict(https='socks5://127.0.0.1:1080'),timeout=3) | |
counter=counter+1 | |
if counter == 10000000: | |
counter = 0 | |
time.sleep(1) | |
def updateData(s): | |
global data | |
if counter%30==0: | |
json_data = open(json_file) | |
_json = json.load(json_data) | |
json_data.close() | |
data['aqi'] = str(_json['Aqi']['data']['aqi']), | |
data['tmp'] = _json['Weather']['HeWeather6'][0]['now']['tmp'], | |
data['fl'] = _json['Weather']['HeWeather6'][0]['now']['fl'], | |
data['wind_spd'] = _json['Weather']['HeWeather6'][0]['now']['wind_spd'], | |
data['wind_deg'] = int(_json['Weather']['HeWeather6'][0]['now']['wind_deg'])-90, | |
data['aria2Status'] = getAria2Status() | |
if counter%3==0: | |
data['someone'] = detct() | |
return data | |
def detct(): | |
if GPIO.input(11) == True: | |
return True | |
return False | |
param = ({ | |
"jsonrpc": "2.0", | |
"method": "aria2.tellActive", | |
"id": "QXJpYU5nXzE1NDM3NjU1MTBfMC4yNjIxODg3MTA3MjAxNTgxNQ==", | |
"params": [ | |
[ | |
"uploadSpeed", | |
"downloadSpeed" | |
] | |
]}) | |
def gpioInit(): | |
GPIO.setwarnings(False) | |
GPIO.setmode(GPIO.BOARD) | |
GPIO.setup(11, GPIO.IN) | |
pass | |
def getAria2Status(): | |
try: | |
r = requests.post("http://127.0.0.1:6800/jsonrpc", data=json.JSONEncoder().encode(param)) | |
js = r.json() | |
RX=0 | |
TX=0 | |
for i in range(len(js['result'])): | |
RX = RX+int(js['result'][i]['downloadSpeed']) | |
TX = TX+int(js['result'][i]['uploadSpeed']) | |
return "RX:"+str(int(int(RX)/1e3))+"KB"+"-TX:"+str(int(int(TX)/1e3))+"KB" | |
except BaseException: | |
return "" | |
if __name__ == "__main__": | |
#try: | |
device = get_device() | |
gpioInit() | |
main() | |
#except KeyboardInterrupt: | |
# pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment