Skip to content

Commit bf24ffd

Browse files
authored
Apr, 23 Updates (#32)
1 parent 986b36b commit bf24ffd

File tree

8 files changed

+17
-25
lines changed

8 files changed

+17
-25
lines changed

.devcontainer/requirements.prod.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ python-dateutil
88
numpy
99
Pillow
1010
gitpython
11+
babel

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN apk add --update \
1010
libc-dev \
1111
libffi-dev \
1212
openssl-dev \
13-
musl-locales \
13+
git \
1414
&& rm -rf /var/cache/apk/*
1515

1616
COPY assets/. ./assets

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Join the notification #channel on [Telegram](https://t.me/sammy_ofer_notificatio
1313

1414
## Web-UI
1515

16-
![Web-UI screenshot](screen.png)****
16+
![Web-UI screenshot](screen.png)
1717

1818
## Static landing page ([link](https://drehelis.github.io/sammy_ofer/static.html))
1919

@@ -33,6 +33,7 @@ docker run -d --name sammy_ofer \
3333
--restart=on-failure \
3434
--env TELEGRAM_CHANNEL_ID=<required> \
3535
--env TELEGRAM_TOKEN=<required> \
36+
--env GH_PAT (optional) \
3637
sammy_ofer:latest
3738
```
3839

assets/templates/static_page.jinja2

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<div class="metadata-item">📣: {{ notes }}</div>
4040
{% endif %}
4141
<div class="metadata-item"><img src="assets/images/qrcode.png" alt="QR Code" style="max-width: 100px; margin-top: 1rem;"></div>
42-
<div><img src="https://img.shields.io/endpoint?color=neon&style=plastic&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Fsammy_ofer_notification_channel"></div>
42+
<div><img src="https://img.shields.io/endpoint?color=neon&style=plastic&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Fsammy_ofer_notification_channel&label=Sammy%20Ofer%20Notification%20Channel"></div>
4343
</div>
4444
</div>
4545
<script>
@@ -54,7 +54,7 @@
5454
<div class="metadata">
5555
<div class="metadata-item">⚪ המשחק ⚽ הבא: {{ games['game_1'][0].strftime('%A, %d/%m/%Y') }} ⚪</div>
5656
<div class="metadata-item"><img src="assets/images/qrcode.png" alt="QR Code" style="max-width: 100px; margin-top: 1rem;"></div>
57-
<img src="https://img.shields.io/endpoint?color=neon&style=plastic&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Fsammy_ofer_notification_channel">
57+
<img src="https://img.shields.io/endpoint?color=neon&style=plastic&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Fsammy_ofer_notification_channel&label=Sammy%20Ofer%20Notification%20Channel">
5858
</div>
5959
</div>
6060

html_templates/next.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<div class="divTableRow">
8585
<div class="divTableCell">{{ loop.index }}</div>
8686
<div class="divTableCell">{{ scraped_date_time.strftime('%Y-%m-%d') }}</div>
87-
<div class="divTableCell">{{ scraped_date_time.strftime('%A') }}</div>
87+
<div class="divTableCell">{{ scraped_date_time | babel_format_day_heb }}</div>
8888
<div class="divTableCell">{{ scraped_date_time.strftime('%H:%M') }}</div>
8989
<div class="divTableCell">{{ league }}</div>
9090
<div class="divTableCell"><img width="18" height="18" src="assets/teams/{{ home_team_en }}.png">&nbsp;<a href="{{ home_team_url }}" target="_blank">{{ home_team }}</a></div>

static_html_page.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
from pathlib import Path
44
from shutil import copy
55
import datetime
6+
import os
67

78
from git import Repo
89
from logger import logger
910

10-
REPO_URL = "https://github.com/drehelis/sammy_ofer"
11+
REPO_URL = f"https://{os.getenv("GH_PAT")}@github.com/drehelis/sammy_ofer"
1112
TMP_REPO_DIR = "/tmp/sammy_ofer"
1213
STATIC_HTML_FILENAME = "static.html"
1314
GH_PAGES_BRANCH = "static_page"
@@ -42,6 +43,9 @@ def git_commit():
4243
except:
4344
repo = Repo.clone_from(REPO_URL, TMP_REPO_DIR)
4445

46+
repo.config_writer().set_value("user", "name", "sammy-ofer-bot").release()
47+
repo.config_writer().set_value("user", "email", "[email protected]").release()
48+
4549
try:
4650
repo.git.checkout(GH_PAGES_BRANCH)
4751
except:

web.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,19 @@
99
from flask import Flask, render_template, request
1010
from flask.helpers import send_file
1111
from markupsafe import Markup
12-
from spectators import SPECTATORS
1312

13+
from spectators import SPECTATORS
1414
import web_scrape
1515

1616

17-
def b64encode(s):
18-
return base64.b64encode(s.encode())
19-
17+
def babel_format_day_heb(s):
18+
from babel.dates import format_date
2019

21-
def b64decode(s):
22-
data = base64.b64decode(s)
23-
return data.decode()
20+
return format_date(s, "EEEE", locale="he")
2421

2522

2623
app = Flask(__name__, template_folder="html_templates")
27-
app.jinja_env.filters["b64encode"] = b64encode
28-
app.jinja_env.filters["b64decode"] = b64decode
24+
app.jinja_env.filters["babel_format_day_heb"] = babel_format_day_heb
2925

3026

3127
@app.route("/next", methods=["GET"])

web_scrape.py

-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from dateutil import parser
99
from pathlib import Path
1010
from logger import logger
11-
import locale
1211
import requests
1312
import re
1413

@@ -19,15 +18,6 @@
1918
from static_html_page import gen_static_page
2019
from metadata import TEAMS_METADATA, DESKTOP_AGENTS
2120

22-
try:
23-
locale.setlocale(locale.LC_TIME, "he_IL") # MacOS
24-
except locale.Error:
25-
try:
26-
# apt-get install language-pack-he language-pack-he-base
27-
locale.setlocale(locale.LC_TIME, "he_IL.UTF-8") # Ubuntu
28-
except locale.Error:
29-
pass
30-
3121

3222
def random_ua():
3323
return {"User-Agent": choice(DESKTOP_AGENTS)}

0 commit comments

Comments
 (0)