apples723
Posts: 80
Joined: Sat Jun 22, 2013 3:13 pm

weather

Tue Jun 25, 2013 12:30 am

ok so heres my problem i want to write a script using module requests
my first problem is that request module is only recognised in idle but not in idle 3 and the problem with that is that my main script i want to use the weather script in is only working in idle 3

my second problem is that i get this error

Code: Select all

Traceback (most recent call last):
  File "/home/pi/Desktop/Scripts/weather.py", line 9, in <module>
    print (forecast) ['forecast']['txt_forecast']
TypeError: 'instancemethod' object has no attribute '__getitem__'
when running this script

Code: Select all

import requests

key = '015098ae0bc15cce'
ApiUrl = \
'http://api.wunderground.com/api/' + key + '/forecast/q/IA/Urbandale.json'

r = requests.get(ApiUrl)
forecast = r.json
print forecast ['forecast']['txt_forecast'] 
any help would be appreciated total noob here

Maddo
Posts: 15
Joined: Mon May 06, 2013 4:39 am

Re: weather

Tue Jun 25, 2013 6:31 am

Could you please link to module requests as I have no idea what it is meant to do, and no way of helping sorry.

apples723
Posts: 80
Joined: Sat Jun 22, 2013 3:13 pm

Re: weather

Tue Jun 25, 2013 1:32 pm

Maddo wrote:Could you please link to module requests as I have no idea what it is meant to do, and no way of helping sorry.
does this help? http://www.python-requests.org/en/lates ... uickstart/

IanH2
Posts: 79
Joined: Tue Dec 18, 2012 10:17 am

Re: weather

Fri Jun 28, 2013 7:30 pm

I'm not familiar with the module, but the Python error suggests that 'forecast' ends up being a method of an object, which is something you need to call to get a usable result. Try something like:

Code: Select all

forecast = r.json()

Ian
-----
https://github.com/IanHarvey

User avatar
addeswe
Posts: 27
Joined: Fri Jul 19, 2013 3:49 pm
Location: Sweden

Re: weather

Mon Jul 22, 2013 9:16 am

Examplecode to get current degrees in C of my hometown Umeå, Sweden:

Code: Select all

import requests
import json
apikey = "<insert api-key here>"
url = requests.get("http://api.wunderground.com/api/"+apikey+"/conditions/q/SE/Umea.json")
json = json.loads(url.text)
print json['current_observation']['temp_c']
Hope this can help you with your coding.
“Knock, knock.” - “Who’s there?” - very long pause…. - “Java.”
If a python knocks on your door and says “Hi, I’m a vacuum cleaner!” it’s not true. That’s a python.

Return to “Python”