Skip to content

Commit 1416f06

Browse files
authored
Apr, 15 Updates (#29)
1 parent b64c585 commit 1416f06

11 files changed

+308
-55
lines changed

.devcontainer/requirements.prod.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ python-telegram-bot
66
requests
77
python-dateutil
88
numpy
9-
Pillow
9+
Pillow
10+
gitpython

assets/qrcode/qrcode.png

57.2 KB
Loading

assets/teams/Bnei Sakhnin.png

15.3 KB
Loading

assets/teams/Maccabi Tel Aviv.png

53.2 KB
Loading

assets/templates/static_page.jinja2

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="refresh" content="60">
7+
<title>Sammy Ofer Notification</title>
8+
<link href="templates/style.css" rel="stylesheet" type="text/css">
9+
<script>
10+
const currentDate = new Date();
11+
const day = currentDate.getDate();
12+
const month = ("0" + (currentDate.getMonth() + 1)).slice(-2);
13+
const year = currentDate.getFullYear();
14+
const todayDate = `${year}-${month}-${day}`;
15+
</script>
16+
</head>
17+
<body>
18+
{% for key, value in games.items() %}
19+
{% set scraped_date_time, league, home_team, home_team_en, home_team_url, game_hour, guest_team, guest_team_en, guest_team_url, game_time_delta, road_block_time, specs_word, specs_number, poll, notes, custom_sepcs_number, custom_road_block_time = value %}
20+
<header id="header-{{loop.index}}" class="header" dir="rtl">
21+
<div class="top-right"><img src="assets/qrcode/qrcode.png" width="192" height="192"></div>
22+
<div>משחק ⚽ היום בשעה: <i>{{ game_hour }}</i></div>
23+
<div>צפי חסימת כבישים: <i>{{ custom_road_block_time }}</i></div>
24+
<div>צפי אוהדים משוער: <i>{{ specs_word }} {{ custom_sepcs_number | replace("\\", "") }}</i></div>
25+
{% if notes %}
26+
<div>📣: <i>{{ notes }}</i></div>
27+
{% endif %}
28+
</header>
29+
30+
<div id="match-container-{{loop.index}}" class="match-container">
31+
<div class="team">
32+
<img src="assets/teams/{{ home_team_en }}.png" class="team-logo">
33+
<div class="team-name">{{ home_team }}</div>
34+
</div>
35+
36+
<div class="vs-logo">
37+
<hr class="style-two"></hr>
38+
<img class="vs-logo" src="assets/versus/vs9.png" alt="VS Logo">
39+
<hr class="style-two"></hr>
40+
</div>
41+
42+
<div class="team">
43+
<img src="assets/teams/{{ guest_team_en }}.png" class="team-logo">
44+
<div class="team-name">{{ guest_team }}</div>
45+
46+
</div>
47+
</div>
48+
<script>
49+
const gameDate_{{loop.index}} = "{{ scraped_date_time.strftime('%Y-%m-%d') }}";
50+
if (todayDate !== gameDate_{{loop.index}}) {
51+
document.getElementById('header-{{loop.index}}').style.display = 'none';
52+
document.getElementById('match-container-{{loop.index}}').style.display = 'none';
53+
}
54+
</script>
55+
{% endfor %}
56+
57+
<div class="footer">
58+
<div class="column left" id="last-modified"><script>var x = document.getElementById("last-modified"); x.innerHTML = new Date(document.lastModified);</script></div>
59+
<div class="column center"><img src="https://img.shields.io/endpoint?color=neon&style=plastic&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Fsammy_ofer_notification_channel"></div>
60+
<div class="column right" id="resolution"><script>var w = window.innerWidth; var h = window.innerHeight; var x = document.getElementById("resolution"); x.innerHTML = "Browser resolution: " + w + "x" + h;</script></div>
61+
</div>
62+
63+
</body>
64+
</html>

assets/templates/style.css

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
* {
2+
margin: 0;
3+
padding: 0;
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
font-family: Arial, sans-serif;
9+
font-size: 16px;
10+
color: #333;
11+
background-color: #f5f5f5;
12+
}
13+
14+
header {
15+
background-color: #1a3e67;
16+
padding: 15px;
17+
text-align: center;
18+
}
19+
20+
/* Match details styles */
21+
.match-container {
22+
display: flex;
23+
flex-direction: column;
24+
align-items: center;
25+
justify-content: center;
26+
padding: 40px 20px;
27+
}
28+
29+
.team {
30+
display: flex;
31+
align-items: center;
32+
margin-bottom: 20px;
33+
}
34+
35+
.team-logo {
36+
/* width: 50px;
37+
height: 50px; */
38+
margin-right: 20px;
39+
}
40+
41+
.vs-logo {
42+
width: 128px;
43+
height: 128px;
44+
}
45+
46+
.team-name {
47+
font-size: 48px;
48+
font-weight: bold;
49+
color: #1a3e67;
50+
}
51+
52+
.footer {
53+
font-family: Arial, sans-serif;
54+
display: flex;
55+
padding: 10px;
56+
position: fixed;
57+
left: 0;
58+
bottom: 0;
59+
width: 100%;
60+
background-color: #e0e0e0;
61+
color: #1a3e67;
62+
}
63+
64+
.header {
65+
color: #fff;
66+
font-size: 60px;
67+
font-weight: bold;
68+
}
69+
70+
.column {
71+
flex-basis: 100%;
72+
/* Adjust width as needed */
73+
}
74+
75+
.left {
76+
text-align: left;
77+
}
78+
79+
.center {
80+
text-align: center;
81+
}
82+
83+
.right {
84+
text-align: right;
85+
}
86+
87+
.top-right {
88+
position: absolute;
89+
right: 5;
90+
top: 5;
91+
}
92+
93+
hr.style-two {
94+
border: 0;
95+
height: 1px;
96+
background-image: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));
97+
}

