-1

I created a small python script which calls a json url and then displays the data. One of the fields from the website json output is date so i do a print ['date'] and this returns 2015-12-05T00:00:00

import urllib, json

url = "http://buienradar.nl/Json/GetDailyForecast?geolocationid=2745340"
response = urllib.urlopen(url)
data = json.loads(response.read())
do1 = data['days'][0]


print  do1['date']
print "windsnelheid", do1['windspeed']
print "Gevoelstemperatuur",do1['temperature']
print "Minimale temperatuur",do1['mintemperature']
print "Maximale temperatuur",do1['maxtemperature']
print '\n'

now at the print do1['date'] i receive the 2015-12-02T00:00:00 and there i would like to have the current day. Can somebody help me with that?

Thank you

1 Answers1

1

You could parse the date with datetime's strptime and send it to strftime with the %A specifier:

In  [5]: sdate = '2015-12-05T00:00:00'
In  [6]: date = datetime.datetime.strptime(sdate[:10], '%Y-%m-%d')
In  [7]: date.strftime('%A')
Out [7]: 'Saturday'
xnx
  • 24,509
  • 11
  • 70
  • 109