Skip to content

Instantly share code, notes, and snippets.

@bhargavkulk
Created July 10, 2021 16:22
Show Gist options
  • Save bhargavkulk/f58ba0307069210369b9e6b868f9e9f4 to your computer and use it in GitHub Desktop.
Save bhargavkulk/f58ba0307069210369b9e6b868f9e9f4 to your computer and use it in GitHub Desktop.
D.GG archiver bot o7
import tweepy
from datetime import date
from pprint import pprint
import re
import json
import os
user_id = "TheOmniLiberal"
THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
recent_id = os.path.join(THIS_FOLDER, 'id.txt')
API_KEY = ""
API_SECRET_KEY = ""
BEARER_TOKEN = ""
ACCESS_TOKEN = ""
ACCESS_TOKEN_SECRET = ""
auth = tweepy.OAuthHandler(API_KEY, API_SECRET_KEY)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
most_recent_id = None
with open(recent_id, "r") as fin:
most_recent_id = fin.read()
fin.close()
rec_id = None
if most_recent_id != "":
rec_id = int(most_recent_id)
for status in api.user_timeline(id=user_id, since_id=rec_id, tweet_mode="extended"):
if status.in_reply_to_status_id is None:
print(status.full_text)
tweet = re.sub("https://t\.co/[A-z0-9]+", "", status.full_text).strip()
if tweet != '':
api.update_status(tweet)
else:
print(status.full_text)
tweet = re.sub("https://t\.co/[A-z0-9]+", "", status.full_text).strip()
if tweet != "":
temp1 = tweet.split(" ")
temp2 = []
flag = True
while len(temp1) != 0:
if len(temp1) > 0 and temp1[0][0] == '@' and flag:
temp1.pop(0)
else:
flag = False
temp2.append(temp1.pop(0))
tweet = " ".join(temp2)
new_tweet = api.update_status(tweet)
reply_text = "Replied to: https://twitter.com/twitter/statuses/" + str(api.get_status(status.in_reply_to_status_id).id)
api.update_status(reply_text, in_reply_to_status_id=new_tweet.id)
cur_id = (api.user_timeline(id=user_id, count=1)[0]).id
with open(recent_id, "w") as fout:
fout.write(str(cur_id))
fout.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment