add datetime_handler
This commit is contained in:
parent
ba466810ef
commit
c146dbb674
1 changed files with 8 additions and 6 deletions
|
@ -6,12 +6,10 @@ from pathlib import Path
|
||||||
|
|
||||||
SCRAPERS = {}
|
SCRAPERS = {}
|
||||||
|
|
||||||
|
|
||||||
def register_scraper(cls):
|
def register_scraper(cls):
|
||||||
SCRAPERS[cls.__name__] = cls
|
SCRAPERS[cls.__name__] = cls
|
||||||
return cls
|
return cls
|
||||||
|
|
||||||
|
|
||||||
def run_all(args: argparse.Namespace):
|
def run_all(args: argparse.Namespace):
|
||||||
results = {}
|
results = {}
|
||||||
for scraper_cls in SCRAPERS.values():
|
for scraper_cls in SCRAPERS.values():
|
||||||
|
@ -19,10 +17,14 @@ def run_all(args: argparse.Namespace):
|
||||||
results.update(scraper.scrape())
|
results.update(scraper.scrape())
|
||||||
print(results)
|
print(results)
|
||||||
|
|
||||||
# Save the results to a JSON file
|
def datetime_handler(obj):
|
||||||
with open('results.json', 'w') as json_file:
|
if isinstance(obj, datetime.datetime):
|
||||||
json.dump(results, json_file, indent=4)
|
return obj.isoformat()
|
||||||
|
raise TypeError("Unknown type")
|
||||||
|
|
||||||
|
# Save the results to a JSON file
|
||||||
|
with open('results.json', 'w') as json_file:
|
||||||
|
json.dump(results, json_file, indent=4, default=datetime_handler)
|
||||||
|
|
||||||
def import_scrapers():
|
def import_scrapers():
|
||||||
directory = Path(__file__).resolve().parent / "scrapers"
|
directory = Path(__file__).resolve().parent / "scrapers"
|
||||||
|
|
Loading…
Reference in a new issue