twitools/deleter.py

59 lines
1.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import twitools
import tkinter, tkinter.messagebox, html.parser, os
two = twitools.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:" + twitools.twObject().whoami()
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()