# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
import tweepy                             #api to fetch tweeets
from googletrans import Translator        #api to translate one language to another
import re
translator=Translator()

consumer_key = "<KEY>"      # find these token from twitter developer account 
consumer_secret = "<KEY>"   # click and create an app and then browse to token and copy your keys here
access_key = "<KEY>"
access_secret = "<KEY>"

#do not share these tokens with anyone as they can be used to exploit your twitter data

def fetch(Twitter_handle): 
        
    verify = tweepy.OAuthHandler(consumer_key, consumer_secret) 
    verify.set_access_token(access_key, access_secret)
    var=[]
    api = tweepy.API(verify) 
    tweets = api.user_timeline(screen_name=Twitter_handle,count=2,tweet_mode='extended') # you can set count to the number of tweets you want starting from the most recent tweet
    list_tweets= [tweet.full_text for tweet in tweets] 
    #tweet_mode is set to extended  and .full_text is used with extracted tweets to fetch full length of tweets
    
    for element in list_tweets: 
        element=re.sub("\n",'',element)     # regex to remove url and other puctuations
        element=re.sub(r"@[a-z]*|#(\w+)",'',element)
        element=re.sub("/",' or ',element)
        element=re.sub("-",' ',element)
        element=translator.translate(element,dest='en').text    #using translator to translate the extracted tweets in english from any language
        #this API will detect language on its own since they have fuctions inside this API to do so and "en" is for english
        var.append(element)              #append all tweets to a list var[]

        
    print(var) # print tweets



if __name__ == '__main__': 


    fetch("---name of the twitter account whose tweets you want to fetch---") 



# -

# # P.S. 
#
# ## i don't want to beautify this code as this is my own working module for a project but you can put these functionalities inside class and methods which you can easily find on someone else repository
#
#
#
#
#
# # THANK YOU
#



StarcoderdataJupyterScriptsDedupFiltered