Skip to content

Commit

Permalink
feat: add url to sporteasy in events
Browse files Browse the repository at this point in the history
  • Loading branch information
tbmc committed May 23, 2024
1 parent b38ce43 commit 0801908
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 29 deletions.
4 changes: 2 additions & 2 deletions calendar_connector/calendar_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def get_calendar_text(
cal.add("REFRESH-INTERVAL;VALUE=DURATION", "PT8H")
cal.add("X-PUBLISHED-TTL", "PT8H")

for current_team_id, team_name in teams:
for current_team_id, team_name, team_url in teams:
# Ignore other teams
if (
team_id is not None
Expand All @@ -92,7 +92,7 @@ def get_calendar_text(
for event in events:
cal.add_component(
event_to_calendar_event(
current_team_id, team_name, event, links_data
current_team_id, team_name, event, links_data, team_url
)
)

Expand Down
3 changes: 2 additions & 1 deletion calendar_connector/event_convertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ def event_to_calendar_event(
team_name: str,
event_data: EVENT_TYPE,
links_data: Optional[GenerateLinksData],
team_web_url: str,
) -> Event:
event = Event()
event.add("uid", str(event_data["id"]) + f"@sporteasy.net")
extract_event_location(event_data, event)
extract_event_dates(event_data, event)
extract_event_summary(event_data, event, team_name)
extract_event_description(team_id, event_data, event, links_data)
extract_event_description(team_id, event_data, event, links_data, team_web_url)

event.add("class", "PUBLIC")
current_timestamp = get_current_timestamp()
Expand Down
8 changes: 8 additions & 0 deletions calendar_connector/event_utils/description.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,17 @@ def _generate_response_links(
return f"{present} | {absent}"


def _generate_link_to_sporteasy(team_web_url: str, event_data: EVENT_TYPE) -> str:
id_ = event_data["id"]
return f'<a href="{team_web_url[:-1]}/event/{id_}/">SportEasy event</a>'


def extract_event_description(
team_id: int,
event_data: EVENT_TYPE,
event: Event,
links_data: Optional[GenerateLinksData],
team_web_url: str,
) -> None:
description = ""
score = extract_scores(event_data)
Expand All @@ -102,6 +108,8 @@ def extract_event_description(
response_links = _generate_response_links(team_id, event_id, links_data)
description += f"{response_links}\n"

description += f"\n{_generate_link_to_sporteasy(team_web_url, event_data)}\n"

description += f"\nLast sync: {get_formated_current_time()}\n"

event.add("description", description.strip())
10 changes: 8 additions & 2 deletions calendar_connector/sporteasy_connector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import cast
import collections

import requests

Expand All @@ -13,6 +14,8 @@
)
from calendar_connector.normalize import normalize

team_namedtuple = collections.namedtuple("team_namedtuple", ["id", "name", "web_url"])


class SporteasyConnector:
def __init__(self) -> None:
Expand All @@ -32,10 +35,13 @@ def login(self, username: str, password: str) -> str:
# csrf = authenticate_response.cookies.get(csrf_name)
return token

def list_teams(self) -> list[tuple[int, str]]:
def list_teams(self) -> list[team_namedtuple]:
response = self.session_requests.get(url_list_teams)
data = response.json()
return [(d["id"], normalize(d["name"])) for d in data["results"]]
return [
team_namedtuple(d["id"], normalize(d["name"]), d["web_url"])
for d in data["results"]
]

def list_events(self, team_id: int) -> list[EVENT_TYPE]:
response = self.session_requests.get(
Expand Down
12 changes: 4 additions & 8 deletions list_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@

teams = connector.list_teams()

team_list = [
("TEAM NAME", "TEAM ID"),
] + teams

str_template = "{:^8} | {}"
print(str_template.format("TEAM ID", "TEAM NAME"))
for team_id, team_name in teams:
print(str_template.format(team_id, team_name))
str_template = "{:^8} | {:15} | {}"
print(str_template.format("TEAM ID", "TEAM NAME", "URL"))
for team_id, team_name, team_url in teams:
print(str_template.format(team_id, team_name, team_url))
6 changes: 4 additions & 2 deletions test/data/expected_calendar_with_links.ics
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ DESCRIPTION:Présents: 8\, En attente: 7\, Non retenu: 0\, Absents: 2\n<a
2f690fb&presence=yes">Present</a> | <a href="http://localhost:5000/api/cha
nge_my_presence?team_id=1&event_id=1&user_id=None&token=1e32f46899ac900246
7942d1da1b1789a0ce6633a0e8ad6a74209aebab5e631c&presence=no">Absent</a>\n\n
Last sync: 2024-12-25 10:45:00
<a href="https://equipe1.sporteasy.net/event/1/">SportEasy event</a>\n\nLa
st sync: 2024-12-25 10:45:00
LAST-MODIFIED:20200101T010101Z
LOCATION:rue de la Paix\, 75000 Paris\, France
STATUS:TENTATIVE
Expand All @@ -45,7 +46,8 @@ DESCRIPTION:<a href="http://localhost:5000/api/change_my_presence?team_id=
2ceadd65f63d2af8b42372&presence=yes">Present</a> | <a href="http://localho
st:5000/api/change_my_presence?team_id=1&event_id=2&user_id=None&token=727
a4d5a7ab761b6a36a32eed2d6643fe41648b7a48a788682ddb2a27bfc8cfb&presence=no"
>Absent</a>\n\nLast sync: 2024-12-25 10:45:00
>Absent</a>\n\n<a href="https://equipe1.sporteasy.net/event/2/">SportEasy
event</a>\n\nLast sync: 2024-12-25 10:45:00
LAST-MODIFIED:20200101T010101Z
LOCATION:rue de la Paix\, 75000 Paris\, France
TRANSP:OPAQUE
Expand Down
8 changes: 5 additions & 3 deletions test/data/expected_calendar_without_links.ics
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ UID:[email protected]
SEQUENCE:173512350
CLASS:PUBLIC
CREATED:20200101T010101Z
DESCRIPTION:Présents: 8\, En attente: 7\, Non retenu: 0\, Absents: 2\n\nL
ast sync: 2024-12-25 10:45:00
DESCRIPTION:Présents: 8\, En attente: 7\, Non retenu: 0\, Absents: 2\n\n<
a href="https://equipe1.sporteasy.net/event/1/">SportEasy event</a>\n\nLas
t sync: 2024-12-25 10:45:00
LAST-MODIFIED:20200101T010101Z
LOCATION:rue de la Paix\, 75000 Paris\, France
STATUS:TENTATIVE
Expand All @@ -35,7 +36,8 @@ UID:[email protected]
SEQUENCE:173512350
CLASS:PUBLIC
CREATED:20200101T010101Z
DESCRIPTION:Last sync: 2024-12-25 10:45:00
DESCRIPTION:<a href="https://equipe1.sporteasy.net/event/2/">SportEasy eve
nt</a>\n\nLast sync: 2024-12-25 10:45:00
LAST-MODIFIED:20200101T010101Z
LOCATION:rue de la Paix\, 75000 Paris\, France
TRANSP:OPAQUE
Expand Down
3 changes: 2 additions & 1 deletion test/data/list_events.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"registration_parameters": {
"hide_attendance": false
},
"url": "https://sport",
"_links": {}
},
{
Expand Down Expand Up @@ -147,4 +148,4 @@
"_links": {}
}
]
}
}
8 changes: 5 additions & 3 deletions test/data/list_teams.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
},
"has_deal_advertising": true,
"total_unread_comments": 0,
"onboarding_info": null
"onboarding_info": null,
"web_url": "https://equipe1.sporteasy.net/"
},
{
"id": 2,
Expand Down Expand Up @@ -181,7 +182,8 @@
},
"has_deal_advertising": true,
"total_unread_comments": 1,
"onboarding_info": null
"onboarding_info": null,
"web_url": "https://equipe2.sporteasy.net/"
}
]
}
}
6 changes: 3 additions & 3 deletions test/test_list_teams.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import requests_mock

