Trying to loop through titles of movies in a text file to call API and store the response to a text file.
file contains one title on every line ex.
Titanic
Avatar
A Star Is Born
the api i am trying to use is from www.odmpapi.com
This is what i have to correctly join and create the weblink
import requests
import sys
prefixURL = 'http://www.omdbapi.com/?t='
suffixURL = '&apikey=xxx4s23'
text_file = open("url.txt", "w")
with open('print.txt', 'r') as f:
for i in f:
uri = prefixURL + i.rstrip(' \n\t') + suffixURL
print uri
text_file.write(url)
text_file.write('\n')
text_file.close()
text_file = open("responses.txt", "w")
with open('url.txt', 'r') as f2:
for i in f2:
url = i.strip(' \n\t')
batch = requests.get(i.rstrip(' \n\t'))
data = batch.text
print data
text_file.write(data)
text_file.write('\n')
text_file.close()
This writes to responses.txt only the last title in the list.
urllib.requestsdocs or theRequests: HTTP for Humansdocs?