Created
January 13, 2020 16:47
-
-
Save sijanec/80e29afdee185e708e59a5445794573a 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
import pygetwindow as gw | |
import requests | |
import time | |
import sys | |
#get sijaneciot from https://github.com/sijanec/sijaneciot | |
if len(sys.argv) < 5: | |
print("pametna_vrata client: v prihodnje lahko odgovore nastavis kot argumente") | |
ip = input("IP naslov sijaneciot: ") | |
gesl = input("geslo sijaneciot: ") | |
pijn = input("pin sijaneciot: ") | |
okn = input("okna z delom imajo v naslovu: ") | |
dilej = input("delay med http zahtevami na sijaneciot www api v sekundah: ") | |
else: | |
ip = sys.argv[1] | |
gesl = sys.argv[2] | |
pijn = sys.argv[3] | |
okn = sys.argv[4] | |
dilej = sys.argv[5] | |
print("vnos zabelezen") | |
r = requests.get('http://'+ip+'/api/pin?p='+pijn, auth=('sijaneciot', gesl)) | |
if r.status_code != 200: | |
print("napaka zahteve, koda odziva ni 200 ampak "+r.status_code+", spodaj je odziv, zapiram program") | |
print(r.text) | |
sys.exit() | |
if r.text == "1": | |
print("pin je trenutno 1, vrata so zaprta, ko bo 0, minimiziram okno") | |
odprl = False | |
if r.text == "0": | |
print("pin je trenutno 0, vrata so odprta, ko se zaprejo in spet odprejo, minimiziram okno") | |
odprl = True | |
while True: | |
r = requests.get('http://'+ip+'/api/pin?p='+pijn, auth=('sijaneciot', gesl)) | |
if r.text == "0" and odprl != True: | |
print("*** VRATA SO ODPRTA ***as") | |
for win in gw.getWindowsWithTitle(okn): | |
win.maximize() | |
odprl=True | |
time.sleep(float(dilej)) | |
if r.text == "1" and odprl != False: | |
print("vrata so spet zaprta, see ya") | |
for win in gw.getWindowsWithTitle(okn): | |
win.minimize() | |
odprl = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment