Skip to content

Commit

Permalink
Merge pull request #33 from Der-Henning/dev
Browse files Browse the repository at this point in the history
Release 1.4
  • Loading branch information
Der-Henning authored Jan 2, 2022
2 parents 335b9cb + eddc3cc commit 4b3836c
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 80 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,25 @@ jobs:
working-directory: ./src
run: python -m unittest
env:
TGTG_PASSWORD: ${{secrets.TGTG_PASSWORD}}
TGTG_USERNAME: ${{secrets.TGTG_USERNAME}}
TGTG_USERNAME: ${{secrets.TGTG_USERNAME}}
TGTG_ACCESS_TOKEN: ${{secrets.TGTG_ACCESS_TOKEN}}
TGTG_REFRESH_TOKEN: ${{secrets.TGTG_REFRESH_TOKEN}}
TGTG_USER_ID: ${{secrets.TGTG_USER_ID}}
- uses: hmanzur/actions-set-secret@v2.0.0
with:
name: 'TGTG_ACCESS_TOKEN'
value: ${{env.TGTG_ACCESS_TOKEN}}
repository: Der-Henning/tgtg
token: ${{ secrets.REPO_ACCESS_TOKEN }}
- uses: hmanzur/actions-set-secret@v2.0.0
with:
name: 'TGTG_REFRESH_TOKEN'
value: ${{env.TGTG_REFRESH_TOKEN}}
repository: Der-Henning/tgtg
token: ${{ secrets.REPO_ACCESS_TOKEN }}
- uses: hmanzur/actions-set-secret@v2.0.0
with:
name: 'TGTG_USER_ID'
value: ${{env.TGTG_USER_ID}}
repository: Der-Henning/tgtg
token: ${{ secrets.REPO_ACCESS_TOKEN }}
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ services:
environment:
- DEBUG=false ## true for debug log messages
- TGTG_USERNAME= ## TGTG Username / Login EMail
- TGTG_PASSWORD= ## TGTG Login Password
- SLEEP_TIME=20 ## Time to wait till next scan in seconds - default 20 seconds
- SLEEP_TIME=60 ## Time to wait till next scan in seconds - default 60 seconds
- ITEM_IDS= ## (optional) Comma seperated list of Item Ids to scan

- SMTP=true ## true = enable mail notifications via smtp
Expand Down
2 changes: 1 addition & 1 deletion requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-r requirements.txt
altgraph==0.17.2
pyinstaller==4.7
pyinstaller-hooks-contrib==2021.3
pyinstaller-hooks-contrib==2021.4
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
certifi==2021.10.8
charset-normalizer==2.0.7
charset-normalizer==2.0.9
idna==3.3
packaging==21.2
pyparsing==2.4.7
packaging==21.3
pyparsing==3.0.6
python-pushsafer==1.0
requests==2.26.0
urllib3==1.26.7
1 change: 0 additions & 1 deletion sample.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
TGTG_USERNAME=
TGTG_PASSWORD=

SMTP=false
SMTP_HOST=smtp.gmail.com
Expand Down
7 changes: 3 additions & 4 deletions src/config.sample.ini
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
[MAIN]
## true for debug log messages
Debug = false
## Time to wait till next scan in seconds - default 20 seconds
SleepTime = 20
## Time to wait till next scan in seconds - default 60 seconds
SleepTime = 60
## optional comma seperated list of item ids that should be scanned
ItemIDs =

[TGTG]
## TGTG Username and Password / Login EMail
## TGTG Username / Login EMail
Username =
Password =

