Created
September 14, 2022 18:39
-
-
Save yavuzKomecoglu/a39adbb71d0d7b81f0f83fa5b7ff7038 to your computer and use it in GitHub Desktop.
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 | |
def search_hashtag(searchterm, dt_until, dt_since, lang, limit=100000): | |
query = "({searchterm}) lang:{lang} until:{until} since:{since}".format(searchterm=searchterm, lang=lang, until=dt_until, since=dt_since) | |
#query = (#Emmys2022) lang:en until:2022-09-14 since:2022-09-01 | |
tweets = [] | |
limit = limit | |
q = sntwitter.TwitterSearchScraper(query) | |
for tweet in q.get_items(): | |
if len(tweets) == limit: | |
break | |
else: | |
tweets.append([tweet.date, tweet.content]) | |
df = pd.DataFrame(tweets, columns=['Date', 'Tweet']) | |
csv_name = "data/Emmys2022/" + searchterm.replace("#","hastag_").replace("\"","").replace(" ","_") + "_" + str(since) + "_" + str(until) + ".csv" | |
df.to_csv(csv_name, index=False) | |
print("succecss") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment