-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
93 lines (75 loc) · 2.55 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"./dblayer"
"fmt"
"net/http"
"strconv"
"time"
)
var client *http.Client
var param string
var latestSpotId int
func main() {
//API endpoint
go endpoint()
//LOL this is so bad
//I don't have testing, which I could fix.
//I'm also testing in production.
//No-nos that I'm too lazy to change right now.
//Get users
users := dblayer.GetAllUsers()
for {
//For every user, update every device
for _, user := range users {
//fmt.Println(user)
devices := dblayer.GetDevices(user)
//Iterate through all of the users' devices
for _, device := range devices {
//Device is a SPOT GPS. First supported device.
if device.Type == "SPOT" {
//Get the latest spot id
lastSpotId, conversionErr := strconv.ParseInt(device.MostRecent, 10, 64)
if conversionErr != nil {
newLocations, err := GetNewLocations(device.Key, int(lastSpotId))
if err != nil {
fmt.Println("Error getting new locations:", err)
}
for _, location := range newLocations {
//fmt.Println("Adding new GPS location", location.MessageType)
//SPOT returns time in UTC. This will correct the time to the localized time.
dblayer.AddGPS_UTC(location.Longitude, location.Latitude, location.MessageContent, location.MessageType, user, location.UnixTime)
if location.Id > latestSpotId {
latestSpotId = location.Id
dblayer.SaveLatestSpotId(latestSpotId)
}
}
}
} //ELSE IF THIS IS ANOTHER TYPE OF DEVICE, ADD SUPPORT HERE
}
}
time.Sleep(30000 * time.Millisecond)
} //End of the infinite 'for', wait between users. Bad because the more users, the less refresh rate.
/*
//OLD CODE TO KEEP THIS BEAST RUNNING, KEPT FOR SAFE KEEPING
//update latestSpotId
latestSpotId = dblayer.GetLatestSpotId()
for {
//DO ALL SPOT UPDATES
newLocations, err := GetNewLocations("0oCHzmaKo1zRkSHQglD2qqXkT2yJPvzpK", latestSpotId)
if err != nil {
fmt.Println("Error getting new locations:", err)
}
for _, location := range newLocations {
fmt.Println("Adding new GPS location", location.MessageType)
//SPOT returns time in UTC. This will correct the time to the localized time.
dblayer.AddGPS_UTC(location.Longitude, location.Latitude, location.MessageContent, location.MessageType, "markpleskac@gmail.com", location.UnixTime)
if location.Id > latestSpotId {
latestSpotId = location.Id
dblayer.SaveLatestSpotId(latestSpotId)
}
}
//DO OTHER UPDATES FROM OTHER DEVICES
//Wait 30 seconds
time.Sleep(30000 * time.Millisecond)
}*/
}