#### Notifiers
## To enable notifier fill in the needed settings
Expand Down
8 changes: 3 additions & 5 deletions src/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Config():
def __init__(self, file=None):
self.item_ids = []
self.sleep_time = 20
self.sleep_time = 60
self.debug = False
self.tgtg = {}
self.pushSafer = {}
Expand All @@ -30,8 +30,7 @@ def _ini_reader(self, file):
',') if "ItemIDs" in config["MAIN"] else []
self.sleep_time = int(config["MAIN"]["SleepTime"])
self.tgtg = {
"username": config["TGTG"]["Username"],
"password": config["TGTG"]["Password"]
"username": config["TGTG"]["Username"]
}
self.pushSafer = {
"enabled": config["PUSHSAFER"]["enabled"].lower() in ('true', '1', 't'),
Expand Down Expand Up @@ -61,8 +60,7 @@ def _env_reader(self):
self.debug = True if environ.get(
"DEBUG", "").lower() in ('true', '1', 't') else False
self.tgtg = {
"username": environ.get("TGTG_USERNAME"),
"password": environ.get("TGTG_PASSWORD")
"username": environ.get("TGTG_USERNAME")
}
self.pushSafer = {
"enabled": environ.get("PUSH_SAFER", "").lower() in ('true', '1', 't'),
Expand Down
3 changes: 3 additions & 0 deletions src/models/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class TgtgLoginError(Error):
class TgtgAPIError(Error):
pass

class TgtgPollingError(TgtgAPIError):
pass

class ConfigurationError(Error):
pass

Expand Down
13 changes: 9 additions & 4 deletions src/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import logging
from os import path
from notifiers import Notifiers
from models import Item, Config, ConfigurationError, TGTGConfigurationError
from models import Item, Config, TgtgAPIError, Error, ConfigurationError, TGTGConfigurationError
from packaging import version
import requests

VERSION_URL = 'https://api.github.com/repos/Der-Henning/tgtg/releases/latest'
VERSION = "1.3.0"
VERSION = "1.4"

prog_folder = path.dirname(sys.executable) if getattr(
sys, '_MEIPASS', False) else path.dirname(path.abspath(__file__))
Expand Down Expand Up @@ -41,10 +41,12 @@ def __init__(self):
try:
self.tgtg_client = TgtgClient(
email=self.config.tgtg["username"],
password=self.config.tgtg["password"],
timeout=60)
self.tgtg_client.login()
except:
except TgtgAPIError as err:
raise
except Error as err:
log.error(err)
raise TGTGConfigurationError()
self.notifiers = Notifiers(self.config)

Expand Down Expand Up @@ -145,6 +147,9 @@ def main():
except ConfigurationError as err:
log.error("Configuration Error - {0}".format(err))
sys.exit(1)
except TgtgAPIError as err:
log.error("TGTG API Error: {0}".format(err))
sys.exit(1)
except KeyboardInterrupt:
log.info("Shutting down scanner ...")
except:
Expand Down
37 changes: 14 additions & 23 deletions src/tests/tgtg/test_tgtg.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
import unittest
from .constants import GLOBAL_PROPERTIES, ITEM_PROPERTIES, STORE_PROPERTIES
from .constants import GLOBAL_PROPERTIES
from tgtg import TgtgClient
from os import environ

class TGTG_API_Test(unittest.TestCase):
def test_get_items(self):
client = TgtgClient(
email=environ["TGTG_USERNAME"], password=environ["TGTG_PASSWORD"]
)
data = client.get_items(
favorites_only=True
email=environ.get("TGTG_USERNAME", None),
access_token=environ.get("TGTG_ACCESS_TOKEN", None),
refresh_token=environ.get("TGTG_REFRESH_TOKEN", None),
user_id=environ.get("TGTG_USER_ID", None),
)
credentials = client.get_credentials()
env_file = environ.get('GITHUB_ENV', None)
if env_file:
with open(env_file, "a") as myfile:
myfile.write("TGTG_ACCESS_TOKEN={}\n".format(credentials["access_token"]))
myfile.write("TGTG_REFRESH_TOKEN={}\n".format(credentials["refresh_token"]))
myfile.write("TGTG_USER_ID={}\n".format(credentials["user_id"]))
data = client.get_items(favorites_only=True)
assert len(data) > 0
for property in GLOBAL_PROPERTIES:
assert property in data[0]


def test_get_one_item(self):
client = TgtgClient(
email=environ["TGTG_USERNAME"], password=environ["TGTG_PASSWORD"]
)
item_id = "36684"
data = client.get_item(item_id)

for property in GLOBAL_PROPERTIES:
assert property in data
for property in ITEM_PROPERTIES:
assert property in data["item"]
for property in STORE_PROPERTIES:
assert property in data["store"]

assert data["item"]["item_id"] == item_id
assert property in data[0]
Loading

0 comments on commit 4b3836c

Please sign in to comment.