+ sync_schedules util
This commit is contained in:
1 parent
27f09669fe
commit
7d97953877
1 file changed
+23
-16
@@ -8,24 +8,31 @@ import settings
|
|||||||
__author__ = 'tmshv'
|
__author__ = 'tmshv'
|
||||||
|
|
||||||
|
|
||||||
db = MongoClient(settings.database_uri).hudozka
|
def process_file(schedule_path):
|
||||||
db.schedules.drop()
|
with open(schedule_path, 'rb') as schedule_file:
|
||||||
|
data = schedule_file.read().decode('utf-8')
|
||||||
|
try:
|
||||||
|
return json.loads(data)
|
||||||
|
except json.decoder.JSONDecodeError:
|
||||||
|
print(schedule_path)
|
||||||
|
|
||||||
|
|
||||||
for schedule_path in glob(settings.root_dir_schedule + '/*.json'):
|
if __name__ == '__main__':
|
||||||
with open(schedule_path, 'r') as schedule_file:
|
db = MongoClient(settings.database_uri).hudozka
|
||||||
name = os.path.basename(schedule_path)
|
db.schedules.drop()
|
||||||
|
|
||||||
period = re.search('(\d{4}-\d{4})', name).group(1)
|
# dir_schedule = settings.root_dir_schedule
|
||||||
semester = re.search('([a-zA-Z]+)\.json$', name).group(1)
|
dir_schedule = '/Users/tmshv/Dropbox/Dev/Hud School/Schedules/'
|
||||||
|
files = glob(dir_schedule + '*.json')
|
||||||
|
ss = list(map(process_file, files))
|
||||||
|
|
||||||
schedule = json.loads(schedule_file.read())
|
list(map(print, ss))
|
||||||
# print(name, period, semester, schedule)
|
|
||||||
|
|
||||||
db.schedules.insert({
|
list(map(
|
||||||
'period': period,
|
db.schedules.insert,
|
||||||
'semester': semester,
|
filter(
|
||||||
'schedule': schedule
|
lambda i : i is not None,
|
||||||
})
|
ss
|
||||||
|
)
|
||||||
print('schedule sync complete')
|
))
|
||||||
|
print('schedule sync complete')
|
||||||
Reference in new issue
Block a user