- small clean up
This commit is contained in:
mcinj 2022-05-16 16:03:12 -04:00
parent b51712cb87
commit 6cb493eba7
7 changed files with 29 additions and 21 deletions

View file

@ -36,6 +36,8 @@ pushover.user_key =
[WEB] [WEB]
# should we enable the webserver which is just a simple, simple, simple webui to view the logs # should we enable the webserver which is just a simple, simple, simple webui to view the logs
web.enabled = false web.enabled = false
# the host to listen on. localhost or 0.0.0.0 are the two common options
web.host = localhost
# the port to run on # the port to run on
web.port = 9547 web.port = 9547
# the app root / web folder / root / many other names . MUST contain a trailing '/' # the app root / web folder / root / many other names . MUST contain a trailing '/'

View file

@ -27,7 +27,6 @@ def choose_user_agent():
class ConfigReader(ConfigParser): class ConfigReader(ConfigParser):
required_values = { required_values = {
'DEFAULT': { 'DEFAULT': {
'enabled': ('true', 'false'), 'enabled': ('true', 'false'),
@ -75,6 +74,7 @@ class ConfigReader(ConfigParser):
}, },
'WEB': { 'WEB': {
'web.enabled': 'false', 'web.enabled': 'false',
'web.host': '0.0.0.0',
'web.app_root': '/', 'web.app_root': '/',
'web.port': '9647', 'web.port': '9647',
'web.ssl': 'true', 'web.ssl': 'true',

View file

@ -1,8 +1,12 @@
import datetime
import threading import threading
from datetime import timedelta, datetime
from random import randint from random import randint
from threading import Thread from threading import Thread
from time import sleep from time import sleep
from dateutil import tz
import log import log
from enter_giveaways import EnterGiveaways from enter_giveaways import EnterGiveaways
@ -52,7 +56,9 @@ class GiveawayThread(threading.Thread):
logger.info("🔴 All giveaways evaluated.") logger.info("🔴 All giveaways evaluated.")
random_seconds = randint(1740, 3540) # sometime between 29-59 minutes random_seconds = randint(1740, 3540) # sometime between 29-59 minutes
logger.info(f"🛋 Going to sleep for {random_seconds / 60} minutes.") when_to_start_again = datetime.now(tz=tz.tzlocal()) + timedelta(seconds=random_seconds)
logger.info(f"🛋 Going to sleep for {random_seconds / 60} minutes. "
f"Will start again at {when_to_start_again}")
sleep(random_seconds) sleep(random_seconds)
def run(self): def run(self):

View file

@ -1,10 +1,8 @@
import http.client import http.client
import urllib import urllib
from sqlalchemy.orm import Session
from tables import TableNotification
import log import log
from tables import TableNotification
logger = log.get_logger(__name__) logger = log.get_logger(__name__)

View file

@ -41,7 +41,8 @@ class TableNotification(Base):
.filter_by(type='won').all() .filter_by(type='won').all()
actual = [] actual = []
for r in within_3_days: for r in within_3_days:
if r.created_at.replace(tzinfo=tz.tzutc()).astimezone(tz.tzlocal()).date() == datetime.now(tz=tz.tzlocal()).date(): if r.created_at.replace(tzinfo=tz.tzutc()).astimezone(tz.tzlocal()).date() == datetime.now(
tz=tz.tzlocal()).date():
actual.append(r) actual.append(r)
return actual return actual

View file

@ -15,6 +15,7 @@ class WebServerThread(threading.Thread):
Thread.__init__(self) Thread.__init__(self)
self.exc = None self.exc = None
self.config = config self.config = config
self.host = config['WEB'].get('web.host')
self.port = config['WEB'].getint('web.port') self.port = config['WEB'].getint('web.port')
self.ssl = config['WEB'].getboolean('web.ssl') self.ssl = config['WEB'].getboolean('web.ssl')
self.enabled = config['WEB'].getboolean('web.enabled') self.enabled = config['WEB'].getboolean('web.enabled')
@ -63,9 +64,9 @@ class WebServerThread(threading.Thread):
if self.enabled: if self.enabled:
logger.info("Webserver Enabled. Running") logger.info("Webserver Enabled. Running")
if self.ssl: if self.ssl:
app.run(port=self.port, host="0.0.0.0", ssl_context='adhoc') app.run(port=self.port, host=self.host, ssl_context='adhoc')
else: else:
app.run(port=self.port, host="0.0.0.0") app.run(port=self.port, host=self.host)
else: else:
logger.info("Webserver NOT Enabled.") logger.info("Webserver NOT Enabled.")