-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfbprocess.py
More file actions
executable file
·69 lines (61 loc) · 1.31 KB
/
fbprocess.py
File metadata and controls
executable file
·69 lines (61 loc) · 1.31 KB
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
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
import FitBit
import yaml
import getopt
import sys
def usage():
pass
if __name__ == '__main__':
uname = ""
passw = ""
hname = ""
dbnam = ""
fname = ""
conf = ""
c = None
try:
opts,args = getopt.getopt(sys.argv[1:], "u:p:h:d:c:f:", ["config=","host=","user=",
"pass=", "db=","file="])
except getopt.GetoptError as err:
print >> sys.stderr, str(err)
usage()
sys.exit(1)
for o, a in opts:
if o in ("-c", "--config"):
conf = a
elif o in ("-u", "--user"):
uname = a
elif o in ("-p", "--pass"):
passw = a
elif o in ("-h", "--host"):
hname = a
elif o in ("-d", "--db"):
dbnam = a
elif o in ("-f", "--file"):
fname = a
else:
assert False, "unknown option"
# end command parsing
# load the config, but the options on the cli over-ride the config
if len(conf) > 0:
with open(conf,'r') as stream:
c = yaml.load(stream)
else:
with open("config.yml", 'r') as stream:
c = yaml.load(stream)
if len(uname) == 0:
uname = c['username']
if len(passw) == 0:
passw = c['password']
if len(hname) == 0:
hname = c['hostname']
if len(dbnam) == 0:
dbnam = c['database']
if len(fname) == 0:
fname = c['file']
fb = FitBit.FitBit()
fb.load_file(fname)
fb.connectdb(uname,passw,hname,dbnam)
fb.insert_data()
fb.dbcommit()
fb.dbclose()