Twitter

Post here if you need help with creating a Graphical User Interface in Python.

Twitter

Postby ProDin » Tue Mar 18, 2014 6:49 pm

Hello I have managed to get this but my question now is how can i loop the function so that it will keep updating the window that displays the tweet?
Code: Select all
from tkinter import *
from tkinter import ttk
import time
from twython import Twython

TWITTER_APP_KEY = 'MV1XaU8amCCEPOJvJKcGeQ'
TWITTER_APP_KEY_SECRET = 'REDACTED'
TWITTER_ACCESS_TOKEN = '2343422275-lsAUKVqdsCXXM0XBmSyuO6jIhXpJJk1j4U2LUOA'
TWITTER_ACCESS_TOKEN_SECRET = 'REDACTED'

t = Twython(app_key=TWITTER_APP_KEY,
            app_secret=TWITTER_APP_KEY_SECRET,
            oauth_token=TWITTER_ACCESS_TOKEN,
            oauth_token_secret=TWITTER_ACCESS_TOKEN_SECRET)

def get_tweet():
    ip=user_ip.get()
    old_id = ' '
    try:
        tweet = t.search(q=ip, lang='en', count=1)['statuses'].pop()
        time.sleep(3)
        if old_id != tweet['id_str']:
            old_id = tweet['id_str']
            Tweet = Label(TweetWin, text=tweet['text']).grid(column=0, row=0, sticky=W)
            User = Label(TweetWin, text=tweet['user']['name']).grid(column=0, row=1, sticky=W)
            Timestamp = Label(TweetWin, text=tweet['created_at']).grid(column=0, row=2, sticky=W)
    except UnicodeEncodeError:
        pass
        return
   
window = Tk()
window.title('Twitter Fountain')
window.wm_iconbitmap('twittericon.ico')
window.resizable(False, False)

TweetWin = Tk()
TweetWin.title('Twitter Fountain')
TweetWin.wm_iconbitmap('twittericon.ico')
TweetWin.resizable(False, False)
TweetWin.geometry('500x70+100+300')

mainframe = ttk.Frame(window, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)

user_ip = StringVar()

ip_entry = ttk.Entry(mainframe, width=41, textvariable=user_ip)
ip_entry.grid(column=0, row=1, sticky=W)

ttk.Label(mainframe, text="Enter a Username, Hashtag or Keyword to search").grid(column=0, row=0, sticky=W)

ttk.Button(mainframe, text="Search", command=get_tweet).grid(column=1, row=1, sticky=W)

ttk.Button(mainframe, text="Exit", command=exit).grid(column=1, row=2)

window.mainloop()
Last edited by micseydel on Wed Mar 19, 2014 2:51 am, edited 1 time in total.
Reason: Removed secret keys... you don't want to post those....
ProDin
 
Posts: 4
Joined: Thu Jan 23, 2014 2:54 am

Re: Twitter

Postby Kebap » Wed Mar 19, 2014 12:25 pm

Never post your secret keys. Anywhere. You can thank micseydel later. ;)
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 396
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: Twitter

Postby ProDin » Wed Mar 19, 2014 2:10 pm

Thank you for removing the secret keys. I forgot to delete those when I was pasting the code in :/ ...
ProDin
 
Posts: 4
Joined: Thu Jan 23, 2014 2:54 am


Return to GUI

Who is online

Users browsing this forum: No registered users and 3 guests