-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (39 loc) · 896 Bytes
/
main.go
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
package main
import (
"flag"
"fmt"
"io"
"net/http"
"os"
"time"
)
func main() {
var old = ""
var new = ""
durationArg := flag.String("d", "10m", "Duration between scrapes")
url := flag.String("w", "https://info.mik.pte.hu/hu/zarovizsga", "Website to scrape")
flag.Parse()
for {
newResp, err := http.Get(*url)
getTime()
if err != nil {
fmt.Println("Something went wrong!:(")
}
bodyOld, err := io.ReadAll(newResp.Body)
if err != nil {
fmt.Println("Something went wrong!:(")
}
new = string(bodyOld)
duration, _ := time.ParseDuration(*durationArg)
time.Sleep(duration)
if old != new && old != "" {
fmt.Println("Fent az eredmény!:)")
os.Exit(0)
}
old = new
}
}
func getTime() {
hours, minutes, sec := time.Now().Clock()
fmt.Printf("%d:%02d:%02d - Scraped \r\n", hours, minutes, sec)
}