import_city_halls.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:epuap-watchdog 作者: ad-m 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号