import snscrape.modules.twitter as sntwitter
import pandas as pd

def scrape(limit=0):
    # prepare variables
    tweet_list = list()
    query = '(Odense OR odense OR #odense OR #Odense) until:2022-12-17 since:2017-01-01 -filter:replies'
    # begin scraping
    for i, tweet in enumerate(sntwitter.TwitterSearchScraper(query).get_items()):
        # if limit is reached, break out of loop
        if limit > 0 and i > limit: break
        # if another 100 tweets found, tell it
        if i % 100 == 0: 
            print(f'found {i} tweets')
        tweet_list.append([tweet.date, tweet.id, tweet.content, tweet.user.username])
    # create dataframe
    df = pd.DataFrame(tweet_list, columns=['Datetime', 'Id', 'Text', 'Username'])
    return df
