Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ LOGIN_NETID=
LOGIN_PASSWORD=
LOGIN_ASTRA_USERNAME=
LOGIN_ASTRA_PASSWORD=
#Login to https://east.mymazevo.com/main-home then go to https://east.mymazevo.com/api/tenantsettings/GetApiKey
MAZEVO_API_KEY=

#Uploader
MONGODB_URI=
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func main() {
scrapeEvents := flag.Bool("events", false, "Alongside -scrape, signifies that events should be scraped.")
// Flag for astra scraping
scrapeAstra := flag.Bool("astra", false, "Alongside -scrape, signifies that Astra should be scraped.")
// Flag for mazevo scraping
scrapeMazevo := flag.Bool("mazevo", false, "Alongside -scrape, signifies that Mazevo should be scraped.")

// Flags for parsing
parse := flag.Bool("parse", false, "Puts the tool into parsing mode.")
Expand Down Expand Up @@ -100,6 +102,8 @@ func main() {
scrapers.ScrapeEvents(*outDir)
case *scrapeAstra:
scrapers.ScrapeAstra(*outDir)
case *scrapeMazevo:
scrapers.ScrapeMazevo(*outDir)
default:
log.Panic("You must specify which type of scraping you would like to perform with one of the scraping flags!")
}
Expand Down
94 changes: 94 additions & 0 deletions scrapers/mazevo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
This file contains the code for the Mazevo scraper.
*/

package scrapers

import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
"time"

"github.com/joho/godotenv"
)

func ScrapeMazevo(outDir string) {

// Load env vars
if err := godotenv.Load(); err != nil {
log.Panic("Error loading .env file")
}
apikey, present := os.LookupEnv("MAZEVO_API_KEY")
if !present {
log.Panic("MAZEVO_API_KEY is missing from .env!")
}

// Make output folder
err := os.MkdirAll(outDir, 0777)
if err != nil {
panic(err)
}

// Init http client
tr := &http.Transport{
MaxIdleConns: 10,
IdleConnTimeout: 30 * time.Second,
DisableCompression: true,
}
cli := &http.Client{Transport: tr}

// Start on previous date to make sure we have today's data, regardless of what timezone the scraper is in
date := time.Now()
startDate := date.Add(time.Hour * -24).Format(time.RFC3339)
endDate := date.Add(time.Hour * 24 * 365).Format(time.RFC3339)

// Request events
stringBody := ""
{
url := "https://east.mymazevo.com/api/PublicCalendar/GetCalendarEvents"
requestBodyMap := map[string]string{
"apiKey": apikey,
"end": endDate,
"start": startDate,
}
requestBodyBytes, _ := json.Marshal(requestBodyMap)
requestBody := bytes.NewBuffer(requestBodyBytes)
req, err := http.NewRequest("POST", url, requestBody)
if err != nil {
panic(err)
}
req.Header = http.Header{
"Content-type": {"application/json"},
"Accept": {"application/json"},
}
res, err := cli.Do(req)
if err != nil {
panic(err)
}
if res.StatusCode != 200 {
log.Panicf("ERROR: Status was: %s\nIf the status is 404, you've likely been IP ratelimited!", res.Status)
}
body, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
res.Body.Close()
stringBody = string(body)
}

// Write event data to output file
fptr, err := os.Create(fmt.Sprintf("%s/mazevoReservations.json", outDir))
if err != nil {
panic(err)
}
_, err = fptr.Write([]byte(stringBody))
if err != nil {
panic(err)
}
fptr.Close()
}