Beispiel #1
0
    def __init__(self, path, symbol, message_queue):
        self._message_queue = message_queue

        # Configure logger
        self._logger = logging.getLogger(f"{symbol}_MarketLogger")
        self._logger.setLevel(logging.ERROR)
        handler = logging.handlers.SysLogHandler(address='/dev/log')
        self._logger.addHandler(handler)

        self._plotProvider = PlotProvider()
        # Path structure:
        # path
        #  - genotick/
        #    - genotick.jar
        #  - <market_name>/
        #    - config.txt
        #    - data/
        #      - <market_symbol>.csv
        #    - robots/
        #      - robot files
        self._path = os.path.abspath(path)
        self._symbol = symbol
        self._db = DatabaseManager()
        self._genotick_path = fr"{self._path}/genotick/genotick.jar"
        self._data_path = fr"{self._path}/{self._symbol}/data/{self._symbol}.csv"
        self._reverse_data_path = fr"{self._path}/{self._symbol}/data/reverse_{self._symbol}.csv"
        self._gen_config_path = fr"{self._path}/{self._symbol}/config.txt"
        self._robots_path = fr"{self._path}/robots"
    def unsubscribe(self, email, token):
        if email is None or email.isspace():
            return False

        email = email.strip()
        if not validate_email(email):
            print('유효하지 않은 이메일 주소', email)
            return False

        if token is None or token.isspace():
            return False

        if len(token) != 8:
            print('유효하지 않은 토큰', token)
            return False

        id = int32(int(token, 16))
        if id not in self.__subscriber_table:
            print('구독중이 아닌 이메일 주소', email)
            return False

        DatabaseManager().remove_subscriber_by_id(id)
        del self.__subscriber_table[id]

        return True
def main(argv):
    usage = "usage: {} market_symbol".format(argv[0])
    if len(argv) != 2:
        print(usage)
        sys.exit(1)
    db = DatabaseManager()
    pp = PlotProvider()
    image = pp.get_market_24plot(db.get_24h_plot_data(argv[1]), argv[1][1:])
 def _bot_job(self):
     try:
         db = DatabaseManager()
         bot = Bot(self._bot_token)
         chats = bot.get_chat_list()
         for c in chats:
             db.add_chat(c)
     except Exception:
         self._logger.exception("Failed to collect bot chats.")
 def _daily_market_plot_job(self):
     try:
         db = DatabaseManager()
         pp = PlotProvider()
         markets = db.get_markets()
         for m in markets:
             data = db.get_24h_plot_data(m)
             image = pp.get_market_24plot(data, m[1:])
             self._message_queue.put({'type': 'image', 'data': image})
     except Exception:
         self._logger.exception("Failed to push daily market plots.")
 def process_market_message(self):
     try:
         db = DatabaseManager()
         bot = Bot(self._bot_token)
         message = self._message_queue.get()
         chats = db.get_chat_list()
         if message["type"] == "text":
             bot.send_text_message(message["data"], chats)
         elif message["type"] == "image":
             bot.send_image(message["data"], chats)
         self._message_queue.task_done()
     except Exception:
         self._logger.exception(f"Failed to process market message.")
    def subscribe(self, email):
        if email is None or email.isspace():
            return False

        email = email.strip()
        if not validate_email(email):
            print('유효하지 않은 이메일 주소', email)
            return False

        subscriber = Subscriber(email)
        if subscriber.id in self.__subscriber_table:
            print('이미 등록된 이메일 주소', email)
            return False

        DatabaseManager().add_subscriber(subscriber)
        self.__subscriber_table[subscriber.id] = subscriber
        return True
 def _predictions_job(self):
     try:
         db = DatabaseManager()
         markets_list = db.get_markets()
         # Create thread for each market
         for m in markets_list:
             if m in self._markets and self._markets[m].is_alive():
                 self._logger.error(
                     f"Thread for market {m} is still alive.")
                 continue
             else:
                 t = threading.Thread(target=market_thread_func,
                                      args=(m, self._path,
                                            self._message_queue))
                 t.start()
                 self._markets[m] = t
     except Exception:
         self._logger.exception("Failed to start predictions job.")
 def __init__(self, path, bot_token):
     self._bot_token = bot_token
     self._logger = logging.getLogger('MarketManagerLogger')
     self._logger.setLevel(logging.ERROR)
     handler = logging.handlers.SysLogHandler(address='/dev/log')
     self._logger.addHandler(handler)
     self._db = DatabaseManager()
     self._path = path
     self._scheduler = BackgroundScheduler()
     self._scheduler.add_job(self._daily_market_plot_job,
                             trigger='cron',
                             hour='0')
     self._scheduler.add_job(self._predictions_job,
                             trigger='cron',
                             hour='*')
     self._scheduler.add_job(self._bot_job, trigger='cron', minute='*')
     self._markets = dict()
     self._message_queue = queue.Queue()
