Skip to content

Commit ba8f69a

Browse files
committed
Beta version
Implemented: * db connection * getting recent codes * downloading codes
1 parent 3c008ee commit ba8f69a

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

Main.go

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,65 @@ package main
22

33
import (
44
"fmt"
5+
_ "github.com/go-sql-driver/mysql"
56
"github.com/gocolly/colly"
7+
"io"
8+
"log"
9+
"net/http"
10+
"os"
11+
"strings"
612
)
713

8-
func main() {
14+
func getRecentLinks() (string, string) {
915
c := colly.NewCollector(colly.AllowedDomains("ideone.com"))
1016

17+
var ret string
18+
var result string
19+
1120
c.OnHTML("strong", func(htmlElement *colly.HTMLElement) {
12-
link := htmlElement.Attr("href")
13-
fmt.Printf("Found link: %q -> %s\n", htmlElement.Text, link)
21+
ret += ";" + htmlElement.Text
22+
})
23+
24+
c.OnHTML("span .info", func(htmlElement *colly.HTMLElement) {
25+
result += ";" + htmlElement.Text
1426
})
1527

1628
c.Visit("https://ideone.com/recent")
1729

30+
return ret, result
1831
}
32+
33+
func main() {
34+
links, result := getRecentLinks()
35+
fmt.Print(result)
36+
37+
split := strings.Split(links, ";")
38+
split = split[1:49]
39+
for _, k := range split {
40+
fmt.Printf("https://ideone.com/plain/%s \n", k[1:])
41+
var url = "https://ideone.com/plain/" + k[1:]
42+
43+
response, err := http.Get(url)
44+
if err != nil {
45+
log.Fatal(err)
46+
} else {
47+
defer response.Body.Close()
48+
_, err := io.Copy(os.Stdout, response.Body)
49+
if err != nil {
50+
log.Fatal(err)
51+
}
52+
}
53+
}
54+
55+
//jdbc:mariadb://192.168.1.65:3306/ideone
56+
//db, err := sql.Open("mysql", "jdbc:mariadb://192.168.1.65:3306/ideone")
57+
//checkErr(err)
58+
59+
60+
}
61+
62+
func checkErr(err error) {
63+
if err != nil {
64+
panic(err)
65+
}
66+
}

0 commit comments

Comments
 (0)