-
-
Save suatatan/6c15c36803d2bedbd1fe8e37c7056b11 to your computer and use it in GitHub Desktop.
Bu kodlar yardımı ile herhangi bir konunda topluca twit çekebilirsiniz. API key gerekmez. Tarih aralığı verme de mümkün. Ayrıca bu kodlar gelen twitlerden wordcloud oluşturur ve twitleri excel ve pickle formatında kaydeder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import snscrape.modules.twitter as sntwitter | |
import pandas as pd | |
from wordcloud import WordCloud | |
import matplotlib.pyplot as plt | |
# Creating list to append tweet data to | |
tweets_list2 = [] | |
# Twitter'da bir konudaki veriyileri çeker excel ve pickle olarak kaydeder ve kelime bulutuna dönüştürür | |
# Dr. Suat ATAN tarafından yazıldı | |
def veri_al_ve_gor(anahar_terim, zaman_araligi = "since:2020-02-01 until:2020-03-01"): | |
for i,tweet in enumerate(sntwitter.TwitterSearchScraper(f'{anahar_terim} {zaman_araligi}').get_items()): | |
if i>500: | |
break | |
tweets_list2.append([tweet.date, tweet.id, tweet.content]) | |
# Creating a dataframe from the tweets list above | |
tweets_df2 = pd.DataFrame(tweets_list2, columns=['Datetime', 'Tweet Id', 'Text' ]) | |
exportit = tweets_df2[['Tweet Id', 'Text']] | |
exportit.to_excel(f"sonuc_{anahar_terim}.xls") | |
exportit.to_pickle(f"pickle_{anahar_terim}.pickle") | |
text3 = ' '.join(exportit['Text']) | |
wordcloud2 = WordCloud().generate(text3) | |
# Generate plot | |
plt.imshow(wordcloud2) | |
plt.savefig(f'wordcloud_{anahar_terim}.pdf') | |
print("İşlem tamam: {ananahar_terim}") | |
liste = ['umutsuz','kaygı','anksiyete','korku','mutsuz','stresli', | |
'panik','stres','obsesif','depresyon','üzgün','fobi','çarpıntı','ağlama','distimik', | |
'katatonik','ümitiz'] | |
for kavram in liste: | |
veri_al_ve_gor(kavram) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment