5
5
"fmt"
6
6
_ "github.com/go-sql-driver/mysql"
7
7
"github.com/gocolly/colly"
8
+ "github.com/rakanalh/scheduler"
9
+ "github.com/rakanalh/scheduler/storage"
8
10
"io/ioutil"
9
11
"log"
10
12
"net/http"
@@ -41,14 +43,30 @@ func getRecentLinks() (string, string) {
41
43
}
42
44
43
45
func main () {
44
- links , result := getRecentLinks ()
45
- //jdbc:mariadb://192.168.1.65:3306/ideone
46
46
dsn := DB_USER + ":" + DB_PASS + "@" + DB_HOST + "/" + DB_NAME + "?charset=utf8"
47
+ var db * sql.DB
47
48
db , err := sql .Open ("mysql" , dsn )
48
49
checkErr (err )
50
+ memStorage := storage .NewMemoryStorage ()
51
+ s := scheduler .New (memStorage )
52
+ fmt .Println ("Im good at school three huna worldwide" )
53
+ if _ , err := s .RunEvery (15 * time .Second , scrapIdeone , db ); err != nil {
54
+ log .Fatal (err )
55
+ }
56
+ s .Start ()
57
+ s .Wait ()
58
+ }
59
+
60
+ func scrapIdeone (db * sql.DB ) {
61
+ links , result := getRecentLinks ()
62
+ //jdbc:mariadb://192.168.1.65:3306/ideone
49
63
50
64
split := strings .Split (links , ";" )
51
65
split = split [1 :50 ]
66
+
67
+ results := strings .Split (result , ";" )
68
+ results = results [1 :50 ]
69
+
52
70
for i , k := range split {
53
71
fmt .Println ("----------" )
54
72
var url = "https://ideone.com/plain/" + k [1 :]
@@ -61,21 +79,13 @@ func main() {
61
79
html , err := ioutil .ReadAll (response .Body )
62
80
var txt string = string (html )
63
81
fmt .Println (len (html ))
64
- // fullurl VARCHAR(60),
65
- // codedate VARCHAR(60),
66
- // codekey VARCHAR(30),
67
- // size BIGINT,
68
- // codelines BIGINT,
69
- // language VARCHAR(30),
70
- // status VARCHAR(30),
71
- // txt LONGTEXT,
72
82
stmt , err := db .Prepare ("INSERT INTO IE (fullurl, codedate, codekey, size, codelines, language, " +
73
83
"status, txt) VALUES (?,?,?,?,?,?,?,?)" )
74
84
checkErr (err )
75
85
76
86
currentTime := time .Now ()
77
87
res , err := stmt .Exec (url , currentTime .Format ("2006-01-02 15:04:05" ), k [1 :], len (html ),
78
- strings .Count (txt , "\n " ), "language" , result [i ], txt )
88
+ strings .Count (txt , "\n " ), "language" , results [i ], txt )
79
89
if res == nil {
80
90
81
91
}
@@ -85,7 +95,6 @@ func main() {
85
95
fmt .Println (result [i ], ", " , url )
86
96
fmt .Println ("____" )
87
97
}
88
-
89
98
}
90
99
91
100
func checkErr (err error ) {
0 commit comments