forked from 321k/Google-Trends
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlynx automate script
115 lines (108 loc) · 1.85 KB
/
lynx automate script
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
system('rm /root/downloads/*.*')
library(RCurl)
library(RMySQL)
functions <- getURL("https://raw.githubusercontent.com/321k/R-Helper-Functions/master/general%20helper%20functions")
eval(parse(text=functions))
functions <- getURL("https://raw.githubusercontent.com/321k/Google-Trends/master/Google%20Trends%20functions")
eval(parse(text=functions))
search_term <- 'transferwise'
file_name <- paste(search_term,' ', Sys.time(), '.csv.gz', sep='')
path <- paste('/root/downloads/', file_name, sep='')
url <- URL_GT(search_term)
script <- list()
script[[1]] <- c('A'
,'Down Arrow'
,'Down Arrow'
,'Down Arrow'
,'Down Arrow'
,'Down Arrow'
,'Down Arrow'
,'Down Arrow'
,'Down Arrow'
,'Down Arrow'
,'Down Arrow'
,'^J'
,'A'
,'a'
,'n'
,'t'
,'o'
,'n'
,'.'
,'m'
,'a'
,'i'
,'n'
,'h'
,'o'
,'f'
,'@'
,'g'
,'m'
,'a'
,'i'
,'l'
,'.'
,'c'
,'o'
,'m'
,'<tab>'
,'o'
,'o'
,'d'
,'i'
,'x'
,'a'
,'c'
,'h'
,'^J'
,'^J'
,'A'
,'A'
,'A'
,'A'
,'A'
,'g')
script[[2]] <- substring(url, 1:nchar(url), 1:nchar(url))
script[[3]] <- c(
'^J',
'A',
'D',
'Down Arrow',
'Down Arrow',
'Down Arrow',
'^J',
'<delete>',
'<delete>',
'<delete>',
'<delete>',
'<delete>',
'<delete>',
'<delete>',
'<delete>',
'<delete>',
'<delete>',
'<delete>',
'<delete>',
'<delete>'
)
script[[4]] <- substring(path, 1:nchar(path), 1:nchar(path))
script[[5]] <- c(
'^J',
'q',
'y'
)
res <- vector()
for(i in 1:length(script)){
res <- c(res, script[[i]])
}
for(i in 1:length(res)){
res[i] <- paste('key', res[i])
}
res <- paste(res,collapse="\n")
write.table(res, '/root/gt_download', row.names=F, col.names=F, quote=F)
system("lynx -cmd_script=/root/gt_download www.google.com")
file_path <- list.files('/root/downloads/')
x <- readGT(paste('/root/downloads/', file_path, sep=''))
con <- dbConnect(MySQL(), user='root', password = 'johansson', host = '127.0.0.1', port=3306, dbnam='gt')
dbWriteTable(con, 'transferwise', x, overwrite=T, row.names=F)