示例#1
0
def run_bot(token):
    storage.init_db()
    """Start the bot."""
    # Create the Updater and pass it your bot's token.
    # Make sure to set use_context=True to use the new context based callbacks
    # Post version 12 this will no longer be necessary
    updater = Updater(token, use_context=True)

    # Get the dispatcher to register handlers
    dp = updater.dispatcher

    # on different commands - answer in Telegram
    dp.add_handler(CommandHandler('help', help_command))
    dp.add_handler(CommandHandler(['list', 'lst'], list_rates_command))
    dp.add_handler(CommandHandler('exchange', exchange_command))
    dp.add_handler(CommandHandler('history', history_command))

    # wrong input
    dp.add_handler(MessageHandler(Filters.text & ~Filters.command, no_command))

    # Start the Bot
    updater.start_polling()

    # Run the bot until you press Ctrl-C or the process receives SIGINT,
    # SIGTERM or SIGABRT. This should be used most of the time, since
    # start_polling() is non-blocking and will stop the bot gracefully.
    updater.idle()
示例#2
0
def test_init_and_remove(name, base_path):
    storage.init_db(base_path)
    if os.path.exists(base_path):
        result_one = PASSED
    else:
        result_one = FAILED
    storage.remove_db(base_path)
    if os.path.exists(base_path):
        result_two = FAILED
    else:
        result_two = PASSED
    print("Test {}: init {}; remove {}.".format(name, result_one, result_two))
示例#3
0
from storage.models.fighter import Fighter

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

if __name__ == "__main__":

    mysql_connection_string = "mysql+pymysql://{username}:{password}@{host}/{dbname}".format(
        username='******',
        password='******',
        host='localhost',
        dbname='ufcdb')

    memory_connection_string = 'sqlite:///:memory:'

    Session = init_db(mysql_connection_string, create=True)

    session = Session()

    all_fighters = session.query(Fighter).all()
    parse_queue = [f.ref for f in all_fighters]
    shuffle(parse_queue)

    if len(parse_queue) == 0:
        parse_queue = ["/fighter/Jon-Jones-27944"]

    parsed = set()

    while len(parse_queue) != 0:
        logger.info("queue: {}, parsed: {}".format(len(parse_queue),
                                                   len(parsed)))
示例#4
0
        print(fighter2.ref)

        fight = FightProxy(fighter1, fighter2, EventProxy(event_date))
        print(featurize(fight))

        print(predictor.predict(fight))


if __name__ == "__main__":
    mysql_connection_string = "mysql+pymysql://{username}:{password}@{host}/{dbname}".format(
            username='******',
            password='******',
            host='localhost',
            dbname='ufcdb')

    memory_connection_string = 'sqlite:///:memory:'

    Session = init_db(mysql_connection_string, create=True)

    session = Session()

    all_fights = session.query(Fight).all()
    fights = filter(validate_fight, all_fights)
    fighters = session.query(Fighter).all()

    predictor = MLPredictor(featurize)

    # print(cross_validate(predictor, fights))

    predict_event(predictor, fights, fighters)
示例#5
0
import json
import os
import ctypes
import storage
import image
from flask import Flask, render_template, send_from_directory
from PIL import ImageFile
from pprint import pprint

app = Flask(__name__, template_folder='app', static_folder='app/dist')
storage.init_db()


@app.route('/')
def index():
    images = storage.get_images()
    images_json = json.dumps([dict(image) for image in images])

    return render_template('app.html', images_json=images_json)


@app.route('/images')
def fetch():
    image.get_new_images()
    images = storage.get_images()
    images_json = json.dumps([dict(image) for image in images])
    return (images_json, 200)


@app.route('/images/<reddit_id>', methods=['POST'])
def set(reddit_id):
示例#6
0
from storage.models.fight import Fight
from storage.models.fighter import Fighter

from storage import Session, init_db
from storage.models.event import Event

if __name__ == "__main__":
    init_db()
    session = Session()

    tagir = Fighter(name='Tagir', ref='/fighter/tagir-1001')
    session.add(tagir)

    sergey = Fighter(name='Sergey', ref='/fighter/sergey-1002')
    session.add(sergey)

    ufc01 = Event(name='UFC 01', ref='/event/ufc-01')
    session.add(ufc01)

    f1 = Fight(fighter1=tagir, fighter2=sergey, event=ufc01, outcome='Tagir crushed him')
    session.add(f1)

    # e1 = session.query(Event).filter_by(name='UFC 01').first()
    # print(e1.fights[0].first_fighter.name)

    #t = session.query(Fighter).filter_by(name='Tagir').first()
    session.commit()

    t = session.query(Fight).first()

    tagir.name = "TTT"