Skip to content

Commit f8d5b42

Browse files
authored
Merge pull request #344 from Der-Henning/dev
Update item API to v8
2 parents 96198ce + cfe1afd commit f8d5b42

File tree

14 files changed

+108
-38
lines changed

14 files changed

+108
-38
lines changed

.codecov.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
target: auto
6+
threshold: 1.0%
7+
base: auto
8+
branches:
9+
- main
10+
- dev

DOCKER_README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Readme, source, and documentation on [https://github.com/Der-Henning/tgtg](https
1010

1111
- [`edge`](https://github.com/Der-Henning/tgtg/blob/main/Dockerfile)
1212
- [`edge-alpine`](https://github.com/Der-Henning/tgtg/blob/main/Dockerfile.alpine)
13-
- [`v1`, `v1.16`, `v1.16.2`, `latest`](https://github.com/Der-Henning/tgtg/blob/v1.16.2/Dockerfile)
14-
- [`v1-alpine`, `v1.16-alpine`, `v1.16.2-alpine`, `latest-alpine`](https://github.com/Der-Henning/tgtg/blob/v1.16.2/Dockerfile.alpine)
13+
- [`v1`, `v1.16`, `v1.16.3`, `latest`](https://github.com/Der-Henning/tgtg/blob/v1.16.3/Dockerfile)
14+
- [`v1-alpine`, `v1.16-alpine`, `v1.16.3-alpine`, `latest-alpine`](https://github.com/Der-Henning/tgtg/blob/v1.16.3/Dockerfile.alpine)
1515

1616
# Quick Start
1717

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![Tests](https://github.com/Der-Henning/tgtg/actions/workflows/tests.yml/badge.svg)](https://github.com/Der-Henning/tgtg/actions/workflows/tests.yml)
2+
[![codecov](https://codecov.io/github/Der-Henning/tgtg/branch/main/graph/badge.svg?token=POHW9USW7C)](https://codecov.io/github/Der-Henning/tgtg)
23
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/der-henning/tgtg/release.yml)](https://github.com/Der-Henning/tgtg/actions/workflows/release.yml)
34
[![GitHub release](https://img.shields.io/github/release/Der-Henning/tgtg?include_prereleases=&sort=semver&color=blue)](https://github.com/Der-Henning/tgtg/releases/)
45
[![Docker Pulls](https://img.shields.io/docker/pulls/derhenning/tgtg)](https://hub.docker.com/r/derhenning/tgtg)
@@ -76,7 +77,7 @@ Method for advanced usage.
7677
2. Clone the repository `git clone https://github.com/Der-Henning/tgtg`
7778
3. Enter repository folder `cd tgtg`
7879
4. Run `pip install -r requirements.txt`
79-
5. Create config file `cp src/config.template.ini src/config.ini`
80+
5. Create config file `cp src/config.sample.ini src/config.ini`
8081
6. Modify `src/config.ini` as described in the file
8182
7. Run `python src/main.py`
8283

RELEASE_CHECKLIST.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
Since I always forget something when I create a new release, here is a small checklist for my future me.
44

5-
1. Read this checklist.
6-
2. Make sure all tests are passing.
7-
3. Do some manual testing.
8-
4. Make sure everything that should be merged is merged. (Dependency updates?)
9-
5. Update Version in `./src/_version.py`.
10-
6. Update Version and Dockerfile links in `./DOCKER_README.md`.
11-
7. Check if the readme file needs to be adjusted.
5+
* [ ] Read this checklist.
6+
* [ ] Make sure all tests are passing.
7+
* [ ] Do some manual testing.
8+
* [ ] Make sure everything that should be merged is merged. (Dependency updates?)
9+
* [ ] Update Version in `./src/_version.py`.
10+
* [ ] Update Version and Dockerfile links in `./DOCKER_README.md`.
11+
* [ ] Check if the readme file needs to be adjusted.

requirements-build.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
-r requirements.txt
22
altgraph==0.17.3
3-
pyinstaller==5.8.0
4-
pyinstaller-hooks-contrib==2023.0
3+
pyinstaller==5.9.0
4+
pyinstaller-hooks-contrib==2023.1

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ prometheus-client==0.16.0
1212
pycron==3.0.0
1313
python-pushsafer==1.1
1414
python-telegram-bot==13.15
15-
pytz==2022.7.1
15+
pytz==2023.3
1616
pytz-deprecation-shim==0.1.0.post0
1717
requests==2.28.2
1818
six==1.16.0
1919
tornado==6.1
20-
tzdata==2022.7
21-
tzlocal==4.2
20+
tzdata==2023.3
21+
tzlocal==4.3
2222
urllib3==1.26.15

src/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__title__ = "TGTG Scanner"
22
__description__ = "Provides notifications for TGTG magic bags"
3-
__version__ = "1.16.2"
3+
__version__ = "1.16.3"
44
__author__ = "Henning Merklinger"
55
__author_email__ = "[email protected]"
66
__license__ = "GPL"

src/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def main() -> NoReturn:
113113

114114
# Set all loggers to level Error
115115
for logger_name in logging.root.manager.loggerDict:
116-
logging.getLogger(logger_name).setLevel(logging.ERROR)
116+
logging.getLogger(logger_name).setLevel(logging.CRITICAL)
117117

118118
# Define stream formatter and handler
119119
stream_formatter = colorlog.ColoredFormatter(

src/models/config.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
'url': '',
4242
'cron': Cron('* * * * *'),
4343
'title': 'New Magic Bags',
44-
'body': '${{display_name}} - new amount: ${{items_available}} '
45-
'- https://share.toogoodtogo.com/item/${{item_id}}'
44+
'body': '${{display_name}} - new amount: '
45+
'${{items_available}} - ${{link}}'
4646
},
4747
'console': {
4848
'enabled': False,
@@ -77,7 +77,7 @@
7777
'key': '',
7878
'body': '{"value1": "${{display_name}}", '
7979
'"value2": ${{items_available}}, '
80-
'"value3": "https://share.toogoodtogo.com/item/${{item_id}}"}',
80+
'"value3": "${{link}}"}',
8181
'timeout': 60,
8282
'cron': Cron('* * * * *')
8383
},
@@ -86,11 +86,12 @@
8686
'server': 'https://ntfy.sh',
8787
'topic': None,
8888
'title': 'New TGTG items',
89-
'message': '${{display_name}} - New Amount: ${{items_available}} - '
90-
'https://share.toogoodtogo.com/item/${{item_id}}',
89+
'message': '${{display_name}} - New Amount: '
90+
'${{items_available}} - ${{link}}',
91+
'body': None,
9192
'priority': 'default',
9293
'tags': 'shopping,tgtg',
93-
'click': 'https://share.toogoodtogo.com/item/${{item_id}}',
94+
'click': '${{link}}',
9495
'username': None,
9596
'password': None,
9697
'timeout': 60,
@@ -330,6 +331,7 @@ def _read_ini(self) -> None:
330331
self._ini_get(config, "NTFY", "Topic", "ntfy.topic")
331332
self._ini_get(config, "NTFY", "Title", "ntfy.title")
332333
self._ini_get(config, "NTFY", "Message", "ntfy.message")
334+
self._ini_get(config, "NTFY", "Body", "ntfy.body")
333335
self._ini_get(config, "NTFY", "Priority", "ntfy.priority")
334336
self._ini_get(config, "NTFY", "Tags", "ntfy.tags")
335337
self._ini_get(config, "NTFY", "Click", "ntfy.click")
@@ -461,6 +463,7 @@ def _read_env(self) -> None:
461463
self._env_get("NTFY_TOPIC", "ntfy.topic")
462464
self._env_get("NTFY_TITLE", "ntfy.title")
463465
self._env_get("NTFY_MESSAGE", "ntfy.message")
466+
self._env_get("NTFY_BODY", "ntfy.body")
464467
self._env_get("NTFY_PRIORITY", "ntfy.priority")
465468
self._env_get("NTFY_TAGS", "ntfy.tags")
466469
self._env_get("NTFY_CLICK", "ntfy.click")

src/models/item.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import datetime
2+
import logging
23
import re
4+
from http import HTTPStatus
35

46
import humanize
7+
import requests
58

69
from models.errors import MaskConfigurationError
710

811
ATTRS = ["item_id", "items_available", "display_name", "description",
912
"price", "currency", "pickupdate", "favorite", "rating",
1013
"buffet", "item_category", "item_name", "packaging_option",
1114
"pickup_location", "store_name", "item_logo", "item_cover",
12-
"scanned_on"]
15+
"scanned_on", "item_logo_bytes", "item_cover_bytes", "link"]
16+
17+
log = logging.getLogger('tgtg')
1318

1419

1520
class Item():
@@ -77,14 +82,39 @@ def check_mask(text: str) -> None:
7782
if not match.group(1) in ATTRS:
7883
raise MaskConfigurationError(match.group(0))
7984

85+
@staticmethod
86+
def get_image(url: str) -> bytes:
87+
response = requests.get(url)
88+
if not response.status_code == HTTPStatus.OK:
89+
log.warning("Get Image Error: %s - %s",
90+
response.status_code,
91+
response.content)
92+
return None
93+
return response.content
94+
95+
@property
96+
def item_logo_bytes(self) -> bytes:
97+
return self.get_image(self.item_logo)
98+
99+
@property
100+
def item_cover_bytes(self) -> bytes:
101+
return self.get_image(self.item_cover)
102+
103+
@property
104+
def link(self) -> str:
105+
return f"https://share.toogoodtogo.com/item/{self.item_id}"
106+
80107
def unmask(self, text: str) -> str:
81108
"""
82109
Replaces variables with the current values.
83110
"""
111+
if text in ["${{item_logo_bytes}}", "${{item_cover_bytes}}"]:
112+
matches = re.findall(r"\${{([a-zA-Z0-9_]+)}}", text)
113+
return getattr(self, matches[0])
84114
for match in re.finditer(r"\${{([a-zA-Z0-9_]+)}}", text):
85115
if hasattr(self, match.group(1)):
86-
text = text.replace(match.group(0), str(
87-
getattr(self, match.group(1))))
116+
val = getattr(self, match.group(1))
117+
text = text.replace(match.group(0), str(val))
88118
return text
89119

90120
@property

0 commit comments

Comments
 (0)