acikyazilimagi / deprem-yardim-backend

afetharita.com backend projesi
Apache License 2.0
384 stars 76 forks source link

Collecting tweets for addresses of earthquake victims: get_tweets function #111

Closed apassenger closed 1 year ago

apassenger commented 1 year ago

Here is the function which collects the tweets and print them according to the earthquake victims locations i.e Hatay, Adana I am not able to open the application right now. Probably this function was already written but in case, I put here. If you think it is useless, you can simply delete and close the issue:

def get_tweets(query, count = 20000): 

    tweets = []
    adana = io.open("adana.txt", 'w', encoding='utf-8')
    hatay_antakya = io.open("hatay_antakya.txt", 'w', encoding='utf-8')
    kahramanmaras = io.open("kahramanmaras.txt", 'w', encoding='utf-8')
    urfa = io.open("urfa.txt", 'w', encoding='utf-8')
    adiyaman = io.open("adiyaman.txt",'w', encoding='utf-8')
    malatya = io.open("malatya",'w',encoding='utf-8')

    q=str(query)
    a=str(q + "enkaz") #.decode('iso-8859-9')
    b=str(q + "Antakya")#.decode('iso-8859-9')
    c=str(q + "Kahramanmaras")
    d=str(q + "Adana")
    e=str(q + "hatay")
    f=str(q + "urfa")
    g=str(q + "malatya")
    i=str(q + "adiyaman")
    fetched_tweets_adana = api.search_tweets(d, count=count)
    fetched_tweets_antakya = api.search_tweets(b, count = count) + api.search_tweets(e, count = count) 
    fetched_tweets_kahramanmaras = api.search_tweets(c, count = count)
    fetched_tweets_urfa = api.search_tweets(f, count = count)
    fetched_tweets_malatya = api.search_tweets(g, count= count)
    fetched_tweets_adiyaman = api.search_tweets(i, count = count)
    print(len(fetched_tweets_adana ))

    print (len(fetched_tweets_antakya ))
    print (len(fetched_tweets_kahramanmaras ))
    print (len(fetched_tweets_urfa ))
    print (len(fetched_tweets_malatya ))
    print (len(fetched_tweets_adiyaman ))

    for tweet in fetched_tweets_adana:

        parsed_tweet = {}

        parsed_tweet['text'] = tweet.text
        if "http" not in tweet.text:
            line = re.sub("[^A-Za-z]", " ", tweet.text)
            adana.write(line+"\n")

    for tweet in fetched_tweets_antakya:

        parsed_tweet = {}

        parsed_tweet['text'] = tweet.text
        if "http" not in tweet.text:
            line = re.sub("[^A-Za-z]", " ", tweet.text)
            hatay_antakya.write(line+"\n")

    for tweet in fetched_tweets_kahramanmaras:

        parsed_tweet = {}

        parsed_tweet['text'] = tweet.text
        if "http" not in tweet.text:
            line = re.sub("[^A-Za-z]", " ", tweet.text)
            kahramanmaras.write(line+"\n")

    for tweet in fetched_tweets_malatya:

        parsed_tweet = {}

        parsed_tweet['text'] = tweet.text
        if "http" not in tweet.text:
            line = re.sub("[^A-Za-z]", " ", tweet.text)
            malatya.write(line+"\n")

    for tweet in fetched_tweets_urfa:

        parsed_tweet = {}

        parsed_tweet['text'] = tweet.text
        if "http" not in tweet.text:
            line = re.sub("[^A-Za-z]", " ", tweet.text)
            urfa.write(line+"\n")

    for tweet in fetched_tweets_adiyaman:

        parsed_tweet = {}

        parsed_tweet['text'] = tweet.text
        if "http" not in tweet.text:
            line = re.sub("[^A-Za-z]", " ", tweet.text)
            adiyaman.write(line+"\n")
    return tweets