Skip to content

Commit 91b6409

Browse files
committedSep 12, 2021
switched config to ini. removed pyinstyller workflows
1 parent 9573ebb commit 91b6409

13 files changed

+109
-118
lines changed
 

‎.github/workflows/pyinstaller-linux.yml

-36
This file was deleted.

‎.github/workflows/pyinstaller-windows.yml

-36
This file was deleted.

‎.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ __pycache__
22
build
33
dist
44

5-
docker-compose.dev.yml
5+
.env

‎README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ If someone wants to make a detailed guide, feel free to contribute to the projec
2121

2222
1. Download Release from https://github.com/Der-Henning/tgtg/releases
2323
2. Unzip Archiv
24-
3. Edit ```.env``` as described in the file
24+
3. Create ```config.ini``` as described in the file ```config.template.ini```
2525
4. Run scanner
2626

2727
### Install from source
@@ -30,7 +30,7 @@ If someone wants to make a detailed guide, feel free to contribute to the projec
3030

3131
1. Install python3
3232
2. Run ```pip3 install -r requirements.txt```
33-
3. Edit ```/src/.env``` as described in the file
33+
3. Create ```/src/config.ini``` as described in the file ```config.template.ini```
3434
4. Register ```python {install directory}/src/scanner.py``` as a service or just run it manually
3535

3636
#### With Docker

‎docker-compose.dev.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: "3.3"
2+
services:
3+
app:
4+
build: .
5+
environment:
6+
- DEBUG=true
7+
env_file:
8+
- .env

‎icon.ico

14.7 KB
Binary file not shown.

‎requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
certifi==2021.5.30
22
chardet==4.0.0
33
idna==2.10
4-
python-dotenv==0.19.0
54
python-pushsafer==0.4
65
requests==2.25.1
76
tgtg==0.5.0

‎scanner.spec

+9-13
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ block_cipher = None
77
a = Analysis(['src/scanner.py'],
88
pathex=['/home/app'],
99
binaries=[],
10-
datas=[('src/models', 'models'),('src/notifiers', 'notifiers'),('src/.env', '.')],
11-
hiddenimports=['pushsafer', 'requests', 'smtplib', 'email.mime.multipart', 'email.mime.text'],
10+
datas=[],
11+
hiddenimports=[],
1212
hookspath=[],
1313
hooksconfig={},
1414
runtime_hooks=[],
@@ -21,24 +21,20 @@ pyz = PYZ(a.pure, a.zipped_data,
2121
cipher=block_cipher)
2222

2323
exe = EXE(pyz,
24-
a.scripts,
24+
a.scripts,
25+
a.binaries,
26+
a.zipfiles,
27+
a.datas,
2528
[],
26-
exclude_binaries=True,
2729
name='scanner',
2830
debug=False,
2931
bootloader_ignore_signals=False,
3032
strip=False,
3133
upx=True,
34+
upx_exclude=[],
35+
runtime_tmpdir=None,
3236
console=True,
3337
disable_windowed_traceback=False,
3438
target_arch=None,
3539
codesign_identity=None,
36-
entitlements_file=None )
37-
coll = COLLECT(exe,
38-
a.binaries,
39-
a.zipfiles,
40-
a.datas,
41-
strip=False,
42-
upx=True,
43-
upx_exclude=[],
44-
name='scanner')
40+
entitlements_file=None , icon='icon.ico')

‎src/.env

-22
This file was deleted.

‎src/__init__.py

Whitespace-only changes.

‎src/config.sample.ini

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[MAIN]
2+
## true for debug log messages
3+
Debug = false
4+
## Time to wait till next scan in seconds - default 20 seconds
5+
SleepTime = 20
6+
;ItemIDs =
7+
8+
[TGTG]
9+
## TGTG Username and Password / Login EMail
10+
Username =
11+
Password =
12+
13+
#### Notifiers
14+
## To enable notifier fill in the needed settings
15+
## and set enabled to true
16+
17+
[SMTP]
18+
## SMTP Settings / Example for gmail
19+
enabled = true
20+
Host = smtp.gmail.com
21+
Port = 465
22+
Username = max.mustermann@gmail.com
23+
Password =
24+
TLS = true
25+
Sender = max.mustermann@gmail.com
26+
Recipient = max.mustermann@gmail.com
27+
28+
[PUSHSAFER]
29+
enabled = false
30+
Key =
31+
DeviceID =
32+
33+
[IFTTT]
34+
enabled = false
35+
Event =
36+
Key =

