Created
November 13, 2013 23:28
-
-
Save arthur-flam/7458425 to your computer and use it in GitHub Desktop.
Twitter: follower growth + unfollowers
Run the shell script first !
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
library(RCurl) | |
library(stringr) | |
library(twitteR) | |
library(ggplot2) | |
library(plyr) | |
## Setup twitter credentials once (with an API app key) | |
# cred <- OAuthFactory$new(consumerKey="XXXXX", | |
# consumerSecret="XXXXX", | |
# requestURL="https://api.twitter.com/oauth/request_token", | |
# accessURL="https://api.twitter.com/oauth/access_token", | |
# authURL="https://api.twitter.com/oauth/authorize") | |
# cred$handshake() | |
# save(cred,file="credOAuth") | |
load("twitterAuthCredentials.Rdata") | |
registerTwitterOAuth(cred) | |
me = getUser("ArthurFlam") | |
followers = me$getFollowers() | |
## Unfollowers | |
followers_once = readLines("followers.txt") | |
followers_once <- str_extract_all(followers_once, "\\([^()]+\\)") | |
followers_once = substring(k, 2, nchar(followers_once)-1) | |
followers_once = gsub("@", "", followers_once) | |
followers_ids = unlist(lapply(followers, function(x) x$screenName)) | |
# here's the list ! | |
setdiff(followers_once, followers_ids) | |
## follower growth | |
dates = followers_once = readLines("dates.txt") | |
dates = str_sub(dates, start=12, end=-16)#7 | |
Sys.setlocale("LC_TIME", "en_US") | |
dates = as.Date(dates, format="%d %b %Y") | |
d = data.frame(date=dates) | |
d = ddply(d, .(date), function(x) { | |
data.frame(sum=nrow(x)/2) | |
}) | |
d$cum = cumsum(d$sum) | |
g = ggplot(d, aes(x=date, y=cum))+geom_step() | |
timeline_rt = userTimeline(me, n=3200, includeRts=TRUE) | |
#timeline = userTimeline(me, n=3200) | |
tweet_dates = unlist(lapply(timeline_rt, function(x) as.Date(x$created))) | |
tweet_dates = as.Date(tweet_dates, origin=as.Date("1970-01-02")) | |
g+geom_vline(xintercept=tweet_dates, alpha=0.2) |
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
#!/bin/bash | |
# where have you stored your mails ? | |
cd /Users/ArthurFlam/Library/Mail/V2/IMAP-arthur.flam@imap.gmail.com | |
grep "vous suit désormais sur Twitter" -Rl * > ~/Desktop/twitterFollowers/files.txt | |
while read p; do | |
grep "Date: " "$p" >> ~/Desktop/twitterFollowers/dates.txt | |
grep "vous suit désormais sur Twitter" "$p" >> ~/Desktop/twitterFollowers/followers.txt | |
done < ~/Desktop/twitterFollowers/files.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment