Quantcast
Channel: Support - Pimoroni Buccaneers
Viewing all articles
Browse latest Browse all 6853

Scrollphat Python twitter code help needed

$
0
0

@Mentazm wrote:

HI folks, Programmed the scrollphat to stream my twitter timeline. Totally new to python and have very limited coding experience, mostly from 20 years ago. The code below works, but the tweets constantly repeat until a new one is posted. So I'm looking for some help to -

  • stop tweets after they scroll once.
  • strip out any http links embedded in the tweet - I just want the text content.
  • ideally change the tweets to all upper case letters to make it easier to read, but that's not a priority.

Feel free to copy the code for your own projects, you'll have to install twython though.

Any ideas?

===

!/usr/bin/env python

import scrollphat
import sys
import time
import thread
from twython import TwythonStreamer

Twitter application authentication

APP_KEY = ''
APP_SECRET = ''
OAUTH_TOKEN = ''
OAUTH_TOKEN_SECRET = ''

class MyStreamer(TwythonStreamer):
def on_success(self, data):
if 'text' in data:
tweet = '@{}: {}'.format(data['user']['screen_name'].encode('utf-8'), data['text'].encode('utf-8'))
scrollphat.write_string(tweet)
#print tweet

def on_error(self, status_code, data):
    print status_code, data

def scroll_display(sleeptime):
# turn everything off
scrollphat.clear()
scrollphat.rotate = True

while True:
    try:
        scrollphat.scroll()
        #print 'thread awake'
        time.sleep(sleeptime)
    except KeyboardInterrupt:
        scrollphat.clear()
        sys.exit(-1)

def main():
# kick off the thread to manage the display
thread.start_new_thread(scroll_display, (0.1,))

# Requires Authentication as of Twitter API v1.1
stream = MyStreamer(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
stream.user()

if name == "main":
main()

Posts: 3

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 6853

Trending Articles