コード例 #1
0
ファイル: app.py プロジェクト: tensei/Flask-orlrequests
def admin():
    global globalmsg
    global Twitchuser
    if Twitchuser in settings.Admins:
        if request.method == 'POST':
            # print('h', request.form['message'], request.form['channel'])
            if request.form.get('message', None):
                globalmsg = request.form.get('message', None)
                print('globalmsg change to', globalmsg)
                return render_template('admin.html',
                                       channels=channels, username=Twitchuser)
            if request.form.get('deletemsg', None):
                globalmsg = False
                print('globalmsg change to', globalmsg)
                return render_template('admin.html',
                                       channels=channels,
                                       username=Twitchuser)
            elif request.form.get('delete', None):
                channelname = request.form.get('delete', None).lower()
                denies[channelname] = channels.pop(channelname, None)
                loadfiles.save_denies(denies)
                loadfiles.save_requests(channels)
                print('deleted', channelname)
                return render_template('admin.html',
                                       channels=channels,
                                       data='success',
                                       msg='Deleted ' + channelname,
                                       username=Twitchuser)
            elif request.form.get('accept', None):
                channelname = request.form.get('accept', None).lower()
                channels.pop(channelname, None)
                logging_channels[channelname] = channel_info.checkchannel(channelname)
                loadfiles.save_logging(logging_channels)
                loadfiles.save_requests(channels)
                print('deleted', channelname)
                return render_template('admin.html',
                                       channels=channels,
                                       data='success',
                                       msg='Deleted ' + channelname,
                                       username=Twitchuser)
        return render_template('admin.html',
                               channels=channels,
                               username=Twitchuser)
    else:
        return redirect(url_for('index'))
コード例 #2
0
ファイル: app.py プロジェクト: tensei/Flask-orlrequests
def req():
    global Twitchuser, admin
    if not Twitchuser:
        return render_template('index.html',
                               data='fail',
                               msg='Please login first',
                               request=False,
                               channels=channels,
                               globalmsg=globalmsg,
                               reqtab=reqtab,
                               username=Twitchuser)

    if request.method == 'POST':
        # params = {'secret': settings.reCaptcha_secret,
        #           'response': request.form.get('g-recaptcha-response', None),
        #           'remoteip': request.remote_addr}
        # response_captcha = post('https://www.google.com/recaptcha/api/siteverify', data=params)
        # print(response_captcha.text)
        # js_response = json.loads(response_captcha.text)
        # if not js_response['success']:
        #     error = 'reCAPTCHA Error ' + js_response['error-codes']
        #     return render_template('index.html',
        #                            data='fail',
        #                            msg=error,
        #                            request=True,
        #                            channels=channels,
        #                            admin=admin,
        #                            globalmsg=globalmsg,
        #                            reqtab=reqtab,
        #                            username=Twitchuser)
        time_now = datetime.utcnow().strftime('%b %d %Y %H:%M:%S UTC')
        ip = request.remote_addr
        channelname = request.form.get('channel', None).lower()
        if Twitchuser not in ips.keys():
            ips[Twitchuser] = {}
            ips[Twitchuser]['ips'] = ip
            ips[Twitchuser]['channels'] = []
            loadfiles.save_ips(ips)
        if channelname not in ips[Twitchuser]['channels']:
            channelname = request.form.get('channel', None).lower()
            if request.form.get('channel', None):
                status = checkchannel(channelname)
                if status != True:
                    return render_template('index.html',
                                           data='fail',
                                           msg=status,
                                           request=True,
                                           channels=channels,
                                           admin=admin,
                                           globalmsg=globalmsg,
                                           reqtab=reqtab,
                                           username=Twitchuser)
            for key in logging_channels.keys():
                if key.lower() == channelname:
                    return render_template('index.html',
                                           data='fail',
                                           msg="already logging!",
                                           request=True,
                                           channels=channels,
                                           admin=admin,
                                           globalmsg=globalmsg,
                                           reqtab=reqtab,
                                           username=Twitchuser)
            if channelname not in channels.keys() and channelname and channelname not in ips[Twitchuser]['channels']:
                channels[channelname] = {}
                channels[channelname]['requests'] = 0
            if channelname in channels.keys() and channelname not in ips[Twitchuser]['channels']:
                try:
                    ips[Twitchuser]['channels'].append(channelname)
                    channels[channelname]['requests'] += 1
                    channels[channelname]['link'] = js['url']
                    channels[channelname]['logo'] = js['logo']
                    channels[channelname]['views'] = js['views']
                    channels[channelname]['followers'] = js['followers']
                    channels[channelname]['date'] = time_now
                    loadfiles.save_requests(channels)
                    loadfiles.save_ips(ips)
                except Exception as e:
                    return render_template('index.html',
                                           data='fail',
                                           msg='Error ' + str(js),
                                           request=True,
                                           channels=channels,
                                           admin=admin,
                                           globalmsg=globalmsg,
                                           reqtab=reqtab,
                                           username=Twitchuser)
                print(channels)
            else:
                return render_template('index.html',
                                       request=True,
                                       channels=channels,
                                       admin=admin,
                                       globalmsg=globalmsg,
                                       reqtab=reqtab,
                                       username=Twitchuser)
            print('POST ', ips, channels)
        else:
            print('voted already')
            return render_template('index.html',
                                   data='fail',
                                   msg=settings.fail_message,
                                   request=True,
                                   channels=channels,
                                   admin=admin,
                                   globalmsg=globalmsg,
                                   reqtab=reqtab,
                                   username=Twitchuser)
        print('voted')
        return render_template('index.html',
                               data='success',
                               msg=settings.success_message,
                               request=False,
                               channels=channels,
                               admin=admin,
                               globalmsg=globalmsg,
                               reqtab=reqtab,
                               username=Twitchuser)
    else:
        print('GET /request')
        return render_template('index.html',
                               request=True,
                               channels=channels,
                               admin=admin,
                               globalmsg=globalmsg,
                               reqtab=reqtab,
                               username=Twitchuser)