import CSV (how can i convert my data to csv?) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: import CSV (how can i convert my data to csv?) (/thread-15962.html) |
import CSV (how can i convert my data to csv?) - IvanR - Feb-08-2019 from pprint import pprint from urllib.request import urlopen import json import csv city = input('City name: ') url = 'http://api.openweathermap.org/data/2.5/weather?q={}&appid=9fd4a33e0db32b96a20241175b963165&units=metric'.format(city) request = urlopen(url) text = request.read().decode('utf-8') data = json.loads(text) #pprint(data) cityy = data['name'] counttry = data['sys']['country'] weatherr = data['weather'][0]['description'] temperaturee = data['main']['temp'] wind_speeeed = data['wind']['speed'] print('City: ', cityy) print('Country: ', counttry) for weather in data['weather']: desc = weather['main'] print("Short Description: ", desc) print('Accurate Description: ', weatherr) print('Temperature: {} °C'.format(temperaturee)) print('Wind speed: {} m/s'.format(wind_speeeed)) #maybe this help #with open('podaci.csv', 'w') as csvFile: #writer = csv.writer(csvFile) #writer.writerows(header) [merge]import CSV (how can i convert my code to csv?) - IvanR - Feb-08-2019 HI. Need urgent help! You input name of any city in the world and it prints weather, temperature, wind etc for that city, and i want those values to be converted into csv... RE: import CSV (how can i convert my data to csv?) - ichabod801 - Feb-08-2019 What is your question? You are using the csv module, although you commented that part out. Is it not working? How exactly is it not working? |