From 4169ae5ae2e51c82674d81ed6b96170c81903a8e Mon Sep 17 00:00:00 2001 From: mytja <52399966+mytja@users.noreply.github.com> Date: Sat, 12 Sep 2020 19:41:09 +0200 Subject: [PATCH] Guinea pig 1.2.2 Guinea pig 1.2.2 What's new in this version? - Removed updater on boot (now you can directly run python3 my.py in .bashrc) - Added releases API with description and new functions, that release provides Thanks to @alexmercerind for submitting GitHub API in #61 --- my.py | 30 ++++++++++++++++++------- updateChecker.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 updateChecker.py diff --git a/my.py b/my.py index 995699e..67b932e 100644 --- a/my.py +++ b/my.py @@ -13,11 +13,14 @@ import StringToInteger as strtoint import _thread as thread from youtubesearchpython import searchYoutube +import updateChecker as uc alarm1 = [] alarm2 = [] alarm3 = [] +version = "guinea_1.2.2" + daysOfTheWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] monthsOfTheYear = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] @@ -176,20 +179,20 @@ def recognitionMode(recognitionint): global InternetMode InternetMode = recognitionint -def yesOrNo(): # Not in use +def yesOrNo(toAsk): with sr.Microphone() as source: playsound('media/beep_my.wav') print("I'm listening!") audio = r.listen(source) recognition = r.recognize_google(audio) + tts.say(toAsk) if recognition=="yes": - InternetMode = 1 My = False - tts.say("Ok. Switching to online mode") + return "yes" else: - InternetMode = 0 My = False - tts.say("Ok. Switching to offline mode") + return "no" + def MyMain(): print("I'm listening!") @@ -251,7 +254,7 @@ def MyMain(): tts.say("Electricity.") My = False elif mymainr=="version": - tts.say("Guinea pig 1.2") + tts.say(version) My = False elif mymainr=="what's your favorite food" or mymainr=="what is your favorite food": tts.say("I like pizza.") @@ -269,8 +272,19 @@ def MyMain(): elif mymainr=="reboot": os.system("sudo reboot") elif mymainr=="check for updates" or mymainr=="check for system updates" or mymainr=="update" or mymainr=="update your software": - os.system("./update-from-my") - kill-this-process() #this kills the process of My, because this function doesn't exist + uccheck = uc.checkForVersion("stable", version) + for item in uccheck: + updateAvaiable = item["update"] + desc = item["description"] + if (updateAvaiable=="y"): + assembly = "There is a new release avaiable" + str(description) + "Would you like to install it" + yn = yesOrNo(assembly) + if (yn == "yes"): + tts.say("Okay! Let's do it!") + os.system("cd /home/pi/Desktop/ && ./updater") + kill-this-process() #this kills the process of My, because this function doesn't exist + else: + tts.say("Okay, aborting mission") My = False elif mymainr=="higher volume" or mymainr=="louder" or mymainr=="volume up": os.system("cd /home/pi/Desktop/ && vol +") diff --git a/updateChecker.py b/updateChecker.py new file mode 100644 index 0000000..55e15b2 --- /dev/null +++ b/updateChecker.py @@ -0,0 +1,57 @@ +import requests +import json + +def getRidOf(text): + q = text.lower() + q = q.replace("g", "") + q = q.replace("u", "") + q = q.replace("i", "") + q = q.replace("n", "") + q = q.replace("e", "") + q = q.replace("a", "") + q = q.replace("_", "") + q = q.replace("b", "") + q = q.replace("t", "") + q = q.replace("l", "") + q = q.replace("s", "") + q = q.replace("v", "") + q = q.replace(".", "") + return q + +def checkForVersions(stability, currentTag): + i = True + r = requests.get("https://api.github.com/repos/mytja/MyAssistantOS-Raspbian/releases") + y = r.json() + for item in y: + if (i != False): + i = False + version = item["tag_name"] + author = item["author"]["login"] + target = item["target_commitish"] + description = item["body"] + + ver = int(getRidOf(version)) + curver = int(getRidOf(currentTag)) + + #print(ver) + #print(curver) + + if (ver < curver): + update = "y" + else: + update = "n" + + end = { + "update": update, + "branch": target, + "version": version, + "description": description, + "publisher": author, + "ver": ver + } + + finalJSON = json.dumps(end) + + return finalJSON + +checkForVersions("beta", "1.0.1")