Пример #1
0
def add_session():
    body = request.get_json()
    print(body)
    session = Session(**body)
    session.delta = get_delta(session.start_money, session.end_money)
    session.save()
    id = session.id
    return {'id': str(id)}, 200
Пример #2
0
    def get(self):
        try:
            user_id = get_jwt_identity()
            user = User.objects.get(id=user_id)
            chats = Chat.objects(type='private', users__contains=user)

            all_sessions = [convert_session(session) for session in Session.objects(host=user)]
            for chat in chats:
                sessions = Session.objects(chats__contains=chat)
                for session in sessions:
                    all_sessions.append(convert_session_chat(session, chat))

            return Response(JSONEncoder().encode(all_sessions), mimetype="application/json", status=200)
        except DoesNotExist:
            raise DocumentMissing
        except Exception as e:
            raise InternalServerError
Пример #3
0
    def post(self):
        try:
            user_id = get_jwt_identity()
            body = request.get_json()
            slot_id = body.pop('slot_id')
            host_id = body.pop('host_id')
            chat_id = body.pop('chat_id')
            product_id = body.pop('product_id')

            session = Session(**body, chats=[chat_id], slot=slot_id, host=host_id, product=product_id)
            session.save()

            return {'id': str(session.id)}, 200
        except DoesNotExist:
            raise DocumentMissing
        except ValidationError:
            raise SchemaValidationError
        except Exception as e:
            raise InternalServerError
Пример #4
0
    def _walk_files(self):
        """
        Gather all the files (path+name) recursively based on a given path 

        Returns
        -------
        list
            Path+file_names found
        """
        session=Session()
        try:
            paths = glob.glob(self.path + "/**/*", recursive=True)
            self.logger.warning("Walking incoming path: %s" % self.path)
            if hasattr(self, "file_pattern"):
                paths_based_on_file_pattern = []
                for t in self.file_pattern:
                    self.logger.warning("Walking above path with file_pattern: %s" % t)
                    paths_based_on_file_pattern.extend(glob.glob(self.path + "/**/" + t, recursive=True))
                not_using = list(set(paths) - set(paths_based_on_file_pattern))
                if  not self.dry:
                    # program_unit =Column(String(128)) 
                    # error_code =Column(String(5))  
                    # error_timestamp  =Column(DateTime, default=datetime.datetime.utcnow)
                    # user_name =Column(String(32))  
                    # sql_statement =Column(String(2000)) 
                    for fn in not_using:
                        new_record = ErrorLog(program_unit=f'switchboard: {self.project}',error_code='?????',user_name='GOCD',
                        error_message=f'{os.path.basename(fn)}: No matching REGEX in yaml')
                        session.add(new_record)
                    
                        self.logger.warning("Will not process this file %s" % (os.path.basename(fn)))
                    session.commit()
                paths = paths_based_on_file_pattern
            paths = [p for p in paths if os.path.basename(p) != "."]
            return paths
        except Exception as e:
            self.logger.error("Something went wrong when walking the directory \n {0}".format(e))
            raise ExitProjectException("Something went wrong when walking the directory")
Пример #5
0
def get_sessions():
    all_sessions = Session.objects().to_json()
    return Response(all_sessions, mimetype="application/json", status=200)
Пример #6
0
from switchboard import yaml_reader
from projectio.projectio import ProjectIO
from lorem.text import TextLorem
import shutil
import py_dbutils.rdbms.postgres as dbconn
import random
from database.models import FileRouterHistory, Session, DecBase, DecBase_logging, engine
from switchboard import parse_cli, runner
from utils.utils import traverse_replace_yaml_tree, recurse_replace_yaml

import datetime

from datetime import date, timedelta
MOCKSIZE = 10
# Do this whenever you need a connection to the DB. (typically once at the top of your script)
sess = Session()
now = datetime.datetime.now()

runtime_dict = {
    "today": now.strftime("%Y-%m-%d"),
    "yesterday": (date.today() - timedelta(days=1)).strftime("%Y-%m-%d"),
    "thisyear": now.strftime("%Y"),
    "thismonth": now.strftime("%Y-%m")
}

FILE_TYPES = ['zip', 'txt', 'csv', 'db', 'xls']
SESS = Session()
DecBase.metadata.create_all(engine)
DecBase_logging.metadata.create_all(engine)
yaml_config = yaml_reader('/workspace/scripts/switchboard.yaml')
Пример #7
0
import logging
from config_parent import Config
from switchboard import yaml_reader
from projectio.projectio import ProjectIO
from lorem.text import TextLorem
import shutil
import py_dbutils.rdbms.postgres as dbconn
import random
from database.models import FileRouterHistory, Session, DecBase, engine

__author__ = "Hung Nguyen"
__copyright__ = "Hung Nguyen"
__license__ = "mit"

FILE_TYPES = ['zip', 'txt', 'csv', 'db', 'xls']
SESS = Session()
DecBase.metadata.create_all(engine)
yaml_config = yaml_reader('/workspace/scripts/switchboard.yaml')


def clean_working_dir(folder: str):
    import os, shutil

    for the_file in os.listdir(folder):
        file_path = os.path.join(folder, the_file)
        try:
            if os.path.isfile(file_path):
                os.unlink(file_path)
            #elif os.path.isdir(file_path): shutil.rmtree(file_path)
        except Exception as e:
            print(e)
Пример #8
0
import logging
import datetime
import re
import pprint
from datetime import date, timedelta
from sqlalchemy import Column, Integer, Text
from sqlalchemy.orm import mapper, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from projectio.projectio import ProjectIO
from database.models import FileRouterHistory, Session
from utils.utils import traverse_replace_yaml_tree, recurse_replace_yaml, get_logic_function_names
from utils.logger import Logger
from version import version_dict

# Do this whenever you need a connection to the DB. (typically once at the top of your script)
sess = Session()
now = datetime.datetime.now()

runtime_dict = {
    "today": now.strftime("%Y-%m-%d"),
    "yesterday": (date.today() - timedelta(days=1)).strftime("%Y-%m-%d"),
    "thisyear": now.strftime("%Y"),
    "thismonth": now.strftime("%Y-%m")
}


def yaml_reader(yaml_path=None):
    """
   Reads the yaml file from the path specified into the program.

   Parameters