samedi 25 juillet 2020

Tweet with a random generated number

I'm a newbie to Python actually i want a script to tweet automatically with some random numbers but unfortunately the script always generate a same random number everytime so it leads to a duplicated tweet after some time

Here is my code :

 # importing the module 
import tweepy
from time import sleep
import random


# personal information 
api_key = "xxx"
api_secret_key = "xxx"
access_token = "yyy"
access_token_secret ="zzz"


# authentication 
auth = tweepy.OAuthHandler(api_key, api_secret_key) 
auth.set_access_token(access_token, access_token_secret) 


# authentication of access token and secret 
api = tweepy.API(auth) 

randomlist = random.sample(range(0, 99), 99)
int = random.choice(randomlist)
string = f"{int}"
print(int)
print("Attempting to Comment.", flush=True)

#put your tweets here 
list=["t.co/DVI9mPqtu",
"t.co/mkPzaqXge",
"t.co/ql9UxICTy",
"t.co/dDkDiqj92",
"t.co/LeT4rJRQP",
"t.co/zQsMcPCeY",
"t.co/vrQYUS5ci",
"t.co/QPzpLeH7s",
"t.co/711O1d44J",
"t.co/xxMZiIaer",
"t.co/UPrtKk459",
"t.co/7lDJFRfnm",
"t.co/MoBnbLa5r",
"t.co/LafFjnGcl",
"t.co/QA9VkfaUN",
"t.co/0gWFpbSXZ",
"t.co/tlJLpaUR3",
"t.co/TXFvnG7a1",
"t.co/BixvJkFh2",
"t.co/ceHLkEUgR",
"t.co/ZFFbu3hHu",
"t.co/muGfyIg40",
"t.co/uW2XAA6zF",
"t.co/pTbJbljMA",
"t.co/yYIUmLljV",
"t.co/T1kGm1JeC",
"t.co/4sYk7EWWD"
]

# Posting of tweets 
for i in range(len(list)):
    try:
        #insert more hashtags if you want to here
        api.update_status(status =list[i]+" "+ string+" #twitter") 
        print("successfully tweeted")
        sleep(360)
    except KeyboardInterrupt:
        exit()     

I don't know what's wrong in this script but I faced a same random number genrated every time instead of different one. Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire