コード例 #1
0
ファイル: app.py プロジェクト: tanyifans/WordRoot
def daily():
    username = session['username']
    user = User.objects(user=username).first()
    today = date.today()
    wordlearned = Count.objects(user=user.user, create_at=today).all()
    wordlist = []
    countwords = Count.objects(user=user.user).all()
    for word in countwords:
        if word.word not in wordlist:
            wordlist.append(word.word)
    length = len(wordlist)
    quests = {
        '0': "(daily)Sign in evertday--5 points",
        '1': "(daily)Learn 10 more words--5 points",
        '2': "(daily)Learn 20 more words--15 points",
        '3': "(daily)Learn 50 more words--30 poitns",
        "4": "(only once)Acomplish collections of 100 words -- 100 points",
        "5": "(only once)Acomplish collections of 500 words -- 500 points"
    }
    return (render_template("daily.html",
                            quests=quests,
                            username=user.user,
                            times=user.times,
                            wordlearned=len(wordlearned),
                            wordcollect=length))
コード例 #2
0
ファイル: app.py プロジェクト: tanyifans/WordRoot
def bonus():
    username = session['username']
    index = request.form['index']
    today = date.today()
    user = User.objects(user=username).first()
    tasks = Task.objects(index=index, user=username, create_at=today).all()
    oncetasks = Task.objects(index=index, user=username).all()
    words = Count.objects(user=user.user, create_at=today).all()

    wordlist = []
    countwords = Count.objects(user=user.user).all()
    for word in countwords:
        if word.word not in wordlist:
            wordlist.append(word.word)
    length = len(wordlist)

    if index == '0':
        if len(tasks) == 0:
            user.update(times=user.times + 5)
            Task(user=username, index=index).save()
            return jsonify({'status': '1'})
    elif index == '1':

        if len(words) >= 10 and len(tasks) == 0:
            user.update(times=user.times + 5)
            Task(user=username, index=index).save()
            return jsonify({'status': '1'})
    elif index == '2':

        if len(words) >= 20 and len(tasks) == 0:
            user.update(times=user.times + 15)
            Task(user=username, index=index).save()
            return jsonify({'status': '1'})

    elif index == '3':
        if len(words) >= 50 and len(tasks) == 0:
            user.update(times=user.times + 30)
            Task(user=username, index=index).save()
            return jsonify({'status': '1'})

    elif index == '4' and len(oncetasks) == 0:
        if length >= 100:
            Task(user=username, index=index).save()
            user.update(times=user.times + 100)
            return jsonify({'status': '1'})
    elif index == '5' and len(oncetasks) == 0:
        if length >= 500:
            Task(user=username, index=index).save()
            user.update(times=user.times + 100)
            return jsonify({'status': '1'})

    return jsonify({'status': '0'})
コード例 #3
0
ファイル: app.py プロジェクト: tanyifans/WordRoot
def mywordlist():
    if 'username' in session:
        username = session['username']
        user = User.objects(user=username).first()
        wordlist = []
        words = Count.objects(user=user.user).all()
        for word in words:
            if word.word not in wordlist:
                wordlist.append(word.word)
        wordlist.sort()
        return (render_template("mywordlist.html",
                                words=wordlist,
                                length=len(wordlist),
                                username=user.user,
                                times=user.times))
コード例 #4
0
ファイル: app.py プロジェクト: tanyifans/WordRoot
def index():

    if 'username' in session:
        wordindex = request.args.get('wordindex')
        username = session['username']
        user = User.objects(user=username).first()
        if user.times < 0:
            return (render_template("recharge.html",
                                    username=user.user,
                                    times=user.times))
        else:
            user.update(times=user.times - 1)
            questlists = pd.read_json(Result.objects().to_json())
            wordroot = pd.read_json(Roots.objects().to_json())['root']
            rlength = len(wordroot)
            length = len(questlists['word'])

            if wordindex == None:
                num1 = random.randint(0, length - 1)
            else:
                num1 = questlists[(
                    questlists.word == wordindex)].index.tolist()[0]
            question = questlists.take([num1])
            word = question['word'][num1]
            hints = question['hint'][num1]
            #roots
            roots = question['root'][num1].strip('[').strip(']')
            roots = roots.split(',')
            root2 = []
            for root in roots:
                root = root.strip(" ")
                root2.append(root.strip().strip("'").strip('"'))
            answers = "".join(root2)
            while len(root2) <= 5:
                num2 = random.randint(0, rlength - 1)
                temword = wordroot[num2]
                if temword not in root2:
                    root2.append(temword)
            root2.sort()
            Count(word=word, user=user.user).save()
            #wordcounts
            wordcounts = len(Count.objects(word=word).all())

            #hints
            th = hints.split(']')

            com = (th[0]).split(';')

            t1 = com[0].split('[')
            t2 = com[-1].split('→')
            wordg = ''
            for i in range(len(word)):
                wordg += '_ '
            component = [wordg, t1[1]]
            for c in com[1:-1]:
                component.append(c)
            for t in t2:
                component.append(t)

            hint = th[1].split('。')
            today = date.today()
            wordlearned = len(
                Count.objects(user=user.user, create_at=today).all())

            return (render_template("index.html",
                                    word=word,
                                    roots=root2,
                                    component=component,
                                    hints=hint,
                                    itemid=num1,
                                    answer=question['origin'][num1],
                                    wordcounts=wordcounts,
                                    answers=answers,
                                    username=user.user,
                                    times=user.times,
                                    wordlearned=wordlearned))

    else:
        return render_template('login.html')