Improve nvidia-driver scraper readability (#958)

This commit is contained in:
vtvrv 2023-05-24 11:31:54 +00:00 committed by GitHub
parent 0716fd4767
commit 5620237e78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,19 +8,17 @@ import sys
from datetime import datetime from datetime import datetime
json_data = json.loads(sys.stdin.read()) json_data = json.loads(sys.stdin.read())
json_feed = "{{\"title\": \"{title}\", \"items\": [{items}]}}"
items = list()
json_root = json_data[0] json_root = json_data[0]
json_feed = {"title": "Nvidia " + json_root["articleLocalizedTag"], "items": []}
for ite in json_root["articlePagesList"]: for article in json_root["articlePagesList"]:
article_author = json.dumps(ite["authorName"]) new_item = {
article_url = json.dumps(ite["articlePath"]) "title": article["articleTitle"],
article_title = json.dumps(ite["articleTitle"]) "authors": [{"name": article["authorName"]}],
article_time = json.dumps(datetime.strptime(ite["articleDate"], "%B %d, %Y").isoformat()) "content_text": article["articleShortDescription"],
article_contents = json.dumps(ite["articleShortDescription"]) "url": article["articlePath"],
"date_published": datetime.strptime(article["articleDate"], "%B %d, %Y").isoformat()
}
json_feed["items"].append(new_item)
items.append("{{\"title\": {title}, \"authors\": [{{\"name\": {author}}}], \"content_text\": {html}, \"url\": {url}, \"date_published\": {date}}}".format(title=article_title, html=article_contents, url=article_url, date=article_time, author=article_author)) print(json.dumps(json_feed))
json_feed = json_feed.format(title="Nvidia " + json_root["articleLocalizedTag"], items=", ".join(items))
print(json_feed)