Skip to content

Commit

Permalink
Add support to scrape Has Visto A alerts from the GRO prosecutor's of…
Browse files Browse the repository at this point in the history
…fice website
  • Loading branch information
midir99 committed Jul 18, 2022
1 parent 2f2241d commit 4eeb1b8
Show file tree
Hide file tree
Showing 5 changed files with 689 additions and 45 deletions.
14 changes: 9 additions & 5 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ import (
type Scraper string

const (
ScraperGroAlba = "gro-alba"
ScraperGroAmber = "gro-amber"
ScraperMorAmber = "mor-amber"
ScraperMorCustom = "mor-custom"
ScraperGroAlba = "gro-alba"
ScraperGroAmber = "gro-amber"
ScraperGroHasVistoA = "gro-hasvistoa"
ScraperMorAmber = "mor-amber"
ScraperMorCustom = "mor-custom"
)

func ScrapersAvailable() []Scraper {
return []Scraper{
ScraperGroAlba,
ScraperGroAmber,
ScraperGroHasVistoA,
ScraperMorAmber,
ScraperMorCustom,
}
Expand Down Expand Up @@ -129,7 +131,7 @@ func ParseArgs() (*Args, error) {
}

func PrintVersion() {
fmt.Println("rastreadora v0.0.1")
fmt.Println("rastreadora v0.2.0")
}

func SelectScraperFuncs(scraper Scraper) (func(*goquery.Document, *http.Client) []mpp.MissingPersonPoster, func(uint64) string, error) {
Expand All @@ -138,6 +140,8 @@ func SelectScraperFuncs(scraper Scraper) (func(*goquery.Document, *http.Client)
return ws.ScrapeGroAlbaAlerts, ws.MakeGroAlbaUrl, nil
case ScraperGroAmber:
return ws.ScrapeGroAmberAlerts, ws.MakeGroAmberUrl, nil
case ScraperGroHasVistoA:
return ws.ScrapeGroHasVistoAAlerts, ws.MakeGroHasVistoAAlertsUrl, nil
case ScraperMorAmber:
return ws.ScrapeMorAmberAlerts, ws.MakeMorAmberUrl, nil
case ScraperMorCustom:
Expand Down
110 changes: 88 additions & 22 deletions mpp/mpp.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package mpp

import (
"encoding/json"
"time"
)

type State string

const (
Expand Down Expand Up @@ -73,26 +78,87 @@ const (
)

type MissingPersonPoster struct {
MpName string `json:"mp_name"`
MpHeight uint `json:"mp_height,omitempty"`
MpWeight uint `json:"mp_weight,omitempty"`
MpPhysicalBuild PhysicalBuild `json:"mp_physical_build,omitempty"`
MpComplexion Complexion `json:"mp_complexion,omitempty"`
MpSex Sex `json:"mp_sex,omitempty"`
MpDob string `json:"mp_dob,omitempty"`
MpAgeWhenDisappeared uint `json:"mp_age_when_disappeared,omitempty"`
MpEyesDescription string `json:"mp_eyes_description,omitempty"`
MpHairDescription string `json:"mp_hair_description,omitempty"`
MpOutfitDescription string `json:"mp_outfit_description,omitempty"`
MpIdentifyingCharacteristics string `json:"mp_identifying_characteristics,omitempty"`
CircumstancesBehindDissapearance string `json:"circumstances_behind_dissapearance,omitempty"`
MissingFrom string `json:"missing_from,omitempty"`
MissingDate string `json:"missing_date,omitempty"`
Found bool `json:"found,omitempty"`
AlertType AlertType `json:"alert_type,omitempty"`
PoState State `json:"po_state"`
PoPostUrl string `json:"po_post_url,omitempty"`
PoPostPublicationDate string `json:"po_post_publication_date,omitempty"`
PoPosterUrl string `json:"po_poster_url,omitempty"`
IsMultiple bool `json:"is_multiple,omitempty"`
MpName string
MpHeight uint
MpWeight uint
MpPhysicalBuild PhysicalBuild
MpComplexion Complexion
MpSex Sex
MpDob time.Time
MpAgeWhenDisappeared uint
MpEyesDescription string
MpHairDescription string
MpOutfitDescription string
MpIdentifyingCharacteristics string
CircumstancesBehindDissapearance string
MissingFrom string
MissingDate time.Time
Found bool
AlertType AlertType
PoState State
PoPostUrl string
PoPostPublicationDate time.Time
PoPosterUrl string
IsMultiple bool
}

func (m MissingPersonPoster) MarshalJSON() ([]byte, error) {
var dob, missingDate, pubDate string
if !m.MpDob.IsZero() {
dob = m.MpDob.Format("2006-01-02")
}
if !m.MissingDate.IsZero() {
missingDate = m.MissingDate.Format("2006-01-02")
}
if !m.PoPostPublicationDate.IsZero() {
pubDate = m.PoPostPublicationDate.Format("2006-01-02")
}
basicMpp := struct {
MpName string `json:"mp_name"`
MpHeight uint `json:"mp_height,omitempty"`
MpWeight uint `json:"mp_weight,omitempty"`
MpPhysicalBuild PhysicalBuild `json:"mp_physical_build,omitempty"`
MpComplexion Complexion `json:"mp_complexion,omitempty"`
MpSex Sex `json:"mp_sex,omitempty"`
MpDob string `json:"mp_dob,omitempty"`
MpAgeWhenDisappeared uint `json:"mp_age_when_disappeared,omitempty"`
MpEyesDescription string `json:"mp_eyes_description,omitempty"`
MpHairDescription string `json:"mp_hair_description,omitempty"`
MpOutfitDescription string `json:"mp_outfit_description,omitempty"`
MpIdentifyingCharacteristics string `json:"mp_identifying_characteristics,omitempty"`
CircumstancesBehindDissapearance string `json:"circumstances_behind_dissapearance,omitempty"`
MissingFrom string `json:"missing_from,omitempty"`
MissingDate string `json:"missing_date,omitempty"`
Found bool `json:"found,omitempty"`
AlertType AlertType `json:"alert_type,omitempty"`
PoState State `json:"po_state"`
PoPostUrl string `json:"po_post_url,omitempty"`
PoPostPublicationDate string `json:"po_post_publication_date,omitempty"`
PoPosterUrl string `json:"po_poster_url,omitempty"`
IsMultiple bool `json:"is_multiple,omitempty"`
}{
MpName: m.MpName,
MpHeight: m.MpHeight,
MpWeight: m.MpWeight,
MpPhysicalBuild: m.MpPhysicalBuild,
MpComplexion: m.MpComplexion,
MpSex: m.MpSex,
MpDob: dob,
MpAgeWhenDisappeared: m.MpAgeWhenDisappeared,
MpEyesDescription: m.MpEyesDescription,
MpHairDescription: m.MpHairDescription,
MpOutfitDescription: m.MpOutfitDescription,
MpIdentifyingCharacteristics: m.MpIdentifyingCharacteristics,
CircumstancesBehindDissapearance: m.CircumstancesBehindDissapearance,
MissingFrom: m.MissingFrom,
MissingDate: missingDate,
Found: m.Found,
AlertType: m.AlertType,
PoState: m.PoState,
PoPostUrl: m.PoPostUrl,
PoPostPublicationDate: pubDate,
PoPosterUrl: m.PoPosterUrl,
IsMultiple: m.IsMultiple,
}
return json.Marshal(basicMpp)
}
Loading

0 comments on commit 4eeb1b8

Please sign in to comment.