Skip to content

Commit 9f5af97

Browse files
committed
config file done
now has config file for lookups and intervals
1 parent 977e10a commit 9f5af97

File tree

5 files changed

+99
-17
lines changed

5 files changed

+99
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,4 @@ Thumbs.db
9494
# Project Specific
9595
data_*.txt
9696
icon_*.png
97+
eClock.cfg

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,10 @@ A Dashboard for raspberry pi Module 3 with the Raspberry 7" Touch Screen
1414
* Saves data to JSON files so does not flood online services, called `data_*.txt`
1515
* Saves images to `icon_*.png`
1616
* Saves a backup of current data/images which are used incase of data update failure
17-
* *Config file coming soon*
17+
* Config file eClock.cfg, this is created using setup.py
1818

19+
## setup
20+
* Register with [OpenWeatherMap](http://www.openweathermap.org/)
21+
* run `setup.py` to create config file
22+
* read [Backlight Setup manual](BacklightControlNotes.md)
23+
* read [Auto run manual](AutorunNotes.md)

eClock.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import time
88
import datetime
99
import os
10+
import ConfigParser
1011
try:
1112
# Python2
1213
import Tkinter as tk
@@ -15,8 +16,11 @@
1516
# Python3
1617
import tkinter as tk
1718
from tkinter import Frame, Canvas
19+
1820
# MAKE SURE WE is in the correct directory
1921
os.chdir('/home/pi/dashdisplay')
22+
config = ConfigParser.ConfigParser()
23+
config.read('eClock.cfg')
2024

2125
def tick(tick_time1=''):
2226
try:
@@ -27,7 +31,7 @@ def tick(tick_time1=''):
2731
if tick_time2 != tick_time1:
2832
tick_time1 = tick_time2
2933
clock.config(text=tick_time2)
30-
fnGetTristanHome();
34+
fnGetOwnerHome();
3135
# calls itself every 200 milliseconds
3236
# to update the time display as needed
3337
min2=tick_time2.split(':')
@@ -157,9 +161,9 @@ def fnGetDlnaText():
157161
return 'DLNA Status: '+"\n"+ 'VID:'+mydlna[0]+' MP3:'+mydlna[1]
158162

159163

160-
def fnGetTristanHome():
164+
def fnGetOwnerHome():
161165
try:
162-
response = os.system('ping -c 1 -w1 wp8_tristancole > /dev/null 2>&1')
166+
response = os.system('ping -c 1 -w1 '+config.get('Owner','PhoneIP')+' > /dev/null 2>&1')
163167
if response == 0:
164168
#yes in
165169
bCloser.config(fg='green')

eClockDataGetter.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,49 @@
55
import time
66
import os
77
import shutil
8+
import ConfigParser
9+
810

911
# MAKE SURE WE is in the correct directory
1012
os.chdir('/home/pi/dashdisplay')
13+
config = ConfigParser.ConfigParser()
14+
config.read('eClock.cfg')
1115

1216

1317
def fnGetWeather():
14-
data_timediff = 24*3600
18+
data_timediff = int(config.get('Weather','Refresh'))*60
1519
try:
1620
data_timediff = int(time.time()) - int(os.path.getmtime('data_weather.txt'))
1721
except:
18-
data_timediff = 25*3600
22+
data_timediff = int(config.get('Weather','Refresh'))*61
1923

2024
try:
2125
if os.path.isfile ('data_weather.txt'): shutil.copyfile ('data_weather.txt', 'data_weather.old.txt')
2226
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)):
2428
#http://openweathermap.org/current#parameter
2529
#Ashburton:2656977
2630
#Downham Market:2651030
2731
# 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'
2933
response = urllib2.urlopen(url_to_call)
3034
json_obj = json.load(response)
3135
with open('data_weather.txt','w') as fp:
3236
json.dump(json_obj, fp)
3337

34-
if str(json_obj['name']) <> 'Ashburton':
38+
if str(json_obj['name']) <> config.get('Weather','TownName'):
3539
raise Exception("Incorrect Location")
3640
time.sleep(1)
3741

3842
fnGetWeatherIcon(json_obj['weather'][0]['icon'], 'weather')
3943

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'
4145
response = urllib2.urlopen(url_to_call)
4246
json_obj = json.load(response)
4347
with open('data_forcast.txt','w') as fp:
4448
json.dump(json_obj, fp)
4549