Beispiel #10
0
def main():
    """
    Downloads history from Mega-Sena website
    and loads data into a MySQL database
    """

    hd = HistoryDownloader('scraper-data')
    hd.download_html()
    hd.scrape_html()
    hd.check_consistency()
    hd.write_file('json')
    hd.write_file('csv')
    hd.create_db_csv_files()
    hd.log_info()

    dm = DatabaseManager(hd.draws_load_path, hd.winloc_load_path)
    dm.create_tables()
    dm.insert_data()
Beispiel #11
0
 def __init__(self):
     handlers = [(r"/", WelcomeHandler),
                 (r"/login", LoginHandler),
                 (r"/logout", LogoutHandler),
                 (r"/list", ListHandler),
                 (r"/new", NewItemHandler),
                 (r"/action/(\w+)/(\w+)", ActionHandler),
                ]
     settings = dict(
                 title="TODO LIST",
                 cookie_secret="SOME_RANDOM_VALUE",
                 template_path=os.path.join(os.path.dirname(__file__),
                                              "templates"),
                 static_path=os.path.join(os.path.dirname(__file__),
                                          "static"),
                 autoreload=True,
                 debug=True)
     super(Application, self).__init__(handlers, **settings)
     self.db = DatabaseManager()
Beispiel #12
0
from dbmanager import DatabaseManager
import pandas as pd
from timeseries import TimeSeries
from utils import Similarity
import inspect
import pika
import json


database_info = {
    "url": "localhost",
    "port": "27017",
    "database": "Sibyl"
}
label = "analyzer"
db_manager = DatabaseManager(database_info, label)

global pewma
global cl
global ts
cl = StaticControlLimits()
pewma_model = Pewma()
ts = TimeSeries()


def entry_point(ch, method, properties, body):
    topic = str(method).split('routing_key=')[-1].split("'")[0]
    print(topic)
    data = json.loads(body.decode("UTF-8"))
    print(data)
    data = transform_properties(data, topic)
Beispiel #13
0
"""
Very simple straightforward testing of CRUD operations on a single item.
"""
from bson.objectid import ObjectId
from dbmanager import DatabaseManager
from taskitem import TaskItem

db = DatabaseManager()
taskid = ObjectId()  # ID to use in test
testitem = TaskItem(_id=taskid,
                    user_id="123abc",
                    description="Test CRUD",
                    priority=1,
                    done=False)


def create():
    db.create(testitem)
    print("Item created")
    read()


def read():
    theitem = db.read_id(taskid)
    print(theitem.document())
    assert theitem.document() == testitem.document(), "Documents do not match"


def update():
    testitem.done = True
    print("Item updated")
 def __update_subscriber_table(self):
     subscribers = DatabaseManager().select_all_subscribers()
     if len(subscribers) > 0:
         self.__subscriber_table.clear()
         for subscriber in subscribers:
             self.__subscriber_table[subscriber.id] = subscriber