From 84a0f642023dafc57a0bf463e0306393bc1b4f44 Mon Sep 17 00:00:00 2001 From: Samuel kalu Date: Wed, 15 Mar 2023 08:29:47 +0100 Subject: [PATCH 1/2] Update README.md --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/README.md b/README.md index 00cb4f9..a36a6be 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,49 @@ If you want to use the development version: pip3 install git+https://github.com/JustAnotherArchivist/snscrape.git ## Usage + +### Python + +#### Using the Twitter API +A simple way to get around using scraping tweets using the twitter module + +```python + +import snscrape.modules.twitter as sntwitter +import pandas as pd + +query = '#python' # a query string , for specific user tweets, you could use 'from:' +scraper = sntwitter.TwitterSearchScraper(query) +tweets_list = [] + + + +for tweet in scraper.get_items(): + data = [ + + tweet.id, + tweet.date, + tweet.content, + tweet.user.username, + tweet.likeCount, + tweet.retweetCount, + + ] + + tweets_list.append(data) + + +column_names = [ 'ID','Date','Content', 'Username', 'LikeCount','RetweetCount'] + +frame = pd.DataFrame(data = tweets_list, columns = column_names) + + +frame.to_csv('./python_hashtag_tweets.csv', index = False) + +``` + + + ### CLI The generic syntax of snscrape's CLI is: From 029b5e43fef9ae535a952faaa99d4dae982eddd1 Mon Sep 17 00:00:00 2001 From: Samuel kalu Date: Wed, 15 Mar 2023 08:31:17 +0100 Subject: [PATCH 2/2] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index a36a6be..7390bf1 100644 --- a/README.md +++ b/README.md @@ -59,9 +59,8 @@ for tweet in scraper.get_items(): column_names = [ 'ID','Date','Content', 'Username', 'LikeCount','RetweetCount'] +# converting to a dataframe using pandas frame = pd.DataFrame(data = tweets_list, columns = column_names) - - frame.to_csv('./python_hashtag_tweets.csv', index = False) ```