Home > OS >  I want help regarding tweepy hiding your username
I want help regarding tweepy hiding your username

Time:07-08

So here is what I am trying to do I am trying to get my Twitter bot to give maths answers to users using WolframAlpha API here is what problem I am facing as people will mention my Twitter username to active the bot example: @twitterusername 2 2 the WolframAlpha will take it as the whole input @twitterusername 2 2 which will give me the error I want it to ignore the username here is my code

def respondToTweet(file='tweet_ID.txt'):
    last_id = get_last_tweet(file)
    mentions = api.mentions_timeline(last_id, tweet_mode='extended')
    if len(mentions) == 0:
        return

    new_id = 0
    logger.info("someone mentioned me...")

    for mention in reversed(mentions):
        logger.info(str(mention.id)   '-'   mention.full_text)
        new_id = mention.id
        status = api.get_status(mention.id)

        if '@Saketltd01' in mention.full_text.lower():
            logger.info("Responding back with QOD to -{}".format(mention.id))
            client = wolframalpha.Client(app_id)

            query = mention.full_text.lower()

            rest = client.query(query)

            answer = next(rest.results).text
            Wallpaper.get_wallpaper(answer)

            media = api.media_upload("created_image.png")

            logger.info("liking and replying to tweet")

            api.create_favorite(mention.id)
            api.update_status('@'   mention.user.screen_name, mention.id,
                              media_ids=[media.media_id])

    put_last_tweet(file, new_id)


def main():
    respondToTweet()

CodePudding user response:

When you take the whole input remember to strip it down by simply removing your username from the actual input string and then perform the mathematical operation on it:

myUsername = "@my_username"
equation = userInput.lstrip(myUsername)

perform_desired_operation_on(equation) // User defined function
  • Related