2021-03-20 20:06:02 +01:00
# Parses output of Nvidia's GDC web service, which provides
# list of articles.
2021-06-30 07:19:34 +02:00
# Sample input file whose contents must be provided as stdin: "https://www.nvidia.com/bin/nvidiaGDC/servlet/article.json?locale=en_US®ion=us&type=both&tag=drivers&offset=0"
2021-03-20 20:06:02 +01:00
# This scripts outputs JSON feed 1.1: https://jsonfeed.org/version/1.1
import json
import sys
from datetime import datetime
json_data = json . loads ( sys . stdin . read ( ) )
json_root = json_data [ 0 ]
2023-05-24 11:31:54 +00:00
json_feed = { " title " : " Nvidia " + json_root [ " articleLocalizedTag " ] , " items " : [ ] }
2021-03-20 20:06:02 +01:00
2023-05-24 11:31:54 +00:00
for article in json_root [ " articlePagesList " ] :
new_item = {
" title " : article [ " articleTitle " ] ,
" authors " : [ { " name " : article [ " authorName " ] } ] ,
" content_text " : article [ " articleShortDescription " ] ,
" url " : article [ " articlePath " ] ,
" date_published " : datetime . strptime ( article [ " articleDate " ] , " % B %d , % Y " ) . isoformat ( )
}
json_feed [ " items " ] . append ( new_item )
2021-03-20 20:06:02 +01:00
2023-05-24 11:31:54 +00:00
print ( json . dumps ( json_feed ) )