forked from n0bel/PiClock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
58 lines (52 loc) · 1.6 KB
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sys
import os.path
import re
buttonFileName = 'Button/gpio-keys'
print "Checking " + buttonFileName
if os.path.isfile(buttonFileName):
try:
print "Setting proper permissions on " + buttonFileName
os.chmod(buttonFileName, 0744)
except:
pass
apikeysFileName = 'Clock/ApiKeys.py'
wuapi_re = re.compile('\\s*wuapi\\s*=')
dsapi_re = re.compile('\\s*dsapi\\s*=')
print "Checking " + apikeysFileName
if (os.path.isfile(apikeysFileName)):
altered = False
foundds = False
newfile = ''
apikeys = open(apikeysFileName, "r")
for aline in apikeys:
if dsapi_re.match(aline):
foundds = True
if wuapi_re.match(aline):
print "Removing wuapi key from " + apikeysFileName
altered = True
else:
newfile += aline
apikeys.close()
if not foundds:
print "This version of PiClock requires a DarkSky api key."
print "https://darksky.net/dev"
print "Enter your DarkSky api key."
print "key:",
k = sys.stdin.readline()
k = k.strip()
if len(k) > 1:
newfile += "dsapi = '" + k + "'"
altered = True
if altered:
print "Writing Updated " + apikeysFileName
apikeys = open(apikeysFileName, "w")
apikeys.write(newfile)
apikeys.close()
else:
print "No changes made to " + apikeysFileName
try:
from rpi_ws281x import * # NOQA
except:
print "NeoAmbi.py now uses rpi-ws281x/rpi-ws281x-python"
print "Please install it as follows:"
print "sudo pip install rpi_ws281x"