Dec-12-2017, 12:48 AM
(This post was last modified: Dec-12-2017, 01:17 AM by sparkz_alot.)
I made a Twitter crawling code and also made GUI. The Code that generates the entered value as a keyword variable.
But I couldn't generate a variable in GUI.How can I generate a variable in GUI?
This is the code
############################################################################################################
import tweepy
import os
import sys
import imp
imp.reload(sys)
from tkinter import *
def twitter():
consumer_key = "my cunsumer key"
consumer_secret = "my consumer secret"
access_token = "my access token"
access_token_secret = "my access token secret"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
public_tweets = api.home_timeline()
for tweet in public_tweets:
print(tweet.text.encode('UTF-8').decode('UTF-8'))
location = "%s,%s,%s" % ("35.95", "128.25", "1000km")
search =
cnt = 1
while(cnt <= 10):
tweets = api.search(keyword)
for tweet in tweets:
search.append(tweet)
cnt += 1
data = {}
i = 0
for tweet in search:
data['text'] = tweet.text
print(i, " : ", data)
i += 1
wfile = open(os.getcwd()+"/twitter.txt", mode='w')
data = {}
i = 0
for tweet in search:
data['text'] = tweet.text
print(i, ":",data)
i += 1
wfile.close()
def show():
print(temp.get())
window = Tk()
explain = Label(window, text="twitter crawling progrem")
explain.pack()
name = Label(window, text="Enter Keyword")
name.pack()
temp = Entry(window)
temp.pack()
keyword = temp.get()
b1 = Button(window, text='Enter!', command=show, bg='green')
b1.pack()
b2 = Button(window, text = 'Crawling!', command = twitter, bg = 'red')
b2.pack()
window.mainloop()
################################################
But I couldn't generate a variable in GUI.How can I generate a variable in GUI?
This is the code
############################################################################################################
import tweepy
import os
import sys
import imp
imp.reload(sys)
from tkinter import *
def twitter():
consumer_key = "my cunsumer key"
consumer_secret = "my consumer secret"
access_token = "my access token"
access_token_secret = "my access token secret"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
public_tweets = api.home_timeline()
for tweet in public_tweets:
print(tweet.text.encode('UTF-8').decode('UTF-8'))
location = "%s,%s,%s" % ("35.95", "128.25", "1000km")
search =
cnt = 1
while(cnt <= 10):
tweets = api.search(keyword)
for tweet in tweets:
search.append(tweet)
cnt += 1
data = {}
i = 0
for tweet in search:
data['text'] = tweet.text
print(i, " : ", data)
i += 1
wfile = open(os.getcwd()+"/twitter.txt", mode='w')
data = {}
i = 0
for tweet in search:
data['text'] = tweet.text
print(i, ":",data)
i += 1
wfile.close()
def show():
print(temp.get())
window = Tk()
explain = Label(window, text="twitter crawling progrem")
explain.pack()
name = Label(window, text="Enter Keyword")
name.pack()
temp = Entry(window)
temp.pack()
keyword = temp.get()
b1 = Button(window, text='Enter!', command=show, bg='green')
b1.pack()
b2 = Button(window, text = 'Crawling!', command = twitter, bg = 'red')
b2.pack()
window.mainloop()
################################################