cron.py

+8-16
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,10 @@ def create_message(*args):
6161
specs_number,
6262
poll,
6363
notes,
64+
custom_sepcs_number,
65+
custom_road_block_time,
6466
) = item
6567

66-
custom_sepcs_number = f"\\({specs_number:,}\\)"
67-
custom_road_block_time = f"החל מ {road_block_time}"
68-
if int(specs_number) >= 28000:
69-
custom_sepcs_number = f"\\({specs_number:,}\\) 😱"
70-
if 1 <= int(specs_number) <= 6000:
71-
custom_sepcs_number = f"\\({specs_number:,}\\) 🤏"
72-
if specs_word == "ללא" or int(specs_number) <= 6000:
73-
custom_road_block_time = "אין"
74-
elif specs_word == "גדול מאוד":
75-
custom_road_block_time = f"החל מ {(datetime.datetime.strptime(road_block_time,'%H:%M') - datetime.timedelta(hours=1)).strftime('%H:%M')}"
76-
7768
yield f"""
7869
משחק ⚽ *היום* בשעה *{game_hour}*
7970
*{league}*: [{home_team}]({home_team_url}) \\|\\| [{guest_team}]({guest_team_url})
@@ -141,9 +132,10 @@ async def send(msg, token=TELEGRAM_TOKEN, chat_id=TELEGRAM_CHANNEL_ID):
141132
scraped_games = web.decoratored_games(scrape)
142133
generated_data = check_games_today(scraped_games)
143134
detected_games_today = list(generated_data)
144-
if detected_games_today:
145-
message = create_message(detected_games_today)
146-
asyncio.run(send(message))
147-
else:
135+
message = create_message(detected_games_today)
136+
137+
if not detected_games_today:
148138
logger.info("There is only one thing we say to death - Not today!")
149-
sys.exit(1)
139+
sys.exit(0)
140+
141+
asyncio.run(send(message))

html_templates/next.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
</div>
7676
</div>
7777
{% for key, value in mygames.items() %}
78-
{% set scraped_date_time, league, home_team, home_team_en, home_team_url, game_hour, guest_team, guest_team_en, guest_team_url, game_time_delta, game_hour_delta, specs_word, specs_number, poll, notes = value %}
78+
{% set scraped_date_time, league, home_team, home_team_en, home_team_url, game_hour, guest_team, guest_team_en, guest_team_url, game_time_delta, road_block_time, specs_word, specs_number, poll, notes, custom_sepcs_number, custom_road_block_time = value %}
7979
{% if guest_team_url != '' %}
8080
{% set guest_team_alter = '<a href="' ~ guest_team_url ~ '" target="_blank">' ~ guest_team ~ '</a>' %}
8181
{% else %}

metadata.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
]
88

99
TEAMS_METADATA = {
10-
"Unavailable": {
11-
"name": "Unavailable",
12-
"url": "",
13-
"logo": ""
14-
},
10+
"Unavailable": {"name": "Unavailable", "url": "", "logo": ""},
1511
"מכבי חיפה": {
1612
"name": "Maccabi Haifa",
1713
"url": "https://www.football.co.il/maccabi-haifa",
@@ -62,6 +58,11 @@
6258
"url": "https://www.football.co.il/bnei-sakhnin",
6359
"logo": "https://static.football.co.il/wp-content/themes/kingclub-theme/images/teams/15960.png",
6460
},
61+
'מכבי ת"א': {
62+
"name": "Maccabi Tel Aviv",
63+
"url": "https://www.football.co.il/maccabi-tel-aviv",
64+
"logo": "https://static.football.co.il/wp-content/themes/kingclub-theme/images/teams/4536.png",
65+
},
6566
}
6667

6768
EMOJI_HEARTS = [

static_html_page.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from jinja2 import Environment, FileSystemLoader
2+
from random import choice
3+
from pathlib import Path
4+
from shutil import copy
5+
import datetime
6+
7+
from git import Repo
8+
from logger import logger
9+
10+
REPO_URL = "https://github.com/drehelis/sammy_ofer"
11+
TMP_REPO_DIR = "/tmp/sammy_ofer"
12+
STATIC_HTML_FILENAME = "static.html"
13+
14+
15+
def gen_static_page(obj):
16+
environment = Environment(loader=FileSystemLoader("assets/templates"))
17+
template = environment.get_template("static_page.jinja2")
18+
19+
content = template.render(games=obj)
20+
21+
try:
22+
with open(STATIC_HTML_FILENAME, mode="r", encoding="utf-8") as f:
23+
existing_content = f.read()
24+
except FileNotFoundError:
25+
existing_content = None
26+
27+
if existing_content == content:
28+
return
29+
30+
with open(STATIC_HTML_FILENAME, mode="w", encoding="utf-8") as f:
31+
f.write(content)
32+
logger.info(f"Generated {STATIC_HTML_FILENAME} from template")
33+
34+
git_commit()
35+
36+
37+
def git_commit():
38+
try:
39+
repo = Repo(TMP_REPO_DIR)
40+
repo.remotes.origin.pull("master")
41+
except:
42+
repo = Repo.clone_from(REPO_URL, TMP_REPO_DIR)
43+
try:
44+
repo.git.checkout("static_page")
45+
except:
46+
repo.git.checkout(b="static_page")
47+
48+
src = Path(__file__).resolve().parent / STATIC_HTML_FILENAME
49+
copy(src, f"{TMP_REPO_DIR}/{STATIC_HTML_FILENAME}")
50+
51+
repo.index.add([STATIC_HTML_FILENAME])
52+
if not repo.index.diff("HEAD"):
53+
logger.info(f"{STATIC_HTML_FILENAME} is up to date")
54+
return
55+
56+
logger.info(f"{STATIC_HTML_FILENAME} pushed to repo")
57+
repo.index.commit(str(datetime.datetime.now()))
58+
repo.git.push("--force")
59+
repo.git.reset("--hard", "origin/master")

0 commit comments

Comments
 (0)