Skip to content

Commit

Permalink
feat: add many more federations
Browse files Browse the repository at this point in the history
  • Loading branch information
timoknapp committed Mar 13, 2023
1 parent e385e00 commit 0783f77
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 78 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@

## Features

* Currently supports the following tennis federations:
* Currently supported tennis federations:
* [Badischer Tennis Verband (BAD)](https://www.badischertennisverband.de/)
* [Hessischer Tennis Verband (HTV)](https://www.htv-tennis.de/)
* [Rheinland-Pfälzischer Tennis Verband (RPTV)](https://www.rlp-tennis.de/)
* [Sächsischer Tennis Verband (STV)](https://www.stv-tennis.de)
* [Tennisverband Mecklenburg-Vorpommern (TMV)](https://www.tennis-mv.de)
* [Tennisverband Sachsen-Anhalt (TSA)](https://www.tennis-tsa.de)
* [Thüringer Tennis-Verband (TTV)](https://www.ttv-tennis.de)
* [Tennis-Verband Niederrhein (TVN)](https://www.tvn-tennis.de)
* [Württembergischer Tennis Bund (WTB)](https://www.wtb-tennis.de/)
* Lets you find the tournaments around you
* Link to the official Tournament at [mybigpoint](https://spieler.tennis.de/web/guest/turniersuche) in order to sign up for the tournament
Expand All @@ -28,15 +33,10 @@
* [Bayerischer Tennis Verband (BTV)](https://www.btv.de)
* [Tennis-Verband Berlin-Brandenburg (TVBB)](https://www.tvbb.de)
* [Hamburger Tennis-Verband](https://www.hamburger-tennisverband.de)
* [Tennisverband Mecklenburg-Vorpommern (TMV)](https://www.tennis-mv.de)
* [Tennisverband Mittelrhein (TVM)](https://www.tvm-tennis.de)
* [Tennis-Verband Niederrhein (TVN)](https://www.tvn-tennis.de)
* [Tennisverband Niedersachsen-Bremen (TNB)](https://www.tnb-tennis.de)
* [Saarländischer Tennisbund (STB)](https://www.stb-tennis.de)
* [Sächsischer Tennis Verband (STV)](https://www.stv-tennis.de)
* [Tennisverband Sachsen-Anhalt (TSA)](https://www.tennis-tsa.de)
* [Tennisverband Schleswig-Holstein (TSH)](https://www.tennis-sh.de)
* [Thüringer Tennis-Verband (TTV)](https://www.ttv-tennis.de)
* [Tennisverband Schleswig-Holstein (TSH)](https://www.tennis.sh)
* [Westfälischer Tennis-Verband (WTV)](https://www.wtv.de)

## Getting Started
Expand Down
90 changes: 90 additions & 0 deletions backend/pkg/federation/federations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package federation

import "github.com/timoknapp/tennis-tournament-finder/pkg/models"

func GetFederations() []models.Federation {
federations := []models.Federation{
{
Id: "BAD",
Url: "https://baden.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/tournamentCalendar",
Name: "Badischer Tennisverband",
Geocoordinates: models.Geocoordinates{Lat: "49.34003", Lon: "8.68514"},
State: "Baden-Württemberg",
ApiVersion: "old",
TrustedProperties: "",
},
{
Id: "HTV",
Url: "https://htv.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/tournamentCalendar",
Name: "Hessischer Tennisverband",
Geocoordinates: models.Geocoordinates{Lat: "50.0770372", Lon: "8.7553832"},
State: "Hessen",
ApiVersion: "old",
TrustedProperties: "",
},
{
Id: "RLP",
Url: "https://www.rlp-tennis.de/spielbetrieb/turniere/appTournament.html",
Name: "Rheinland-Pfälzischer Tennisverband",
Geocoordinates: models.Geocoordinates{Lat: "49.8335079", Lon: "8.0138431"},
State: "Rheinland-Pfalz",
ApiVersion: "new",
TrustedProperties: "{\"tournamentsFilter\":{\"ageCategory\":1,\"ageGroupJuniors\":1,\"ageGroupSeniors\":1,\"circuit\":1,\"region\":1,\"fedRankValuation\":1,\"nationalValuation\":1,\"fedRank\":1,\"name\":1,\"city\":1,\"startDate\":1,\"endDate\":1,\"firstResult\":1,\"maxResults\":1}}8732571a008a8bee386504005773291f579958de",
},
{
Id: "STV",
Url: "https://stv.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/tournamentCalendar",
Name: "Sächsischer Tennisverband",
Geocoordinates: models.Geocoordinates{Lat: "51.3633218", Lon: "12.4132917"},
State: "Sachsen",
ApiVersion: "old",
TrustedProperties: "",
},
{
Id: "TMV",
Url: "https://tmv.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/tournamentCalendar",
Name: "Tennisverband Mecklenburg-Vorpommern",
Geocoordinates: models.Geocoordinates{Lat: "54.0829601", Lon: "12.0889703"},
State: "Mecklenburg-Vorpommern",
ApiVersion: "old",
TrustedProperties: "",
},
{
Id: "TSA",
Url: "https://tsa.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/tournamentCalendar",
Name: "Tennisverband Sachsen-Anhalt",
Geocoordinates: models.Geocoordinates{Lat: "52.1063933", Lon: "11.6015097"},
State: "Sachsen-Anhalt",
ApiVersion: "old",
TrustedProperties: "",
},
{
Id: "TTV",
Url: "https://ttv.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/tournamentCalendar",
Name: "Thüringer Tennisverband",
Geocoordinates: models.Geocoordinates{Lat: "51.0012441", Lon: "11.3327579"},
State: "Thüringen",
ApiVersion: "old",
TrustedProperties: "",
},
{
Id: "TVN",
Url: "https://tvn.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/tournamentCalendar",
Name: "Tennisverband Niederrhein",
Geocoordinates: models.Geocoordinates{Lat: "51.4784721", Lon: "6.9804422"},
State: "Nordrhein-Westfalen",
ApiVersion: "old",
TrustedProperties: "",
},
{
Id: "WTB",
Url: "https://www.wtb-tennis.de/turniere/turnierkalender/app/nuTournaments.html",
Name: "Württembergischer Tennisbund",
Geocoordinates: models.Geocoordinates{Lat: "48.853488", Lon: "9.1373019"},
State: "Baden-Württemberg",
ApiVersion: "new",
TrustedProperties: "a:1:{s:17:\"tournamentsFilter\";a:15:{s:11:\"ageCategory\";i:1;s:15:\"ageGroupJuniors\";i:1;s:15:\"ageGroupSeniors\";i:1;s:7:\"circuit\";i:1;s:16:\"fedRankValuation\";i:1;s:17:\"nationalValuation\";i:1;s:4:\"type\";i:1;s:7:\"fedRank\";i:1;s:6:\"region\";i:1;s:4:\"name\";i:1;s:4:\"city\";i:1;s:9:\"startDate\";i:1;s:7:\"endDate\";i:1;s:11:\"firstResult\";i:1;s:10:\"maxResults\";i:1;}}0084e646e91ed3b7e155957c5d3b286f2602eebc",
},
}
return federations
}
10 changes: 10 additions & 0 deletions backend/pkg/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ type Geocoordinates struct {
Lon string `json:"lon"`
DisplayName string `json:"display_name"`
}

type Federation struct {
Id string `json:"id"`
Url string `json:"url"`
Name string `json:"name"`
Geocoordinates Geocoordinates `json:"geocoordinates"`
State string `json:"state"`
ApiVersion string `json:"api_version"`
TrustedProperties string `json:"trusted_properties"`
}
98 changes: 31 additions & 67 deletions backend/pkg/tournament/tournament.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ import (
"fmt"
"net/http"
"strings"
"sync"
"time"

"github.com/PuerkitoBio/goquery"
"github.com/timoknapp/tennis-tournament-finder/pkg/federation"
"github.com/timoknapp/tennis-tournament-finder/pkg/models"
"github.com/timoknapp/tennis-tournament-finder/pkg/openstreetmap"
"github.com/timoknapp/tennis-tournament-finder/pkg/util"
)

func GetTournaments(w http.ResponseWriter, r *http.Request) {
federations := federation.GetFederations()

util.EnableCors(&w)
Tournaments := []models.Tournament{}

Expand All @@ -31,51 +35,33 @@ func GetTournaments(w http.ResponseWriter, r *http.Request) {
}
fmt.Printf("Get Tournaments from: %s to: %s\n", dateFrom, dateTo)

tournamentsHTV := getTournamentsFromFederationOldApi("HTV", dateFrom, dateTo)
tournamentsBAD := getTournamentsFromFederationOldApi("BAD", dateFrom, dateTo)
tournamentsRLP := getTournamentsFromFederationNewApi("RLP", dateFrom, dateTo)
tournamentsWTB := getTournamentsFromFederationNewApi("WTB", dateFrom, dateTo)

Tournaments = util.ConcatMultipleSlices([][]models.Tournament{tournamentsBAD, tournamentsHTV, tournamentsRLP, tournamentsWTB})
var wg sync.WaitGroup
for i := 0; i < len(federations); i++ {
wg.Add(1)
go func(fed models.Federation) {
defer wg.Done()
if fed.ApiVersion == "old" {
tournaments := getTournamentsFromFederationOldApi(fed, dateFrom, dateTo)
Tournaments = append(Tournaments, tournaments...)
} else if fed.ApiVersion == "new" {
tournaments := getTournamentsFromFederationNewApi(fed, dateFrom, dateTo)
Tournaments = append(Tournaments, tournaments...)
}
}(federations[i])
}
wg.Wait()

json.NewEncoder(w).Encode(Tournaments)
}

func getTournamentsFromFederationNewApi(federation string, dateFrom string, dateTo string) []models.Tournament {
fmt.Printf("Get Tournaments in: %s from: %s to: %s\n", federation, dateFrom, dateTo)
func getTournamentsFromFederationNewApi(federation models.Federation, dateFrom string, dateTo string) []models.Tournament {
fmt.Printf("Get Tournaments in: %s from: %s to: %s\n", federation.Id, dateFrom, dateTo)
var tournaments []models.Tournament

var url = ""
var trustedProperties = ""
var defaultGeocoords models.Geocoordinates
var state = ""
const urlRLP string = "https://www.rlp-tennis.de/spielbetrieb/turniere/appTournament.html"
const urlWTB string = "https://www.wtb-tennis.de/turniere/turnierkalender/app/nuTournaments.html"
const trustedPropertiesRLP string = "{\"tournamentsFilter\":{\"ageCategory\":1,\"ageGroupJuniors\":1,\"ageGroupSeniors\":1,\"circuit\":1,\"region\":1,\"fedRankValuation\":1,\"nationalValuation\":1,\"fedRank\":1,\"name\":1,\"city\":1,\"startDate\":1,\"endDate\":1,\"firstResult\":1,\"maxResults\":1}}8732571a008a8bee386504005773291f579958de"
const trustedPropertiesWTB string = "a:1:{s:17:\"tournamentsFilter\";a:15:{s:11:\"ageCategory\";i:1;s:15:\"ageGroupJuniors\";i:1;s:15:\"ageGroupSeniors\";i:1;s:7:\"circuit\";i:1;s:16:\"fedRankValuation\";i:1;s:17:\"nationalValuation\";i:1;s:4:\"type\";i:1;s:7:\"fedRank\";i:1;s:6:\"region\";i:1;s:4:\"name\";i:1;s:4:\"city\";i:1;s:9:\"startDate\";i:1;s:7:\"endDate\";i:1;s:11:\"firstResult\";i:1;s:10:\"maxResults\";i:1;}}0084e646e91ed3b7e155957c5d3b286f2602eebc"
var geoCoordsRLP = models.Geocoordinates{Lat: "49.8335079", Lon: "8.0138431"}
var geoCoordsWTB = models.Geocoordinates{Lat: "48.853488", Lon: "9.1373019"}
var stateRLP = "Rheinland-Pfalz"
var stateWTB = "Württemberg"

switch federation {
case "RLP":
url = urlRLP
trustedProperties = trustedPropertiesRLP
defaultGeocoords = geoCoordsRLP
state = stateRLP
case "WTB":
url = urlWTB
trustedProperties = trustedPropertiesWTB
defaultGeocoords = geoCoordsWTB
state = stateWTB
default:
federation = "RLP"
url = urlRLP
trustedProperties = trustedPropertiesRLP
defaultGeocoords = geoCoordsRLP
state = stateRLP
}
var url = federation.Url
var trustedProperties = federation.TrustedProperties
var defaultGeocoords = federation.Geocoordinates
var state = federation.State

var fedRankValuation = "true"
var fedRank = "20"
Expand Down Expand Up @@ -160,42 +146,20 @@ func getTournamentsFromFederationNewApi(federation string, dateFrom string, date
return tournaments
}

func getTournamentsFromFederationOldApi(federation string, dateFrom string, dateTo string) []models.Tournament {
fmt.Printf("Get Tournaments in: %s from: %s to: %s\n", federation, dateFrom, dateTo)
func getTournamentsFromFederationOldApi(federation models.Federation, dateFrom string, dateTo string) []models.Tournament {
fmt.Printf("Get Tournaments in: %s from: %s to: %s\n", federation.Id, dateFrom, dateTo)
var tournaments []models.Tournament

var url = ""
var defaultGeocoords models.Geocoordinates
var state = ""
const urlBAD string = "https://baden.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/tournamentCalendar"
const urlHTV string = "https://htv.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/tournamentCalendar"
var geoCoordsBAD = models.Geocoordinates{Lat: "49.34003", Lon: "8.68514"}
var geoCoordsHTV = models.Geocoordinates{Lat: "50.0770372", Lon: "8.7553832"}
var stateBAD = "Baden-Württemberg"
var stateHTV = "Hessen"

switch federation {
case "BAD":
url = urlBAD
defaultGeocoords = geoCoordsBAD
state = stateBAD
case "HTV":
url = urlHTV
defaultGeocoords = geoCoordsHTV
state = stateHTV
default:
federation = "BAD"
url = urlBAD
defaultGeocoords = geoCoordsBAD
state = stateBAD
}
var url = federation.Url
var defaultGeocoords = federation.Geocoordinates
var state = federation.State

var valuationState = "1" // 0=No-LK-Status, 1=LK-Status, 2=DTB-Status
var queryYoungOld = "2" // 1=Youth, 2=Adult, 3=Senior
var compType = "Herren%2BEinzel" // Tournament Type: Herren%2BEinzel, Herren%2BDoppel, Damen%2BEinzel, Damen%2BDoppel, Senioren%2BEinzel, Senioren%2BDoppel, Jugend%2BEinzel, Jugend%2BDoppel
var fedRank = "21" // LK Rank: 1-23

payload := strings.NewReader("queryName=&queryDateFrom=" + dateFrom + "&queryDateTo=" + dateTo + "&valuationState=" + valuationState + "&queryYoungOld=" + queryYoungOld + "&compType=" + compType + "&fedRank=" + fedRank + "&federation=" + federation)
payload := strings.NewReader("queryName=&queryDateFrom=" + dateFrom + "&queryDateTo=" + dateTo + "&valuationState=" + valuationState + "&queryYoungOld=" + queryYoungOld + "&compType=" + compType + "&fedRank=" + fedRank + "&federation=" + federation.Id)

client := &http.Client{}
req, err := http.NewRequest("POST", url, payload)
Expand Down
4 changes: 0 additions & 4 deletions script/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ let map = L.map('map').setView([51.133481, 10.018343], 7);
L.tileLayer('http://a.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png').addTo(map);
let markers = L.markerClusterGroup();


const urlHTV = "https://htv.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/tournamentCalendar"
const urlBAD = "https://baden.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/tournamentCalendar"
const urlRLP = "https://tvrp.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/tournamentCalendar"
// const urlBackend = "http://localhost:8080"
const urlBackend = "https://timoknapp.com/ttf"
const urlGoogleQuery = "https://maps.google.com/maps?q="
Expand Down

0 comments on commit 0783f77

Please sign in to comment.