Check in initial version of the Tweleter

This commit is contained in:
Klaus-Uwe Mitterer 2015-10-10 21:14:51 +02:00
parent 4f1cb5cad1
commit 671dd3b5d9

59
tweleter.py Executable file
View file

@ -0,0 +1,59 @@
#!/usr/bin/env python3
import config, tools
import tkinter, tkinter.messagebox, html.parser, os
two = tools.twObject()
top = tkinter.Tk()
top.title("Tweet Deleter")
scrollbar = tkinter.Scrollbar(top)
scrollbar.pack(side=tkinter.RIGHT, fill=tkinter.Y)
list = tkinter.Listbox(top, height=20, width=150, selectmode=tkinter.MULTIPLE, yscrollcommand=scrollbar.set)
scrollbar.config(command=list.yview)
def deleteTweets():
top.wm_withdraw()
tweets = list.curselection()
success = 0
fail = 0
for tweet in tweets:
id = int(list.get(tweet).rsplit(None, 1)[-1])
try:
print(id)
two.delete(id)
success += 1
except:
fail += 1
tkinter.messagebox.showinfo('Deleted tweets', 'Deleted %i tweets. %i errors.' % (success, fail))
top.destroy()
button = tkinter.Button(top, text="Delete", command=deleteTweets)
def unescapeText(text):
return html.parser.HTMLParser().unescape(text)
def addStatus(id, text):
element = "%s - %i" % (text, id)
list.insert(0, element.encode("UTF-8"))
def getTweets():
query = "from:" + config.user
try:
timeline = two.search(query, 0)
except:
tkinter.messagebox.showerror('Error...', 'An error occurred. Most likely you hit a rate limit. Please try again later.')
exit()
for status in timeline:
addStatus(status.id, unescapeText(status.text))
if __name__ == "__main__":
getTweets()
list.pack()
button.pack()
top.mainloop()