Browse Source

no api secrets in source code, fixing deletion of ssh pfadiskn tweets also for 2015

mxmehl 5 years ago
parent
commit
655746bece

+ 11
- 10
extract-twitter-accounts.R View File

@@ -34,14 +34,14 @@ row.names(acc_df) <- NULL
34 34
 #   --> devtools::install_github("joyofdata/RTwitterAPI")
35 35
 # https://dev.twitter.com/rest/reference/get/statuses/user_timeline
36 36
 api_params <- c(
37
-  "oauth_consumer_key"     = "c9Ob2fWNSONMC0mA2JlNaeRke", 
37
+  "oauth_consumer_key"     = readLines("twitter-api-credentials.txt")[2], 
38 38
   "oauth_nonce"            = NA,
39 39
   "oauth_signature_method" = "HMAC-SHA1",
40 40
   "oauth_timestamp"        = NA,
41
-  "oauth_token"            = "1007025684-RFxCDFc4OPkt02bASmdci00TB4jgaPjfqxLRT58",
41
+  "oauth_token"            = readLines("twitter-api-credentials.txt")[4],
42 42
   "oauth_version"          = "1.0",
43
-  "consumer_secret"        = "cZ3Il2hmbLgK0Lc57mj5kUvymjVdsmZKYwKOGHR3NhCpvWgEOI",
44
-  "oauth_token_secret"     = "rvfv8MgexFKTqrPNSoGrdrZVNhV4fTJb2Bgz249nbvKNg"
43
+  "consumer_secret"        = readLines("twitter-api-credentials.txt")[3],
44
+  "oauth_token_secret"     = readLines("twitter-api-credentials.txt")[5]
45 45
 )
46 46
 
47 47
 #api_url2 <- "https://api.twitter.com/1.1/statuses/show.json"
@@ -186,7 +186,7 @@ for(a in 1:nrow(acc_df)) {
186 186
   
187 187
   # Every tweet from 2014 or newer from user[a] is downloaded. Now next user in for-loop
188 188
 }
189
-rm(a, code, current, error, loop, max_id, name, query, r, status, user, wait, tweets_full, tweets_temp)
189
+rm(a, code, current, error, loop, max_id, max_count, year_first, year_last, name, query, status, user, wait, tweets_full, tweets_temp)
190 190
 
191 191
 
192 192
 # CLEAR DATAFRAME ---------------------------------------------------------
@@ -196,7 +196,6 @@ save(tweets_complete, file="tweets_complete.RData")
196 196
 # Remove duplicates
197 197
 tweets <- tweets_complete[!duplicated(tweets_complete), ]
198 198
 tweets <- na.omit(tweets)
199
-save(tweets, file="tweets.RData")
200 199
 rm(tweets_complete)
201 200
 
202 201
 # Format dates in data frame
@@ -205,15 +204,14 @@ Sys.setlocale("LC_TIME", "C")
205 204
 tweets$created_at <- as.POSIXct(tweets$created_at, format = "%a %b %d %H:%M:%S %z %Y")
206 205
 tweets <- tweets[order(tweets$created_at), ]
207 206
 
208
-# Finally delete every tweet not from 2014 (so also )
207
+# Finally delete every tweet not from 2014 (2013 or 2015)
209 208
 delrow <- NULL
209
+pb <- txtProgressBar(min = 0, max = nrow(tweets), style = 3)
210 210
 for(r in 1:nrow(tweets)) {
211 211
   if(format(tweets$created_at[r], "%Y") != "2014") {
212 212
     delrow <- c(delrow, r)
213 213
   }
214
-  if(format(tweets$created_at[r], "%Y") == "2014") {
215
-    break
216
-  }
214
+  setTxtProgressBar(pb, r)
217 215
 }
218 216
 tweets <- tweets[-delrow, ]
219 217
 rm(delrow, r)
@@ -221,3 +219,6 @@ rm(delrow, r)
221 219
 # Convert dates to omit (unnecessary) time
222 220
 tweets$created_at <- format(tweets$created_at, "%Y-%m-%d")
223 221
 
222
+save(tweets, file="tweets.RData")
223
+
224
+

BIN
ratelimiterror.RData View File


BIN
tweets.RData View File


BIN
tweets_complete.RData View File


+ 0
- 1
twitter-api-consumerkey.txt View File

@@ -1 +0,0 @@
1
-c9Ob2fWNSONMC0mA2JlNaeRke

+ 0
- 1
twitter-api-consumersecret.txt View File

@@ -1 +0,0 @@
1
-cZ3Il2hmbLgK0Lc57mj5kUvymjVdsmZKYwKOGHR3NhCpvWgEOI

+ 5
- 0
twitter-api-credentials.txt View File

@@ -0,0 +1,5 @@
1
+# 1. line: consumer key, 2. consumer secret, 3. oauth token, 4. oauth secret
2
+c9Ob2fWNSONMC0mA2JlNaeRke
3
+cZ3Il2hmbLgK0Lc57mj5kUvymjVdsmZKYwKOGHR3NhCpvWgEOI
4
+1007025684-RFxCDFc4OPkt02bASmdci00TB4jgaPjfqxLRT58
5
+rvfv8MgexFKTqrPNSoGrdrZVNhV4fTJb2Bgz249nbvKNg

Loading…
Cancel
Save