~thrrgilag/partybot

0fc4482bdf570fdf17ed2383d40f22e80523e8dd — Morgan McMillian 1 year, 8 months ago b77e105
containerize this thing
5 files changed, 61 insertions(+), 9 deletions(-)

A .dockerignore
A Dockerfile
M models.py
M partybot-pnut.py
A requirements.txt
A .dockerignore => .dockerignore +11 -0
@@ 0,0 1,11 @@
__pycache__/
*.py[cod]
*.yaml
*.db
*.sublime-project
*.sublime-workspace
.vscode/
.git/
.gitignore
Dockerfile
.dockerignore
\ No newline at end of file

A Dockerfile => Dockerfile +14 -0
@@ 0,0 1,14 @@
FROM python:alpine3.7

VOLUME /data

WORKDIR /usr/src/app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

WORKDIR /data

CMD [ "python", "/usr/src/app/partybot-pnut.py", "-d", "-c", "config.yaml" ]

M models.py => models.py +3 -1
@@ 1,5 1,7 @@
from sqlalchemy import Column, ForeignKey, Integer, String, Boolean
from database import Base
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class Optout(Base):
    __tablename__ = 'optout'

M partybot-pnut.py => partybot-pnut.py +28 -8
@@ 8,10 8,13 @@ import time
import json
import random
import re
import argparse

from database import db_session, init_db
from sqlalchemy import and_
from models import Karma, Optout, Queue, Preferences, MdnpRequests
# from database import db_session, init_db
from sqlalchemy import create_engine, and_
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from models import Base, Karma, Optout, Queue, Preferences, MdnpRequests

_startup = threading.Event()
_shutdown = threading.Event()


@@ 348,12 351,29 @@ def on_open(ws):
if __name__ == "__main__":

    logger = logging.getLogger()
    logging.basicConfig(level=logging.DEBUG)
    a_parser = argparse.ArgumentParser()
    a_parser.add_argument(
        '-d', action='store_true', dest='debug',
        help="debug logging"
    )
    a_parser.add_argument(
        '-c', '--config', default="config.yaml",
        help="configuration file"
    )
    args = a_parser.parse_args()

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.INFO)

    with open("config.yaml", "rb") as config_file:
        config = yaml.load(config_file)
    
    init_db()
    with open(args.config, 'rb') as config_file:
        config = yaml.load(config_file, Loader=yaml.SafeLoader)

    engine = create_engine(config['SERVICE_DB'])
    db_session = scoped_session(sessionmaker(bind=engine))
    Base.query = db_session.query_property()
    Base.metadata.create_all(bind=engine)

    pnutpy.api.add_authorization_token(config['ACCESS_TOKEN'])


A requirements.txt => requirements.txt +5 -0
@@ 0,0 1,5 @@
PyYAML
pnutpy
requests
SQLAlchemy
websocket-client
\ No newline at end of file