forked from niryariv/opentaba-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_db.py
More file actions
50 lines (38 loc) · 1.66 KB
/
update_db.py
File metadata and controls
50 lines (38 loc) · 1.66 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
#!/usr/bin/env python2
# allow ourselves to import from the parent and current directory
import sys
sys.path.insert(0, '../')
sys.path.insert(0, '.')
from lib.conn import *
from lib.gushim import GUSHIM
from optparse import OptionParser
parser = OptionParser()
parser.add_option("--force", dest="force", default=False, action="store_true", help="update gushim in db")
parser.add_option("-m", dest="municipality", help="name of the municipality this server should serve ('all' to serve all of them)")
(options, args) = parser.parse_args()
if not options.force:
print ("This script will update the gushim collection in the actual db. "
"To make sure this isn't running by mistake, run this with --force")
exit()
if not options.municipality:
print ("Parameter \"-m <specific-municipality | all>\" must be specified")
exit()
if options.municipality != "all" and options.municipality not in GUSHIM.keys():
print ("Municipality %s does not exist" % options.municipality)
exit()
gushim_collection = db.gushim.find()
existing_gushim = []
for g in gushim_collection:
existing_gushim.append(g['gush_id'])
total_gushim = len(existing_gushim)
for city in GUSHIM.keys():
if options.municipality == 'all' or city == options.municipality:
for g in GUSHIM[city]['list']:
if g not in existing_gushim:
print 'Inserting new gush id: ', g
db.gushim.insert({'gush_id': g,
'json_hash': '',
'last_checked_at': ''})
total_gushim += 1
existing_gushim.append(g)
print 'There are currently %s gushim' % str(total_gushim)