46-
if str(json_obj['city']['name']) <> 'Ashburton':
50+
if str(json_obj['city']['name']) <> config.get('Weather','TownName'):
4751
raise Exception("Incorrect Forcast Location")
4852
time.sleep(1)
4953

@@ -52,15 +56,15 @@ def fnGetWeather():
5256
fnGetWeatherIcon(json_obj['list'][2]['weather'][0]['icon'], 'forcast3')
5357
fnGetWeatherIcon(json_obj['list'][3]['weather'][0]['icon'], 'forcast4')
5458
fnGetWeatherIcon(json_obj['list'][4]['weather'][0]['icon'], 'forcast5')
55-
56-
59+
5760

5861
except Exception as z:
5962
print 'Error:fnGetWeather', z
6063
if os.path.isfile ('data_weather.old.txt'): shutil.copyfile('data_weather.old.txt','data_weather.txt')
6164
if os.path.isfile ('data_forcast.old.txt'): shutil.copyfile('data_forcast.old.txt','data_forcast.txt')
6265

6366

67+
6468
def fnGetWeatherIcon(value,target):
6569
try:
6670
if os.path.isfile ('icon_'+target+'.png'): shutil.copyfile ('icon_'+target+'.png', 'icon_'+target+'.old.png')
@@ -75,16 +79,16 @@ def fnGetWeatherIcon(value,target):
7579

7680

7781
def fnGetDlna():
78-
data_timediff = 24*3600
82+
data_timediff = int(config.get('DLNA','Refresh'))*60
7983
try:
8084
data_timediff = int(time.time()) - int(os.path.getmtime('data_dlna.txt'))
8185
except:
82-
data_timediff = 25*3600
86+
data_timediff = int(config.get('DLNA','Refresh'))*61
8387

8488
try:
8589
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')+'/'
8892
response = urllib2.urlopen(url_to_call)
8993
response_data = response.read()
9094
count_video = response_data.index("Video")

setup.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import os
2+
import ConfigParser
3+
4+
5+
# MAKE SURE WE is in the correct directory
6+
os.chdir('/home/pi/dashdisplay')
7+
config = ConfigParser.RawConfigParser()
8+
config.read('eClock.cfg')
9+
10+
def dovalue(nsection,nkey,nprompt):
11+
if config.has_section(nsection) == False:
12+
config.add_section(nsection)
13+
if config.has_option(nsection,nkey) == False:
14+
config.set(nsection,nkey,'')
15+
newvalue = raw_input(nprompt+' ['+config.get(nsection,nkey)+'] ?') or config.get(nsection,nkey)
16+
config.set(nsection,nkey,newvalue)
17+
18+
19+
print 'Raspberry PI Dash Display Setup'
20+
print 'from https://github.com/topcats/rpi_dashboard'
21+
print ''
22+
23+
print 'Setup config (y) ?'
24+
nully = raw_input('')
25+
if (nully == '' or nully == 'y'):
26+
#all ok
27+
print ''
28+
else:
29+
quit()
30+
31+
#Set Weather Stuff
32+
print 'Weather:'
33+
dovalue('Weather','appid','App ID')
34+
dovalue('Weather','TownID','Town ID')
35+
dovalue('Weather','TownName','Town Name')
36+
dovalue('Weather','Refresh','Refresh interval (minutes)')
37+
38+
#DLNA
39+
print 'DLNA'
40+
dovalue('DLNA','url','MiniDLNA Web Address')
41+
dovalue('DLNA','Refresh','Refresh interval (minutes)')
42+
43+
#User Stuff
44+
print 'Owner'
45+
dovalue('Owner','PhoneIP','Phone IP Address')
46+
dovalue('Owner','CheckInterval','Check interval (seconds)')
47+
48+
49+
#Office 365
50+
print 'Office 365'
51+
dovalue('Office365','email','Email Address')
52+
dovalue('Office365','password','Password')
53+
dovalue('Office365','Refresh','Refresh interval (minutes)')
54+
55+
56+
57+
#Save it
58+
print ''
59+
print 'New Config'
60+
for section in config.sections():
61+
print section
62+
for key, val in config.items(section):
63+
print ' '+key+ "\t = " + val
64+
nully = raw_input('All Ok (Enter y to save) ?')
65+
if (nully == 'y'):
66+
with open('eClock.cfg', 'wb') as configfile:
67+
config.write(configfile)
68+
print 'Saved'

0 commit comments

Comments
 (0)