Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,7 @@ MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/

# Ignore .FIT & .GPX files
*.fit
*.gpx
# Ignore testing files
files/*

# End of https://www.toptal.com/developers/gitignore/api/linux,macos,windows,jetbrains+all,go,visualstudio,visualstudiocode
54 changes: 54 additions & 0 deletions decode/decoding.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package decode

import (
"bufio"
"bytes"
"crypto/sha512"
"encoding/hex"
"fmt"
"io/ioutil"
"math"
"os"
"strconv"
"strings"
"time"

"github.com/PuerkitoBio/goquery"
"github.com/bikedataproject/go-bike-data-lib/dbmodel"
"github.com/google/uuid"
geo "github.com/paulmach/go.geo"
"github.com/tkrajina/gpxgo/gpx"
"github.com/tormoder/fit"
Expand Down Expand Up @@ -154,3 +160,51 @@ func GpxToContribution(filedir string) (contrib dbmodel.Contribution, err error)

return
}

// GetUserFromHTML : extract a user object from an HTML-file
func GetUserFromHTML(filepath string, usr *dbmodel.User) (err error) {
// Set global user data
usr.UserIdentifier = uuid.New().String()
usr.ExpiresAt = -1
usr.ExpiresIn = -1
usr.IsHistoryFetched = true
usr.Provider = "web/LocationHistory"
usr.TokenCreationDate = time.Now()
usr.AccessToken = "0"
usr.RefreshToken = "0"

// Open HTML file
file, err := os.Open(filepath)
if err != nil {
return
}

// Create a buffer reader from the file
reader := bufio.NewReader(file)

// Create goquery documentreader
doc, err := goquery.NewDocumentFromReader(reader)
if err != nil {
return
}

// Find e-mail address in document
// Find the header element first
doc.Find(".header_title").Each(func(i int, s *goquery.Selection) {
// Split the value of this element by spaces
pageTitle := strings.Split(s.Text(), " ")
// Loop over each word
for _, word := range pageTitle {
// Find the e-mail address
if strings.Contains(word, "@") {
// Hash the e-mail
hasher := sha512.New()
hasher.Write([]byte(word))
usr.ProviderUser = hex.EncodeToString(hasher.Sum(nil))
break
}
}
})

return
}
3 changes: 0 additions & 3 deletions filehandler.go → fit-file-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"go-file-processing-daemon/decode"
"os"
"time"

"github.com/bikedataproject/go-bike-data-lib/dbmodel"
Expand Down Expand Up @@ -50,7 +49,6 @@ func HandleFitFile(file string) error {
return fmt.Errorf("Could not create contribution: %v", err)
}
log.Infof("Added contribution for user %v", userID)
os.Remove(file)
return nil
}

Expand Down Expand Up @@ -87,6 +85,5 @@ func HandleGpxFile(file string) error {
return fmt.Errorf("Could not create contribution: %v", err)
}
log.Infof("Added contribution for user %v", user.ID)
os.Remove(file)
return nil
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module go-file-processing-daemon
go 1.13

require (
github.com/bikedataproject/go-bike-data-lib/dbmodel v0.0.0-20200727162450-a47d3b297b9b
github.com/PuerkitoBio/goquery v1.5.1
github.com/bikedataproject/go-bike-data-lib/dbmodel v0.0.0-20200728150720-09b74d41943c
github.com/fatih/camelcase v1.0.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/google/uuid v1.1.1
Expand Down
12 changes: 10 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/OneOfOne/xxhash v1.2.5 h1:zl/OfRA6nftbBK9qTohYBJ5xvw6C/oNKizR7cZGl3cI=
github.com/OneOfOne/xxhash v1.2.5/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/bikedataproject/go-bike-data-lib/dbmodel v0.0.0-20200727162450-a47d3b297b9b h1:g+zqEaYpgJKUBd2fhtzcGi8PqOqnhA7m2oibnWDkhSg=
github.com/bikedataproject/go-bike-data-lib/dbmodel v0.0.0-20200727162450-a47d3b297b9b/go.mod h1:puaYhkBYtfO+uSfgHater2N6t4BAeGnNqmGs0G1rifM=
github.com/PuerkitoBio/goquery v1.5.1 h1:PSPBGne8NIUWw+/7vFBV+kG2J/5MOjbzc7154OaKCSE=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5zzsLTo=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/bikedataproject/go-bike-data-lib/dbmodel v0.0.0-20200728150720-09b74d41943c h1:43jHCoAqjXn/iAU6piEy++6HF3hT7juI60v+q8f6DXg=
github.com/bikedataproject/go-bike-data-lib/dbmodel v0.0.0-20200728150720-09b74d41943c/go.mod h1:puaYhkBYtfO+uSfgHater2N6t4BAeGnNqmGs0G1rifM=
github.com/bradfitz/latlong v0.0.0-20170410180902-f3db6d0dff40/go.mod h1:ZcXX9BndVQx6Q/JM6B8x7dLE9sl20S+TQsv4KO7tEQk=
github.com/cespare/xxhash v1.0.0 h1:naDmySfoNg0nKS62/ujM6e71ZgM2AoVdaqGwMG0w18A=
github.com/cespare/xxhash v1.0.0/go.mod h1:fX/lfQBkSCDXZSUgv6jVIu/EVA3/JNseAX5asI4c4T4=
Expand Down Expand Up @@ -61,7 +65,11 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/image v0.0.0-20190501045829-6d32002ffd75/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/lint v0.0.0-20190409202823-959b441ac422 h1:QzoH/1pFpZguR8NrRHLcO6jKqfv2zpuSqZLgdm7ZmjI=
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
Expand Down
Loading