Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
✓ Live Streaming✓ Interactive Chat✓ Private Shows✓ HD Quality✓ Free Actions
Free to watch • No registration required • HD streaming
Here is my Final Project Code to create a Rest API with New York Times and the Guardian searching for Rugby articles and creating a CSV file.
To view my code on creating the CSV file above click on ‘Keep reading’
#Angela Chih
#SI 506_Final Project
import json
import requests
#Use that investigation to define a class `NYTArticle` and a class `GuardianArticle` that fulfill requirements, and that you can use as tools to complete the rest of the project.
#Access data from each source with data about articles, and create a list of instances of `NYTArticle` and a list of instances of `GuardianArticle`.
CACHE_FNAME = "cache_file_name.json"
# if I already have cached data, I want to load that data into a python dictionary
try:
cache_file = open(CACHE_FNAME, 'r')
cache_contents = cache_file.read()
cache_diction = json.loads(cache_contents)
cache_file.close()
# if I don't have cached data, I will create an empty dictionary to save data later
except:
cache_diction = {}
def params_unique_combination(baseurl, params_d, private_keys=["api_key"]):
alphabetized_keys = sorted(params_d.keys())
res = []
for k in alphabetized_keys:
if k not in private_keys:
res.append("{}-{}".format(k, params_d[k]))
return baseurl + "_".join(res)
def get_from_NYT(a):
# put together base url and parameters
baseurl = "https://api.nytimes.com/svc/search/v2/articlesearch.json"
params_diction = {}
params_diction["api_key"] = "TakenOffDueToRestrictions"
params_diction["q"] = a
# see if the url identifier is already in cache dictionary
if unique_ident in cache_diction:
# if so, get data from cache dictionary and return
return cache_diction[unique_ident]
# if not, make a new API call using the requests module
else:
resp = requests.get(baseurl, params_diction)
# Or as:
# resp = requests.get(unique_ident)
# save the data in the cache dictionary, using unique url identifier
## as a key and the response data as value
cache_diction[unique_ident] = json.loads(resp.text)
# convert the cache dictionary to a JSON string
dumped_json_cache = json.dumps(cache_diction)
# save the JSON string in the cache file
fw = open(CACHE_FNAME,"w")
fw.write(dumped_json_cache)
fw.close() # Close the open file
# return the data
return cache_diction[unique_ident]
# see if the url identifier is already in cache dictionary
if unique_ident in cache_diction:
# if so, get data from cache dictionary and return
return cache_diction[unique_ident]
# if not, make a new API call using the requests module
else:
resp = requests.get(baseurl, params_diction)
# Or as:
# resp = requests.get(unique_ident)
# save the data in the cache dictionary, using unique url identifier
## as a key and the response data as value
cache_diction[unique_ident] = json.loads(resp.text)
# convert the cache dictionary to a JSON string
dumped_json_cache = json.dumps(cache_diction)
# save the JSON string in the cache file
fw = open(CACHE_FNAME,"w")
fw.write(dumped_json_cache)
fw.close() # Close the open file
# return the data
return cache_diction[unique_ident]