-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_new_version.py
52 lines (44 loc) · 1.58 KB
/
save_new_version.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
import logging
import os
import sys
from google.appengine.api import memcache
ROOT_PATH = os.path.dirname(__file__)
sys.path.append(ROOT_PATH)
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'gaenv'))
import settings
from sources.datamodel import UPPER_WEEK
from sources.util import empty_data
from sources.versions import CURRENT_SOURCE
from sources.gsql_datastore import GsqlDataSource
def main():
site_ds = getattr(settings, 'IMPORT_SOURCE', None)
logging.info(site_ds)
if not site_ds:
site_ds = CURRENT_SOURCE()
max_groups = getattr(settings, 'MAX_GROUPS', 0)
collected = []
c = 0
for (gid, gname) in site_ds.group_ids():
gdata = site_ds.group_data(gid)
logging.info("%s: %s" %
(gid, gdata.week(UPPER_WEEK)[0][1].list()))
if not empty_data(gdata):
collected.append(site_ds.group_data(gid))
if max_groups:
if c < max_groups:
c += 1
else:
break
else:
logging.warn("Skipping group: %s %s %s" % (gid.faculty, gid.year, gid.group))
new_v = GsqlDataSource.save_new_version(site_ds.groups(),
site_ds.faculties(),
site_ds.years(),
collected)
memcache.flush_all()
print 'Fetched new version %s' % new_v
if __name__ == '__main__':
try:
main()
except:
logging.exception("Exception during update: ")