forked from today-is-a-good-day/emojis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postEmoticons.R
44 lines (39 loc) · 1.82 KB
/
postEmoticons.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require(stringi)
library(magrittr)
library(twitteR)
library(tidyr)
# oauth
load("twitterOauthEmoticons.Rdata")
consumer_key <- my_oauth$consumerKey
consumer_secret <- my_oauth$consumerSecret
access_token <- my_oauth$oauthKey
access_secret <- my_oauth$oauthSecret
setup_twitter_oauth(consumer_key = consumer_key, consumer_secret = consumer_secret,
access_token = access_token, access_secret = access_secret)
# post emoticons
tweetslist <- paste0(stri_unescape_unicode(alltogether$Native)," ", alltogether$Description)
# don´t post all at once <- rate limit per 15 minutes!
lapply(tweetslist[1:100], tweet)
lapply(tweetslist[101:200], tweet)
lapply(tweetslist[201:300], tweet)
lapply(tweetslist[301:400], tweet)
lapply(tweetslist[401:500], tweet)
lapply(tweetslist[501:600], tweet)
lapply(tweetslist[601:700], tweet)
lapply(tweetslist[701:800], tweet)
lapply(tweetslist[806:length(tweetslist)], tweet)
# I posted two parts per day, 15 minutes appart
# retrieve emoticons
tweetsback <- userTimeline("Remoticons", n = 900) %>%
twListToDF
# split one column into df with the columns "bytes" and "decription"
tweetsback2 <- data.frame(text = iconv(tweetsback$text, "latin1", "ASCII", "byte"),
stringsAsFactors = FALSE)
# kind of an ugly workaround, but the bytes made it impossible to create a df the proper way
column1 <- separate(tweetsback2, text, into = c("Bytes", "Description"), sep = "\\ ")
column2 <- separate(tweetsback2, text, into = c("Bytes", "Description"), sep = "^[^\\s]*\\s")
df <- data.frame(Bytes = column1$Bytes, Description = column2$Description)
# merge retrieved encoding with original encoding to one df &v write to file
eotw <- merge(alltogether, df1, by = "Description")
names(eotw) <- c("Description", "Native", "Bytes", "R-encoding")
write.csv2(eotw, file = "emDict.csv", row.names = FALSE)