-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpaste.go
52 lines (41 loc) · 1014 Bytes
/
paste.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
52
package main
import (
"encoding/json"
"log"
"time"
)
type Paste struct {
ScrapeUrl string `json:"scrape_url"`
Url string `json:"full_url"`
Key string
Content string
}
func (p *Paste) Download() {
_, exists := conf.keys[p.Key]
if exists {
return
}
// log.Printf("[+] Downloading paste: %s\n", p.Key)
resp := get(p.ScrapeUrl)
p.Content = string(resp)
conf.keys[p.Key] = time.Now()
}
func scrapePastes(c chan<- *ProcessItem) {
var pastes []*Paste
log.Println("[+] Checking for new pastes.")
resp := get("https://scrape.pastebin.com/api_scraping.php?limit=100")
err := json.Unmarshal(resp, &pastes)
if err != nil {
log.Println("[-] Could not parse list of pastes.")
log.Printf("[-] %s.\n", err.Error())
log.Println(string(resp))
return
}
log.Printf("[+] Processing %d pastes.\n", len(pastes))
for i, _ := range pastes {
p := pastes[i]
p.Download()
item := &ProcessItem{Source: "Pastebin", Location: p.Url, Key: p.Key, Content: p.Content}
c <- item
}
}