Esempio n. 1
0
def ratings(name=""):
    name = str(name)
    mydb = db.db()
    q = utils.get_questions()
    me, all = mydb.getAllRatingsFor(name)
    mystats = utils.stats(me)
    allstats = utils.stats(all)
    ans = json.dumps({"questions": q, "me": mystats, "all": allstats})
    return ans
Esempio n. 2
0
 def billon_super_man(self, rail, source, url, open_type):
     screen_cut(cs_mac_rail_top)
     text_line = get_text_line()
     print(text_line)
     if not text_line:
         print("未发现题目")
         return
     questions = get_questions(text_line)
     questions = deal_questions(questions, source=source)
     get_answer(questions, url=url)
     open_webboswer(questions[0], open_type=open_type)
Esempio n. 3
0
 def top_meet(self, rail, source, url, open_type):
     screen_cut(rail)
     text_line = get_text_line()
     print(text_line)
     if not text_line:
         print("未发现题目")
         return
     questions = get_questions(text_line)
     questions = deal_questions(questions, source=source)
     get_answer(questions, url=url)
     open_webboswer(questions[0], open_type=open_type)
Esempio n. 4
0
def rate(name, idnum):
    # check to see if name is in the database
    u = userdb.auth_user(name, idnum)
    if u == None:
        flash("Invalid user")
        return redirect(url_for("login"))
    elif u == False:
        flash("Invalid password")
        return redirect(url_for("login"))

    # we've got a valid user, now get the people to rate (and their current
    # ratings)
    people_to_rate = utils.getPeopleToRate(name)
    q = utils.get_questions()
    me = userdb.get_user(str(name))
    return render_template("rate.html", u=me, r=people_to_rate, q=q)
Esempio n. 5
0
def save_rating_form(name, request):
    # first save all the stuff
    q = utils.get_questions()
    user = request.form.get("user", "")
    d = {}
    for k in request.form.keys():
        if k == "button" or k == "user":
            continue
        (rater, project, ratee, qnum) = k.split(":")
        dk = "%s:%s:%s" % (rater, project, ratee)
        d.setdefault(dk, [5 for x in range(len(q))])
        d[dk][int(qnum)] = request.form[k]
    mydb = db.db()
    for k in d:
        (rater, project, ratee) = k.split(":")
        mydb.saveRatings(project, rater, ratee, d[k])

    # then redirect
    return redirect(url_for("login"))
Esempio n. 6
0
if __name__ == '__main__':
    load_dotenv()
    TG_QUIZBOT_TOKEN = os.getenv('TG_QUIZBOT_TOKEN')
    TG_LOGGING_BOT_TOKEN = os.getenv('TG_LOGGING_BOT_TOKEN')
    CHAT_ID = os.getenv('TG_CHAT_ID')
    REDIS_HOST = os.getenv('REDIS_HOST')
    REDIS_PORT = os.getenv('REDIS_PORT')
    REDIS_PASSWORD = os.getenv('REDIS_PASSWORD')

    State = Enum('State', 'QUESTION SOLUTION')

    redis_db = redis.Redis(host=REDIS_HOST,
                           port=REDIS_PORT,
                           password=REDIS_PASSWORD)

    questions = get_questions()

    logging_bot = Bot(token=TG_LOGGING_BOT_TOKEN)
    logging.basicConfig(
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
        level=logging.INFO)
    logger.setLevel(logging.INFO)
    logger.addHandler(MyLogsHandler(logging_bot, CHAT_ID))
    logger.info('Бот tg-quiz запущен')

    updater = Updater(TG_QUIZBOT_TOKEN)
    dp = updater.dispatcher

    send_question = partial(handle_new_question_request, questions=questions)
    send_answer = partial(handle_give_up_attempt, questions=questions)
Esempio n. 7
0
# -*- coding:utf-8 -*-
from __future__ import unicode_literals

import json
import random

from flask import Blueprint, abort, flash, render_template, request

from utils import get_questions, get_result, get_types_desc

MBTI_BP = Blueprint('mbti', __name__)
QUESTIONS = get_questions()
TYPES_DESC = get_types_desc()


@MBTI_BP.route('/')
def welcome():
    '''欢迎页面,纯属装逼'''
    return render_template('mbti/welcome.html')


@MBTI_BP.route('/home/')
def home():
    '''尼玛逼这才是真正的首页啊'''
    return render_template('mbti/home.html')


@MBTI_BP.route('/about/')
def about():
    '''关于页面'''
    return render_template('mbti/about.html')
Esempio n. 8
0
    return MAP / total, MRR / total, P1 / total, P5 / total


if __name__ == "__main__":
    config = Config()
    config.get_config_from_user()
    config.log.info("=> Finish Loading Configuration")

    # word processing (w2i, i2w, i2v)
    w2i, i2v, vocab_size = utils.word_processing(config)
    config.args.vocab_size = vocab_size
    config.log.info("=> Finish Word Processing")

    # get questions (question dictionary: id -> python array pair (title, body))
    i2q = utils.get_questions(config, w2i)
    config.log.info("=> Finish Retrieving Questions")

    # create dataset
    train_data = utils.QRDataset(config,
                                 config.args.train_file,
                                 w2i,
                                 vocab_size,
                                 i2q,
                                 is_train=True)
    config.log.info("=> Building Dataset: Finish Train")
    dev_data = utils.QRDataset(config,
                               config.args.dev_file,
                               w2i,
                               vocab_size,
                               i2q,
Esempio n. 9
0
def get_questions(difficulty):
    return utils.get_questions(mongo.db, difficulty)