Pi0 Earthquake tweet display


#1

So to Vote Ninja I’ve bought a Scroll pHAT, a Blinkt stick and a Mini Black HAT Hack3r.
So my idea is to use the Scroll pHAT to display tweets from @QuakesToday (quakes magnitude 1.5+).
I also want to use the Blinkt stick to indicate two things (a tweet alert and earthquake intensity).

I have a few questions.

  1. Can I use the Scroll pHAT and the Blinkt at the same time in one python script? (I suspect I can but just need conformation)
  2. I’ve seen a .py script where you can look for a specific #tag, can you do something similar for a specific user?
  3. The format of the tweets puts a number x.y at the start, is it possible to extract this number and display it on the Blinkt stick?

as the Blinkt stick only has 8 LEDs on it this is my idea on how it would display earthquake intensity (using resistor colour codes):
(any hints for rgb codes would be helpfull)

3.0 dark, dark, orange, orange, dark, dark
3.1 dark red, dark, orange, orange, dark, dark red (‘brown’)
3.2 red, dark, orange, orange, dark, red
3.3 dark, orange, orange, orange, orange, dark
3.4 yellow, dark, orange, orange, dark, yellow
3.5 dark, green, orange, orange, green, dark
3.6 blue, dark, orange, orange, dark, blue
3.7 dark, violet, orange, orange, violet, dark (‘purple’)
3.8 grey, dark, orange, orange, dark, grey (30 - 50% brightness)
3.9 dark, white, orange, orange, white, dark
4.0 dark, dark, yellow, yellow, dark, dark

I reckon the I can code the numbers as rgb values eg 9 = 255,255,255 (or something along those lines).
The reason for alternating the position of the odd and even decimals is for ease of reading. ie outside colour = even decimal

Right its time for bed (I’ve had me grog) but I will be adding more later …

e.g the incoming tweet alert is a different colour when the magnitude exceeds a certain level.


#2
  1. Absolutely!

  2. I’ve not tried, but with Tweepy you’ll probably want to replace:

twitterstream.filter(track=['#INSERTHASHTAGHERE'])

with

twitterstream.filter(track=['@QuakesToday'])
  1. It looks like the tweets follow a specific pattern, so even a very naive extraction of the number should work:
parts = tweet.split(" magnitude #earthquake.")
number = float(parts[0])
detail = parts[1]

We can test this in the Python repl.

>>> tweet
'1.7 magnitude #earthquake. 55km ENE of Cape Yakataga, Alaska http://earthquaketrack.com/quakes/2016-11-28-10-38-01-utc-1-7-0 …'
>>> parts = tweet.split(' magnitude #earthquake')
>>> parts
['1.7', '. 55km ENE of Cape Yakataga, Alaska http://earthquaketrack.com/quakes/2016-11-28-10-38-01-utc-1-7-0 …']
>>> parts[0]
'1.7'
>>> float(parts[0])
1.7

RGB codes should be easy enough to figure out. Resistor colour codes pretty much stick to the simple things. IE: 16 colours:

Alternatively you could use a green through yellow to red magnitude bar, perhaps from 90 degrees to 0 degrees around the hue colour space:

Although the resistor colour codes idea is very educational- I could do with the ability to read those at a glance :D