Skip to content

Commit 6290f5d

Browse files
scraper: refactor package
1 parent 91ea7c0 commit 6290f5d

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

scraper/csv.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package scraper
2+
3+
import "github.com/pocketbase/pocketbase/models"
4+
5+
func PriceRecordstoCsv(records []*models.Record) (string, error) {
6+
var csvString string
7+
csvString += "Symbol,Date,Currency,Source,Close\n"
8+
for _, record := range records {
9+
csvString += record.GetString("symbol") + "," + record.GetDateTime("date").Time().Format("2006-01-02") + "," + record.GetString("currency") + "," + record.GetString("source") + "," + record.GetString("closePrice") + "\n"
10+
}
11+
return csvString, nil
12+
}

scraper/model.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package scraper
2+
3+
import "github.com/pocketbase/pocketbase/models"
4+
5+
var _ models.Model = (*SymbolPrice)(nil)
6+
7+
type SymbolPrice struct {
8+
models.BaseModel
9+
Date string
10+
Close float64
11+
}
12+
13+
func (*SymbolPrice) TableName() string {
14+
return "prices"
15+
}
16+
17+
type Scrape struct {
18+
models.BaseModel
19+
Source string
20+
Symbol string
21+
StartDate string
22+
EndDate string
23+
Currency string
24+
}
25+
26+
func (*Scrape) TableName() string {
27+
return "scrapes"
28+
}
29+
30+
type ApiResponse struct {
31+
Message string `json:"message"`
32+
Data interface{} `json:"data"`
33+
}

scraper/scraper.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package scraper
2+
3+
import (
4+
"time"
5+
)
6+
7+
const (
8+
DateFormat = "2006-01-02"
9+
)
10+
11+
type Scraper interface {
12+
GetSymbolData(symbol string, startDate, endDate time.Time) (<-chan *SymbolPrice, error)
13+
//scrapeChunk(symbol string, startDate time.Time, endDate time.Time) (<-chan SymbolPrice, error)
14+
//getChunkSize() int
15+
}

0 commit comments

Comments
 (0)