Skip to content

Instantly share code, notes, and snippets.

@aritraroy24
Last active June 4, 2021 14:39
Show Gist options
  • Save aritraroy24/2c1efcd0b040010345f1912d7a207f72 to your computer and use it in GitHub Desktop.
Save aritraroy24/2c1efcd0b040010345f1912d7a207f72 to your computer and use it in GitHub Desktop.
tweeting data after checking whether it is a repeat or not
def tweet(self, text_list, url_list):
'''
Posting the news in the twitter and logging the data (First news of the list will be posted: One can modify by using random function)
'''
# removing news already tweeted
file_name = "tweets.txt"
with open(file_name, "r") as file:
tweet_list = file.readlines()
tweet_list = [x.strip() for x in tweet_list]
for tweet in tweet_list:
for text, url in zip(text_list, url_list):
if text == tweet:
text_list.remove(text)
url_list.remove(url)
# tweeting the fast news from the modified newslist
for text in text_list:
i = 0
try:
with open(file_name, "a") as file:
file.write(f"{text}\n\n")
api.update_status(
f"@aritraroy24 #compchem #news #update #science #chemistry #quantum\nπ™π™Šπ˜Ώπ˜Όπ™”'π™Ž π™π™‹π˜Ώπ˜Όπ™π™€: {text_list[i]}\n{url_list[i]}")
logger.info(
f"Tweet done at : {str(datetime.datetime.now())} === {text_list[i]} === {url_list[i]}\n\n\n")
i += 1
break
except Exception as e:
logger.info(
f"Tweet can't be done at : {str(datetime.datetime.now())} due to {e} error\n\n\
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment