add default args to work with snap pkg
This commit is contained in:
parent
8a7738ca02
commit
1249c8347a
2 changed files with 23 additions and 3 deletions
|
@ -9,6 +9,7 @@ import json
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import argparse
|
import argparse
|
||||||
|
import os
|
||||||
|
|
||||||
from sqlalchemy import create_engine, and_
|
from sqlalchemy import create_engine, and_
|
||||||
from sqlalchemy.orm import scoped_session, sessionmaker
|
from sqlalchemy.orm import scoped_session, sessionmaker
|
||||||
|
@ -20,6 +21,12 @@ _shutdown = threading.Event()
|
||||||
_connected = threading.Event()
|
_connected = threading.Event()
|
||||||
_error = threading.Event()
|
_error = threading.Event()
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
config = {}
|
||||||
|
db_session = None
|
||||||
|
|
||||||
|
SNAP_DATA = os.environ.get('SNAP_DATA')
|
||||||
|
|
||||||
def subscribe(connection_id):
|
def subscribe(connection_id):
|
||||||
url = f"https://api.pnut.io/v1/channels/{config['CHANNEL']}/messages"
|
url = f"https://api.pnut.io/v1/channels/{config['CHANNEL']}/messages"
|
||||||
url += "?connection_id=" + connection_id
|
url += "?connection_id=" + connection_id
|
||||||
|
@ -353,7 +360,8 @@ def on_open(ws):
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
logger = logging.getLogger()
|
global config
|
||||||
|
global db_session
|
||||||
a_parser = argparse.ArgumentParser()
|
a_parser = argparse.ArgumentParser()
|
||||||
a_parser.add_argument(
|
a_parser.add_argument(
|
||||||
'-d', action='store_true', dest='debug',
|
'-d', action='store_true', dest='debug',
|
||||||
|
@ -363,6 +371,10 @@ def main():
|
||||||
'-c', '--config', default="config.yaml",
|
'-c', '--config', default="config.yaml",
|
||||||
help="configuration file"
|
help="configuration file"
|
||||||
)
|
)
|
||||||
|
a_parser.add_argument(
|
||||||
|
'-s', '--store', default="store.db",
|
||||||
|
help="database store url"
|
||||||
|
)
|
||||||
args = a_parser.parse_args()
|
args = a_parser.parse_args()
|
||||||
|
|
||||||
if args.debug:
|
if args.debug:
|
||||||
|
@ -370,10 +382,17 @@ def main():
|
||||||
else:
|
else:
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
with open(args.config, 'rb') as config_file:
|
if SNAP_DATA is None:
|
||||||
|
filename = args.config
|
||||||
|
db_url = args.store
|
||||||
|
else:
|
||||||
|
filename = SNAP_DATA + '/config.yaml'
|
||||||
|
db_url = 'sqlite:///' + SNAP_DATA + '/store.db'
|
||||||
|
|
||||||
|
with open(filename, 'rb') as config_file:
|
||||||
config = yaml.load(config_file, Loader=yaml.SafeLoader)
|
config = yaml.load(config_file, Loader=yaml.SafeLoader)
|
||||||
|
|
||||||
engine = create_engine(config['SERVICE_DB'])
|
engine = create_engine(db_url)
|
||||||
db_session = scoped_session(sessionmaker(bind=engine))
|
db_session = scoped_session(sessionmaker(bind=engine))
|
||||||
Base.query = db_session.query_property()
|
Base.query = db_session.query_property()
|
||||||
Base.metadata.create_all(bind=engine)
|
Base.metadata.create_all(bind=engine)
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -2,6 +2,7 @@ from setuptools import setup
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='partybot',
|
name='partybot',
|
||||||
|
version='0.2.0',
|
||||||
py_modules=['partybot.models','partybot.pnutbot'],
|
py_modules=['partybot.models','partybot.pnutbot'],
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'PyYAML',
|
'PyYAML',
|
||||||
|
|
Loading…
Reference in a new issue