from calendar_connector.sporteasy_connector import SporteasyConnector
from calendar_connector.sporteasy_connector import SporteasyConnector, team_namedtuple
from test.test_utils import read_text_by_name
from calendar_connector.calendar_converter import CalendarConverter
from calendar_connector.consts import url_list_teams
Expand All @@ -15,6 +15,6 @@ def test_list_teams() -> None:
result = connector.list_teams()

assert result == [
(1, "Equipe 1"),
(2, "Equipe 2"),
team_namedtuple(1, "Equipe 1", "https://equipe1.sporteasy.net/"),
team_namedtuple(2, "Equipe 2", "https://equipe2.sporteasy.net/"),
]
5 changes: 4 additions & 1 deletion web-app/src/lib/GenerateUrl/ListTeams.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
$: data = $fetchTeamsData.map((t) => ({
id: t[0],
name: t[1]
name: t[1],
url: t[2],
}));
</script>

Expand All @@ -21,13 +22,15 @@
<tr>
<th>{$t('generateUrl.listTeams.name')}</th>
<th>{$t('generateUrl.listTeams.id')}</th>
<th>{$t('generateUrl.listTeams.link')}</th>
</tr>
</thead>
<tbody>
{#each data as teamLine (teamLine.id)}
<tr>
<td>{teamLine.name}</td>
<td>{teamLine.id}</td>
<td><a href="{teamLine.url}">{$t('generateUrl.listTeams.link')}</a></td>
</tr>
{/each}
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/lib/GenerateUrl/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function fetchTeamsGet(username: string, password: string) {

try {
const origin = getOrigin();
const response = await fetch(`${origin}/list-teams?data=${data}`);
const response = await fetch(`${origin}/api/list-teams?data=${data}`);
fetchTeamsData.set(await response.json());
} catch (e) {
console.error(e);
Expand Down
3 changes: 2 additions & 1 deletion web-app/src/lib/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"listTeams": {
"title": "Team list",
"name": "Team name",
"id": "Team id"
"id": "Team id",
"link": "Link"
},
"urlGenerated": "Generated URL"
},
Expand Down
3 changes: 2 additions & 1 deletion web-app/src/lib/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"listTeams": {
"title": "Liste des équipes",
"name": "Nom de l'équipe",
"id": "Identifiant de l'équipe"
"id": "Identifiant de l'équipe",
"link": "Lien"
},
"urlGenerated": "URL générée"
},
Expand Down

0 comments on commit 0801908

Please sign in to comment.