5
5
import time
6
6
import os
7
7
import shutil
8
+ import ConfigParser
9
+
8
10
9
11
# MAKE SURE WE is in the correct directory
10
12
os .chdir ('/home/pi/dashdisplay' )
13
+ config = ConfigParser .ConfigParser ()
14
+ config .read ('eClock.cfg' )
11
15
12
16
13
17
def fnGetWeather ():
14
- data_timediff = 24 * 3600
18
+ data_timediff = int ( config . get ( 'Weather' , 'Refresh' )) * 60
15
19
try :
16
20
data_timediff = int (time .time ()) - int (os .path .getmtime ('data_weather.txt' ))
17
21
except :
18
- data_timediff = 25 * 3600
22
+ data_timediff = int ( config . get ( 'Weather' , 'Refresh' )) * 61
19
23
20
24
try :
21
25
if os .path .isfile ('data_weather.txt' ): shutil .copyfile ('data_weather.txt' , 'data_weather.old.txt' )
22
26
if os .path .isfile ('data_forcast.txt' ): shutil .copyfile ('data_forcast.txt' , 'data_forcast.old.txt' )
23
- if (data_timediff >= (1700 )):
27
+ if (data_timediff >= (int ( config . get ( 'Weather' , 'Refresh' )) * 60 )):
24
28
#http://openweathermap.org/current#parameter
25
29
#Ashburton:2656977
26
30
#Downham Market:2651030
27
31
# Get Weather, check for name and get icon image
28
- url_to_call = 'http://api.openweathermap.org/data/2.5/weather?id=2656977 &appid=08b5e93e4e18f3bb67193ab5fa179abc &units=metric'
32
+ url_to_call = 'http://api.openweathermap.org/data/2.5/weather?id=' + config . get ( 'Weather' , 'TownID' ) + ' &appid=' + config . get ( 'Weather' , 'appid' ) + ' &units=metric'
29
33
response = urllib2 .urlopen (url_to_call )
30
34
json_obj = json .load (response )
31
35
with open ('data_weather.txt' ,'w' ) as fp :
32
36
json .dump (json_obj , fp )
33
37
34
- if str (json_obj ['name' ]) <> 'Ashburton' :
38
+ if str (json_obj ['name' ]) <> config . get ( 'Weather' , 'TownName' ) :
35
39
raise Exception ("Incorrect Location" )
36
40
time .sleep (1 )
37
41
38
42
fnGetWeatherIcon (json_obj ['weather' ][0 ]['icon' ], 'weather' )
39
43
40
- url_to_call = 'http://api.openweathermap.org/data/2.5/forecast?id=2656977 &appid=08b5e93e4e18f3bb67193ab5fa179abc &units=metric'
44
+ url_to_call = 'http://api.openweathermap.org/data/2.5/forecast?id=' + config . get ( 'Weather' , 'TownID' ) + ' &appid=' + config . get ( 'Weather' , 'appid' ) + ' &units=metric'
41
45
response = urllib2 .urlopen (url_to_call )
42
46
json_obj = json .load (response )
43
47
with open ('data_forcast.txt' ,'w' ) as fp :
44
48
json .dump (json_obj , fp )
45
49
46
- if str (json_obj ['city' ]['name' ]) <> 'Ashburton' :
50
+ if str (json_obj ['city' ]['name' ]) <> config . get ( 'Weather' , 'TownName' ) :
47
51
raise Exception ("Incorrect Forcast Location" )
48
52
time .sleep (1 )
49
53
@@ -52,15 +56,15 @@ def fnGetWeather():
52
56
fnGetWeatherIcon (json_obj ['list' ][2 ]['weather' ][0 ]['icon' ], 'forcast3' )
53
57
fnGetWeatherIcon (json_obj ['list' ][3 ]['weather' ][0 ]['icon' ], 'forcast4' )
54
58
fnGetWeatherIcon (json_obj ['list' ][4 ]['weather' ][0 ]['icon' ], 'forcast5' )
55
-
56
-
59
+
57
60
58
61
except Exception as z :
59
62
print 'Error:fnGetWeather' , z
60
63
if os .path .isfile ('data_weather.old.txt' ): shutil .copyfile ('data_weather.old.txt' ,'data_weather.txt' )
61
64
if os .path .isfile ('data_forcast.old.txt' ): shutil .copyfile ('data_forcast.old.txt' ,'data_forcast.txt' )
62
65
63
66
67
+
64
68
def fnGetWeatherIcon (value ,target ):
65
69
try :
66
70
if os .path .isfile ('icon_' + target + '.png' ): shutil .copyfile ('icon_' + target + '.png' , 'icon_' + target + '.old.png' )
@@ -75,16 +79,16 @@ def fnGetWeatherIcon(value,target):
75
79
76
80
77
81
def fnGetDlna ():
78
- data_timediff = 24 * 3600
82
+ data_timediff = int ( config . get ( 'DLNA' , 'Refresh' )) * 60
79
83
try :
80
84
data_timediff = int (time .time ()) - int (os .path .getmtime ('data_dlna.txt' ))
81
85
except :
82
- data_timediff = 25 * 3600
86
+ data_timediff = int ( config . get ( 'DLNA' , 'Refresh' )) * 61
83
87
84
88
try :
85
89
if os .path .isfile ('data_dlna.txt' ): shutil .copyfile ('data_dlna.txt' , 'data_dlna.old.txt' )
86
- if (data_timediff >= (24 * 3600 )):
87
- url_to_call = 'http://localhost:8200 /'
90
+ if (data_timediff >= (int ( config . get ( 'DLNA' , 'Refresh' )) * 60 )):
91
+ url_to_call = 'http://' + config . get ( 'DLNA' , 'url' ) + ' /'
88
92
response = urllib2 .urlopen (url_to_call )
89
93
response_data = response .read ()
90
94
count_video = response_data .index ("Video" )
0 commit comments