# Scroll phat wunderground

**URL:** <https://forums.pimoroni.com/t/scroll-phat-wunderground/7963>\
**Category:** Support\
**Created:** [June 17, 2018, 5:43pm UTC](https://forums.pimoroni.com/t/scroll-phat-wunderground/7963 "2018-06-17T17:43:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![g7kse](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@g7kse](https://forums.pimoroni.com/u/g7kse)\
**Post date:** [June 17, 2018, 5:43pm UTC](https://forums.pimoroni.com/t/scroll-phat-wunderground/7963/1 "2018-06-17T17:43:52Z")

</div>

Evening,

I’m having a play with the scroll phat (Well Scroll Bot really) and wanted to use the Wunderground weather example. However, wunderground seem to hae stopped offering the free api. Are there alternative examples that I could use in a school that will show the weather on the mighty bot?

ta

Alex

---

<div class="post-metadata">

**Author:** ![gadgetoid](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/gadgetoid/32/13_2.png) [@gadgetoid](https://forums.pimoroni.com/u/gadgetoid)\
**Post date:** [June 18, 2018, 11:00am UTC](https://forums.pimoroni.com/t/scroll-phat-wunderground/7963/2 "2018-06-18T11:00:54Z")

</div>

Looks like this might be a viable alternative api, but there’s no example for it yet: [https://www.openweathermap.org/api](https://www.openweathermap.org/api)

---

<div class="post-metadata">

**Author:** ![g7kse](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@g7kse](https://forums.pimoroni.com/u/g7kse)\
**Post date:** [June 18, 2018, 4:43pm UTC](https://forums.pimoroni.com/t/scroll-phat-wunderground/7963/3 "2018-06-18T16:43:03Z")

</div>

Yeah…I had a quick look at that but frankly have no idea what I am doing. Are there any simple to understand tutorials on dealing with API’s? So far the ones I’ve come across are so full of jargon it makes it impossible to know what is going on.

My guess is that the script goes and gets the data for a specific location and then returns it. the rest of the script organises it and then displays it

---

<div class="post-metadata">

**Author:** ![Blanchot](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@Blanchot](https://forums.pimoroni.com/u/Blanchot)\
**Post date:** [June 19, 2018, 8:34am UTC](https://forums.pimoroni.com/t/scroll-phat-wunderground/7963/4 "2018-06-19T08:34:09Z")

</div>

> [@g7kse](#):
>
> My guess is that the script goes and gets the data for a specific location and then returns it. the rest of the script organises it and then displays it

Good guess! It’s not that difficult if you take it step by step. Try doing a search for ‘simple python requests json tutorial’

Here’s one that came up from my quick search:

> **[Using the Requests Library in Python - PythonForBeginners.com](https://www.pythonforbeginners.com/requests/using-requests-in-python)**
>
> Using the Requests Library in Python will help you improve your python skills with easy to follow examples and tutorials. Click here to view code examples.

And another one over the requests library:  
[http://docs.python-requests.org/en/master/user/quickstart/](http://docs.python-requests.org/en/master/user/quickstart/)

Hope this helps!

---

<div class="post-metadata">

**Author:** ![gadgetoid](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/gadgetoid/32/13_2.png) [@gadgetoid](https://forums.pimoroni.com/u/gadgetoid)\
**Post date:** [June 19, 2018, 9:07am UTC](https://forums.pimoroni.com/t/scroll-phat-wunderground/7963/5 "2018-06-19T09:07:50Z")

</div>

I was contemplating making writing this example my Twitch Stream theme for this afternoon- showing how I might put it together step-by-step as @Blanchot suggests.

---

<div class="post-metadata">

**Author:** ![g7kse](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@g7kse](https://forums.pimoroni.com/u/g7kse)\
**Post date:** [June 21, 2018, 1:09pm UTC](https://forums.pimoroni.com/t/scroll-phat-wunderground/7963/6 "2018-06-21T13:09:24Z")

</div>

Thanks for the pointers. I’m going to have a play about. Whats the worst that could happen ;-)

---

<div class="post-metadata">

**Author:** ![g7kse](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@g7kse](https://forums.pimoroni.com/u/g7kse)\
**Post date:** [June 21, 2018, 8:15pm UTC](https://forums.pimoroni.com/t/scroll-phat-wunderground/7963/7 "2018-06-21T20:15:28Z")

</div>

So I’ve had a play this evening and come a bit unstuck. It might be worth moving this thread but I’ll post anyway. One of the other projects I’m involved with is one called SatNOGS (its a series of networked ground stations that listen for satellites using RPi’s and rtl\_sdr dongles…its pretty cool). One of my ground stations is numbered 33 so I thought perhaps I could query the api and return the next observation then display some of the basic data like the satellite name (or norad\_id) and the transmitter.

I’ve managed to set up th eurl query and return the full set of data but parsing it is where I’m falling down a bit. I thought I’d return a few observation id’s (called ‘id’) with the hope of producing a list of id’s to start with.

code so far is:

```
import urllib.parse
import requests

url = 'https://network.satnogs.org/api/observations/?format=json&ground_station=33'

json_data = requests.get(url).json()
#print(json_data) - just used this to prove I was getting the right data

observation_id = json_data['0'][0]['id']
print ('obs_id: '+observation_id)

```

The error returned is:

```
Traceback (most recent call last):
File "python", line 9, in <module>
TypeError: list indices must be integers or slices, not str

```

I’m not sure I fully understand the error. So a clue to that would be handy. I’ve found returning the data is relatively easy, its selecting data that I find tricky. From what I can understand is that the data is contained within a dictionary that has a few sub ‘parts’. For simplicity I tried to return the one right at the top under the sub heading ‘0’.

Can anyone put the right code in line line and explain what I’ve done wrong?

After that I’m gong to need to work out how to return the ‘next’ observation as it doesn’t sit at the top of the page but I guess is dynamic and based on the number of scheduled observations.

After that I’m going to need to query one of the other available api’s to return the satellite name from the norad\_id

I think I’ve bitten off way more than I can chew but am really keen to see this one through as it’s cool

cheers

Alex

---

<div class="post-metadata">

**Author:** ![gadgetoid](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/gadgetoid/32/13_2.png) [@gadgetoid](https://forums.pimoroni.com/u/gadgetoid)\
**Post date:** [June 23, 2018, 11:25am UTC](https://forums.pimoroni.com/t/scroll-phat-wunderground/7963/8 "2018-06-23T11:25:18Z")

</div>

The “list indices must be integers or slices, not str” error is a little obtuse sounding, but it actually quite simply if you know what’s going on. In python a list looks like this:

```auto
my_list = ['a', 'b', 'c']

```

It has an implicit order to its items, and each one receives an index 0, 1, 2, but the items are not named in any way so they can _only_ be referred to either by their index or a “slice” which is a way of expressing a group of indexes. IE this will work:

```auto
>>> my_list = ['a', 'b', 'c']
>>> my_list[0]
'a'

```

But this will not:

```auto
>>> my_list = ['a', 'b', 'c']
>>> my_list['0']

```

And neither will this:

```auto
>>> my_list = ['a', 'b', 'c']
>>> my_list['blahblah']

```

Because ‘0’ and ‘blahblah’ are both strings. You might just as well be asking “get me number b” which makes no sense!

This is not to be confused with dictionaries, which have a “key” you can reference by name:

```auto
>>> my_list = {'0': 'monkey', 'blahblah': 'badger'}
>>> my_list['0']
'monkey'
>>> my_list['blahblah']
'badger'

```

So, TLDR: The error is just a really obtuse way of saying “you need a number to get the value of something form a list”

No doubt your `json_data['0']` should read `json_data[0]`

It’s always good practise to do this kind of stuff in a Python repl (just run Python at the command line) so you can step through your code piece by piece and play with the `json_data` object to see what it contains.

In your repl you might:

```auto
>>> import urllib.parse
>>> import requests
>>> data = requests.get('your HTTP url').json()
>>> print(json)
... shows what's returned
>>> json['0']
... returns an error
>>> json[0]
... shows the first element
>>> dir(json)
... returns a list of methods on `json`

```

This makes it easy to prod and poke at something exploratively, and while you’ll still see errors raised, they wont abort the repl so you can continue prodding and poking until you learn what’s what, and then go and bake that into your `.py` file.

---

<div class="post-metadata">

**Author:** ![g7kse](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@g7kse](https://forums.pimoroni.com/u/g7kse)\
**Post date:** [June 24, 2018, 6:15pm UTC](https://forums.pimoroni.com/t/scroll-phat-wunderground/7963/9 "2018-06-24T18:15:14Z")

</div>

Thanks for that. It’s starting to make sense now and I’ve managed to extract the first part of what I want. All told JSON is a very useful tool to get stuff from somewhere else. I can see this taking me a while to get it ‘just right’. Mechanical engineers and coding don’t tend to mix well ;-).

Once I’ve got it all sorted and working I’ll put it somewhere useful in case someone else takes an interest in satellites, Raspberry Pi’s, rtl\_sdr and damp string.

Alex
