mirror of
https://github.com/idanoo/go-flat-finder.git
synced 2024-11-22 08:15:19 +00:00
71 lines
1.2 KiB
Go
71 lines
1.2 KiB
Go
|
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:"-"`
|
||
|
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() {
|
||
|
log.Printf("Polling for updates")
|
||
|
|
||
|
err := Conf.searchTrademe()
|
||
|
if err != nil {
|
||
|
log.Println(err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// Update config
|
||
|
c.storeConfig()
|
||
|
}
|