Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Arduino_Genuino
Published © GPL3+

LedMatrix Tweet Visualization

Display tweets with a certain hashtag on a led matrix in real time!

IntermediateFull instructions provided16,543
LedMatrix Tweet Visualization

Things used in this project

Hardware components

Seeed Studio Led matrix 8x32
×1
Arduino Yun Shield
Arduino Yun Shield
×1

Software apps and online services

Arduino Web Editor
Arduino Web Editor

Story

Read more

Schematics

Schematic

Code

Python script

Python
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals
import requests
from requests_oauthlib import OAuth1
from urlparse import parse_qs
import sys

REQUEST_TOKEN_URL = "https://api.twitter.com/oauth/request_token"
AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize?oauth_token="
ACCESS_TOKEN_URL = "https://api.twitter.com/oauth/access_token"

CONSUMER_KEY = "****"
CONSUMER_SECRET = "****"

OAUTH_TOKEN = ""
OAUTH_TOKEN_SECRET = ""


def setup_oauth():
    """Authorize your app via identifier."""
    # Request token
    oauth = OAuth1(CONSUMER_KEY, client_secret=CONSUMER_SECRET)
    r = requests.post(url=REQUEST_TOKEN_URL, auth=oauth)
    credentials = parse_qs(r.content)

    resource_owner_key = credentials.get('oauth_token')[0]
    resource_owner_secret = credentials.get('oauth_token_secret')[0]

    # Authorize
    authorize_url = AUTHORIZE_URL + resource_owner_key
    print 'Please go here and authorize: ' + authorize_url

    verifier = raw_input('Please input the verifier: ')
    oauth = OAuth1(CONSUMER_KEY,
                   client_secret=CONSUMER_SECRET,
                   resource_owner_key=resource_owner_key,
                   resource_owner_secret=resource_owner_secret,
                   verifier=verifier)

    # Finally, Obtain the Access Token
    r = requests.post(url=ACCESS_TOKEN_URL, auth=oauth)
    credentials = parse_qs(r.content)
    token = credentials.get('oauth_token')[0]
    secret = credentials.get('oauth_token_secret')[0]

    return token, secret


def get_oauth():
    oauth = OAuth1(CONSUMER_KEY,
                client_secret=CONSUMER_SECRET,
                resource_owner_key=OAUTH_TOKEN,
                resource_owner_secret=OAUTH_TOKEN_SECRET)
    return oauth

if __name__ == "__main__":
    ashtag = str(sys.argv[1])
    oauth = get_oauth()

    part1 = "https://api.twitter.com/1.1/search/tweets.json?q=%23"
    part2 = "&count=1"
    r = requests.get(url=part1+ashtag+part2, auth=oauth)

    message_id = r.json()["statuses"][0]["id"]
    text = r.json()["statuses"][0]["text"]

    print message_id
    print text

Arduino Sketch

Credits

Arduino_Genuino

Arduino_Genuino

91 projects • 11340 followers

Comments