mirror of
https://github.com/anatolykopyl/Twitter-Bot.git
synced 2026-03-26 12:54:49 +00:00
Delete tweet by command
This commit is contained in:
22
deleteTweet.py
Normal file
22
deleteTweet.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
from twython import Twython, TwythonError
|
||||||
|
import authorization
|
||||||
|
import re
|
||||||
|
|
||||||
|
def deleteTweet(): #Deletes a tweet with the given ID
|
||||||
|
search_results = authorization.twitter.search(q="#DeleteID", count=5, result_type='recent')
|
||||||
|
try:
|
||||||
|
for tweet in search_results["statuses"]:
|
||||||
|
id_to_delete = int(re.sub("\D", "", tweet["text"]))
|
||||||
|
authorization.twitter.destroy_status(id=id_to_delete)
|
||||||
|
authorization.twitter.update_status(status="Tweet "+str(id_to_delete)+" deleted!", in_reply_to_status_id = tweet["id_str"])
|
||||||
|
|
||||||
|
log_str = "Deleted tweet with ID "+str(id_to_delete)+"\n"
|
||||||
|
log_file=open('log_file.txt', 'a')
|
||||||
|
log_file.write(log_str)
|
||||||
|
log_file.close()
|
||||||
|
print log_str,
|
||||||
|
except TwythonError as e:
|
||||||
|
print e
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
2
main.py
2
main.py
@@ -10,6 +10,7 @@ import filecmp
|
|||||||
import shutil
|
import shutil
|
||||||
from check import *
|
from check import *
|
||||||
from retweet import *
|
from retweet import *
|
||||||
|
from deleteTweet import *
|
||||||
|
|
||||||
import authorization
|
import authorization
|
||||||
|
|
||||||
@@ -57,5 +58,6 @@ def main():
|
|||||||
print log_str,
|
print log_str,
|
||||||
|
|
||||||
retweet()
|
retweet()
|
||||||
|
deleteTweet()
|
||||||
|
|
||||||
time.sleep (60*30)
|
time.sleep (60*30)
|
||||||
Reference in New Issue
Block a user