skip to Main Content

Hi i’m a newbie to Python and i’m just a learner, recently i tried to combine two scripts (retweet and tweet) into one with a interval between two but unfortunately it always ends with an error, i don’t know how to solve this error.

Here is my code:

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

# personal information 
api_key = "xxxx"
api_secret_key = "yyyy"
access_token = "xxxx"
access_token_secret ="yyyy"


# 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) 


#put your tweets here
#some of these tweets have been taken from the top section of the hashtag #BoycottPexa,credit goes to the respective users 
list=["t.co/DVIh9Pqtu",
"t.co/mkPzaqXge",
"t.co/ql9UxICTy",
"t.co/dDSkDij92",
"t.co/LeTY4JRQP"
]


# Retweet and Favorite the tweet
for tweet in tweepy.Cursor(api.search, q = ("#twitter -filter:retweets"),lang="en").items(): 
    try: 
        print("nTweet by: @" + tweet.user.screen_name) 

        tweet.retweet() 
        print("Retweeted the tweet") 

            tweet.favorite() 
            print("Favorited the tweet") 
            sleep(360)

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

Error i received:

    File "post.py", line 95
2020-07-26T07:45:45.598784+00:00 app[worker.1]: tweet.favorite() 
2020-07-26T07:45:45.598785+00:00 app[worker.1]: ^
2020-07-26T07:45:45.598786+00:00 app[worker.1]: IndentationError: unexpected indent

Any help would be appreciated and thanks in advance .

2

Answers


  1. As the user above said, an error would be good but I see the tweet.favourite like is incorrectly indented.

    Login or Signup to reply.
  2. Just as the error says: you have indentation problem in your code.

    It appears that it is happening here:

            tweet.retweet() 
            print("Retweeted the tweet") 
                
                # This bit has no reason to be indented
                tweet.favorite() 
                print("Favorited the tweet") 
                sleep(360)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search