‎src/models/config.py

+49-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,55 @@
11
from os import environ
2+
import configparser
23

34

45
class Config():
5-
def __init__(self):
6+
def __init__(self, file=None):
7+
self.item_ids = []
8+
self.sleep_time = 20
9+
self.debug = False
10+
self.tgtg = {}
11+
self.pushSafer = {}
12+
self.smtp = {}
13+
self.ifttt = {}
14+
self.webhook = {}
15+
if file:
16+
self._ini_reader(file)
17+
else:
18+
self._env_reader()
19+
20+
def _ini_reader(self, file):
21+
config = configparser.ConfigParser()
22+
config.read(file)
23+
self.debug = config["MAIN"]["Debug"].lower() in ('true', '1', 't')
24+
self.item_ids = config["MAIN"]["ItemIDs"].split(
25+
',') if "ItemIDs" in config["MAIN"] else []
26+
self.sleep_time = int(config["MAIN"]["SleepTime"])
27+
self.tgtg = {
28+
"username": config["TGTG"]["Username"],
29+
"password": config["TGTG"]["Password"]
30+
}
31+
self.pushSafer = {
32+
"enabled": config["PUSHSAFER"]["enabled"].lower() in ('true', '1', 't'),
33+
"key": config["PUSHSAFER"]["Key"],
34+
"deviceId": config["PUSHSAFER"]["DeviceID"]
35+
}
36+
self.smtp = {
37+
"enabled": config["SMTP"]["enabled"].lower() in ('true', '1', 't'),
38+
"host": config["SMTP"]["Host"],
39+
"port": config["SMTP"]["Port"],
40+
"tls": config["SMTP"]["TLS"].lower() in ('true', '1', 't'),
41+
"username": config["SMTP"]["Username"],
42+
"password": config["SMTP"]["Password"],
43+
"sender": config["SMTP"]["Sender"],
44+
"recipient": config["SMTP"]["Recipient"]
45+
}
46+
self.ifttt = {
47+
"enabled": config["IFTTT"]["enabled"].lower() in ('true', '1', 't'),
48+
"event": config["IFTTT"]["Event"],
49+
"key": config["IFTTT"]["Key"]
50+
}
51+
52+
def _env_reader(self):
653
self.item_ids = environ.get("ITEM_IDS").split(
754
",") if environ.get("ITEM_IDS") else []
855
self.sleep_time = int(environ.get("SLEEP_TIME", 20))
@@ -33,7 +80,7 @@ def __init__(self):
3380
"key": environ.get("IFTTT_KEY")
3481
}
3582

36-
## ToDo: create notifier for any WebHook
83+
# ToDo: create notifier for any WebHook
3784
self.webhook = {
3885
"enabled": False
3986
}

‎src/scanner.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from dotenv import load_dotenv
21
from tgtg import TgtgClient
32
from time import sleep
43
import sys
@@ -8,13 +7,13 @@
87
from notifiers import Notifier
98
from models import Item, Config
109

11-
basedir = path.abspath(path.dirname(__file__))
12-
load_dotenv(path.join(basedir, '.env'))
13-
1410

1511
class Scanner():
1612
def __init__(self):
17-
self.config = Config()
13+
config_file = path.join(path.dirname(sys.executable), 'config.ini') if getattr(
14+
sys, '_MEIPASS', False) else path.join(path.dirname(path.abspath(__file__)), 'config.ini')
15+
print(config_file)
16+
self.config = Config() if not path.isfile(config_file) else Config(config_file)
1817
log.basicConfig(level=log.DEBUG if self.config.debug else log.INFO)
1918
self.item_ids = self.config.item_ids
2019
self.amounts = {}

0 commit comments

Comments
 (0)
Please sign in to comment.