Skip to content

Commit

Permalink
Adds MD5 for id calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Leduc-Hamel committed Feb 28, 2021
1 parent 4ba8b4d commit b17de97
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion services/rougecombien/pkg/scraper/overflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package scraper

import (
"context"
"crypto/md5"
"crypto/sha1"
"encoding/base64"
"encoding/csv"
"fmt"
"io"
"net/http"
"strconv"
"strings"
Expand All @@ -30,14 +32,23 @@ type Result struct {

func (r *Result) Sha1() string {
hasher := sha1.New()
_, err := hasher.Write([]byte(fmt.Sprintf("%f", r.Outflow)))
_, err := hasher.Write([]byte(fmt.Sprintf("%d:%f", r.TakenAt, r.Outflow)))
if err != nil {
return ""
}

return base64.URLEncoding.EncodeToString(hasher.Sum(nil))
}

func (r *Result) MD5() string {
hasher := md5.New()
_, err := io.WriteString(hasher, fmt.Sprintf("%d:%f", r.TakenAt, r.Outflow))
if err != nil {
return ""
}
return string(hasher.Sum(nil))
}

func NewScraper(cfg *config.Config, consumer func(context.Context, Result) error) *Scraper {
return &Scraper{cfg: cfg, client: &http.Client{}, consumer: consumer}
}
Expand Down

0 comments on commit b17de97

Please sign in to comment.