From 85ccf892a86cb164cab403aa9e78a65802824336 Mon Sep 17 00:00:00 2001 From: csae8092 Date: Mon, 22 Jan 2024 16:12:41 +0100 Subject: [PATCH] dont store image urls longer than 300 chars --- apis_core/apis_entities/management/commands/fetch_images.py | 6 +++++- apis_core/apis_metainfo/models.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apis_core/apis_entities/management/commands/fetch_images.py b/apis_core/apis_entities/management/commands/fetch_images.py index 59464b8..b1a5491 100644 --- a/apis_core/apis_entities/management/commands/fetch_images.py +++ b/apis_core/apis_entities/management/commands/fetch_images.py @@ -23,7 +23,11 @@ def handle(self, *args, **kwargs): ) print(f"start fetching images for {items.count()} persons without images") for x in tqdm(items[:200]): - x.fetch_image() + try: + x.fetch_image() + except Exception as e: + print(x.id, e) + continue time.sleep(0.5) end_time = datetime.now().strftime(settings.PMB_TIME_PATTERN) report = [os.path.basename(__file__), start_time, end_time] diff --git a/apis_core/apis_metainfo/models.py b/apis_core/apis_metainfo/models.py index 8cfb4af..1524d81 100644 --- a/apis_core/apis_metainfo/models.py +++ b/apis_core/apis_metainfo/models.py @@ -150,7 +150,8 @@ def fetch_image(self): self.img_last_checked = datetime.now() img_url = fetch_image(wikidata_uri.uri) if img_url: - self.img_url = img_url + if len(img_url) < 301: + self.img_url = img_url self.save() return self