I have data in Json format availaible on this link: Json Data
What would be the best way to get this done? I know this could be done by Python but not sure how.
I have data in Json format availaible on this link: Json Data
What would be the best way to get this done? I know this could be done by Python but not sure how.
Use urllib module to fetch details from the url.
import urllib
url = "http://www.omdbapi.com/?t=UN%20HOMME%20ID%C3%89AL"
res = urllib.urlopen(url)
print res.code
data = res.read()
Parse data to JSON by json module.
import json
data1 = json.loads(data)
Use xlwt module to create xls file.
data = {"Title":"Un homme idéal","Year":"2015","Rated":"N/A",\
"Released":"18 Mar 2015","Runtime":"97 min","Genre":"Thriller",\
"Director":"Yann Gozlan","Writer":"Yann Gozlan, Guillaume Lemans, Grégoire Vigneron",\
"Actors":"Pierre Niney, Ana Girardot, André Marcon, Valeria Cavalli",\
"Plot":"N/A","Language":"French","Country":"France","Awards":"N/A",\
"Poster":"N/A","Metascore":"N/A","imdbRating":"6.3","imdbVotes":"214",\
"imdbID":"tt4058500","Type":"movie","Response":"True"}
import xlwt
book = xlwt.Workbook(encoding="utf-8")
sheet1 = book.add_sheet("AssetsReport0")
colunm_count = 0
for title, value in data.iteritems():
sheet1.write(0, colunm_count, title)
sheet1.write(1, colunm_count, value)
colunm_count += 1
file_name = "test.xls"%()
book.save(file_name)
Get URL from User.
Use sys.argv
to get arguments passed from the command.
Demo:
import sys
print "Arguments:", sys.argv
Output:
vivek:~/workspace/vtestproject/study$ python polydict.py arg1 arg2 arg3
Arguments: ['polydict.py', 'arg1', 'arg2', 'arg3']
Demo:
>>> url = raw_input("Enter url:-")
Enter url:-www.google.com
>>> url
'www.google.com'
>>>
Note:
Use raw_input() for Python 2.x
Use input for Python 3.x
To get data in Python from an URL (and print it):
import requests
r = requests.get('http://www.omdbapi.com/?t=UN%20HOMME%20ID%C3%89AL')
print(r.text)
To parse a json in Python
import requests
import json
r = requests.get('http://www.omdbapi.com/?t=UN%20HOMME%20ID%C3%89AL')
json.loads(r.text)
You will have a JSON object.
To convert from JSON to tsv you may use tablib.
To create a excel document in Python you may use openpyxl (more tools at python-excel.org).