Skip to content

Instantly share code, notes, and snippets.

@basilesimon
Last active August 8, 2018 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basilesimon/3c40ac1e1706de9b583dbd0fb4591a23 to your computer and use it in GitHub Desktop.
Save basilesimon/3c40ac1e1706de9b583dbd0fb4591a23 to your computer and use it in GitHub Desktop.
How many tweets per week, month, etc?

Install GetOldTweets:

$ git clone git@github.com:Jefferson-Henrique/GetOldTweets-python.git
$ cd GetOldTweets-python
$ pip install -r requirements.txt

Run the exporter with your parameters.
Documentation is at: https://github.com/Jefferson-Henrique/GetOldTweets-python

$ python Exporter.py --username "realDonaldTrump" --since 2017-01-20

Then do your grouping and export in R.
You can round dates with these lubridate methods

library(lubridate)
library(dplyr)
library(readr)

# semicolon-separated dataframe
df <- read.csv("output_got.csv", ";", header=T)

# group by week
week_groups <- df %>%
   mutate(week_name = floor_date(as.POSIXct(date), "weeks")) %>%
   group_by(week_name) %>%
   summarise(count = n())
write.csv(week_groups, "week_groups.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment