go-flat-finder/internal/flatfinder/main.go

70 lines
1.2 KiB
Go
Raw Permalink Normal View History

2022-09-13 07:31:25 +00:00
package flatfinder
import (
"log"
"time"
"github.com/disgoorg/disgo/webhook"
)
// Our local struct we will store data during runtime
type LocalConfig struct {
DiscordWebhook string `json:"-"`
2022-09-13 11:25:11 +00:00
DiscordTag string `json:"-"`
2022-09-13 07:31:25 +00:00
DiscordClient webhook.Client `json:"-"`
GoogleApiToken string `json:"-"`
GoogleLocation1 string `json:"-"`
GoogleLocation2 string `json:"-"`
TradeMeKey string `json:"-"`
TradeMeSecret string `json:"-"`
Suburbs string `json:"-"`
BedroomsMin string `json:"-"`
BedroomsMax string `json:"-"`
PriceMax string `json:"-"`
PropertyTypes string `json:"-"`
PostedProperties map[int64]bool `json:"properties"`
}
var Conf LocalConfig
// Launch!
func Launch() {
// Load discord
Conf.initDiscord()
// Load previously posted properties
Conf.loadConfig()
// Intial run
Conf.pollUpdates()
// Run every minute!
ticker := time.NewTicker(1 * time.Minute)
quit := make(chan struct{})
for {
select {
case <-ticker.C:
Conf.pollUpdates()
case <-quit:
ticker.Stop()
return
}
}
}
// pollUpdates - check for new listings!
func (c *LocalConfig) pollUpdates() {
err := Conf.searchTrademe()
if err != nil {
log.Println(err)
return
}
// Update config
c.storeConfig()
}