from project database import db from project api import api def main k

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
from project.database import db
from project.api import api
def main(**kwargs):
for city in db.city.find({'country_id': 1}, no_cursor_timeout=True):
obj = db.school_city.find_one({'_id': city['_id']})
if obj is not None:
print('City %s already processed' % city['title'])
else:
count = 0
for item in api.call_paginate('database.getSchools',
city_id=city['_id'],
per_page=1000):
item['_id'] = item['id']
item['city_id'] = city['_id']
db.school.save(item)
count += 1
print('City %s: %d' % (city['title'], count))
db.school_city.save({
'_id': city['_id'],
})