php - How to write a python script to call a API and print the results retrieved from the API -
i beginner , new coding. have api in php gives meteo data retrieved meteo station. want have python script call api , print results api in file. please suggest me right coding approach. api is: http://ewodr.wodr.poznan.pl/doradztwo/swd/meteo_api.php?dane={"token":"pcss","id":303,"operacja":"odczyt_doba"}
use urllib2
library (for python 2) fetch data api. this:
import urllib2 import csv # api url url = "your api url" # open api url response = urllib2.urlopen(str(url)) data = response.read() # write results in csv file open('file.csv', 'wb') f: f.write(data)
or if json
import json import urllib2 # api url url = "your api url" # open api url response = urllib2.urlopen(str(url)) data = json.load(response) # write results in csv file open('file.txt', 'w') f: json.dump(data, f)
i have not used python 3 not think there lot of changes.
Comments
Post a Comment