Fixes broken --ads parameter (#249)

This commit is contained in:
Heavenfighter
2024-01-05 20:19:20 +01:00
committed by GitHub
parent c66b4a3eb8
commit 078149bd2a

View File

@@ -238,8 +238,10 @@ class KleinanzeigenBot(SeleniumMixin):
descr_suffix = self.config["ad_defaults"]["description"]["suffix"] or "" descr_suffix = self.config["ad_defaults"]["description"]["suffix"] or ""
ids = [] ids = []
use_specific_ads = False
if re.compile(r'\d+[,\d+]*').search(self.ads_selector): if re.compile(r'\d+[,\d+]*').search(self.ads_selector):
ids = [int(n) for n in self.ads_selector.split(',')] ids = [int(n) for n in self.ads_selector.split(',')]
use_specific_ads = True
LOG.info('Start fetch task for the ad(s) with the id(s):') LOG.info('Start fetch task for the ad(s) with the id(s):')
LOG.info(' | '.join([str(id_) for id_ in ids])) LOG.info(' | '.join([str(id_) for id_ in ids]))
@@ -256,31 +258,32 @@ class KleinanzeigenBot(SeleniumMixin):
LOG.info(" -> SKIPPED: inactive ad [%s]", ad_file) LOG.info(" -> SKIPPED: inactive ad [%s]", ad_file)
continue continue
if self.ads_selector == "new" and ad_cfg["id"] and check_id: if use_specific_ads:
LOG.info(" -> SKIPPED: ad [%s] is not new. already has an id assigned.", ad_file) if not ad_cfg["id"] in ids:
continue LOG.info(" -> SKIPPED: ad [%s] is not in list of given ids.", ad_file)
continue
else:
if self.ads_selector == "new" and ad_cfg["id"] and check_id:
LOG.info(" -> SKIPPED: ad [%s] is not new. already has an id assigned.", ad_file)
continue
if self.ads_selector == "due": if self.ads_selector == "due":
if ad_cfg["updated_on"]: if ad_cfg["updated_on"]:
last_updated_on = parse_datetime(ad_cfg["updated_on"]) last_updated_on = parse_datetime(ad_cfg["updated_on"])
elif ad_cfg["created_on"]: elif ad_cfg["created_on"]:
last_updated_on = parse_datetime(ad_cfg["created_on"]) last_updated_on = parse_datetime(ad_cfg["created_on"])
else: else:
last_updated_on = None last_updated_on = None
if last_updated_on: if last_updated_on:
ad_age = datetime.utcnow() - last_updated_on ad_age = datetime.utcnow() - last_updated_on
if ad_age.days <= ad_cfg["republication_interval"]: if ad_age.days <= ad_cfg["republication_interval"]:
LOG.info(" -> SKIPPED: ad [%s] was last published %d days ago. republication is only required every %s days", LOG.info(" -> SKIPPED: ad [%s] was last published %d days ago. republication is only required every %s days",
ad_file, ad_file,
ad_age.days, ad_age.days,
ad_cfg["republication_interval"] ad_cfg["republication_interval"]
) )
continue continue
if not ad_cfg["id"] in ids:
LOG.info(" -> SKIPPED: ad [%s] is not in list of given ids.", ad_file)
continue
ad_cfg["description"] = descr_prefix + (ad_cfg["description"] or "") + descr_suffix ad_cfg["description"] = descr_prefix + (ad_cfg["description"] or "") + descr_suffix
ensure(len(ad_cfg["description"]) <= 4000, f"Length of ad description including prefix and suffix exceeds 4000 chars. @ [{ad_file}]") ensure(len(ad_cfg["description"]) <= 4000, f"Length of ad description including prefix and suffix exceeds 4000 chars. @ [{ad_file}]")