def handle(self, host, user, password, no_progress, *args, **options):
self.s = requests.Session()
self.s.auth = (user, password)
self.host = host
self.updated, self.inserted, self.errored, self.skipped = 0, 0, 0, 0
count = self.get('institutions/?tags=7')['count']
with transaction.atomic() and tqdm(total=count) as t:
page_num = int(ceil(count / self.PER_PAGE))
for page in range(1, page_num + 1):
t.set_description("Page {} of {}".format(page, page_num))
result = self.get('institutions/?tags=7&page={}'.format(page))
for row in result['results']:
self.update_row(row)
t.update(1)
self.stdout.write(
"Processed {} city halls, which {} updated, {} skipped and {} inserted. but {} errored.".
format(self.updated + self.inserted,
self.updated,
self.skipped,
self.inserted,
self.errored))
total_count = CityHall.objects.count()
self.stdout.write("There is {} city halls in total".format(total_count))
评论列表
文章目录