Skip to content

Commit 4169ae5

Browse files
authored
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
1 parent e519d26 commit 4169ae5

File tree

2 files changed

+79
-8
lines changed

2 files changed

+79
-8
lines changed

my.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
import StringToInteger as strtoint
1414
import _thread as thread
1515
from youtubesearchpython import searchYoutube
16+
import updateChecker as uc
1617

1718
alarm1 = []
1819
alarm2 = []
1920
alarm3 = []
2021

22+
version = "guinea_1.2.2"
23+
2124
daysOfTheWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
2225
monthsOfTheYear = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
2326

@@ -176,20 +179,20 @@ def recognitionMode(recognitionint):
176179
global InternetMode
177180
InternetMode = recognitionint
178181

179-
def yesOrNo(): # Not in use
182+
def yesOrNo(toAsk):
180183
with sr.Microphone() as source:
181184
playsound('media/beep_my.wav')
182185
print("I'm listening!")
183186
audio = r.listen(source)
184187
recognition = r.recognize_google(audio)
188+
tts.say(toAsk)
185189
if recognition=="yes":
186-
InternetMode = 1
187190
My = False
188-
tts.say("Ok. Switching to online mode")
191+
return "yes"
189192
else:
190-
InternetMode = 0
191193
My = False
192-
tts.say("Ok. Switching to offline mode")
194+
return "no"
195+
193196

194197
def MyMain():
195198
print("I'm listening!")
@@ -251,7 +254,7 @@ def MyMain():
251254
tts.say("Electricity.")
252255
My = False
253256
elif mymainr=="version":
254-
tts.say("Guinea pig 1.2")
257+
tts.say(version)
255258
My = False
256259
elif mymainr=="what's your favorite food" or mymainr=="what is your favorite food":
257260
tts.say("I like pizza.")
@@ -269,8 +272,19 @@ def MyMain():
269272
elif mymainr=="reboot":
270273
os.system("sudo reboot")
271274
elif mymainr=="check for updates" or mymainr=="check for system updates" or mymainr=="update" or mymainr=="update your software":
272-
os.system("./update-from-my")
273-
kill-this-process() #this kills the process of My, because this function doesn't exist
275+
uccheck = uc.checkForVersion("stable", version)
276+
for item in uccheck:
277+
updateAvaiable = item["update"]
278+
desc = item["description"]
279+
if (updateAvaiable=="y"):
280+
assembly = "There is a new release avaiable" + str(description) + "Would you like to install it"
281+
yn = yesOrNo(assembly)
282+
if (yn == "yes"):
283+
tts.say("Okay! Let's do it!")
284+
os.system("cd /home/pi/Desktop/ && ./updater")
285+
kill-this-process() #this kills the process of My, because this function doesn't exist
286+
else:
287+
tts.say("Okay, aborting mission")
274288
My = False
275289
elif mymainr=="higher volume" or mymainr=="louder" or mymainr=="volume up":
276290
os.system("cd /home/pi/Desktop/ && vol +")

updateChecker.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import requests
2+
import json
3+
4+
def getRidOf(text):
5+
q = text.lower()
6+
q = q.replace("g", "")
7+
q = q.replace("u", "")
8+
q = q.replace("i", "")
9+
q = q.replace("n", "")
10+
q = q.replace("e", "")
11+
q = q.replace("a", "")
12+
q = q.replace("_", "")
13+
q = q.replace("b", "")
14+
q = q.replace("t", "")
15+
q = q.replace("l", "")
16+
q = q.replace("s", "")
17+
q = q.replace("v", "")
18+
q = q.replace(".", "")
19+
return q
20+
21+
def checkForVersions(stability, currentTag):
22+
i = True
23+
r = requests.get("https://api.github.com/repos/mytja/MyAssistantOS-Raspbian/releases")
24+
y = r.json()
25+
for item in y:
26+
if (i != False):
27+
i = False
28+
version = item["tag_name"]
29+
author = item["author"]["login"]
30+
target = item["target_commitish"]
31+
description = item["body"]
32+
33+
ver = int(getRidOf(version))
34+
curver = int(getRidOf(currentTag))
35+
36+
#print(ver)
37+
#print(curver)
38+
39+
if (ver < curver):
40+
update = "y"
41+
else:
42+
update = "n"
43+
44+
end = {
45+
"update": update,
46+
"branch": target,
47+
"version": version,
48+
"description": description,
49+
"publisher": author,
50+
"ver": ver
51+
}
52+
53+
finalJSON = json.dumps(end)
54+
55+
return finalJSON
56+
57+
checkForVersions("beta", "1.0.1")

0 commit comments

Comments
 (0)