<commit_before>from flask import Flask, render_template

from uptimerobot.uptimerobot import UptimeRobot

app = Flask(__name__)
app.config.from_pyfile('settings.py')

page_name = app.config.get('PAGE_NAME', 'UptimeRobot')
robot = UptimeRobot(app.config['UPTIMEROBOT_API_KEY'])
status_down = ['8', '9']
status_paused = ['0', '1']


@app.route('/')
def hello():
    status, response = robot.getMonitors()
    if status:
        monitors = response['monitors']['monitor']
        monitors_formatted = []
        for monitor in monitors:
            status_raw = monitor['status']
            if status_raw in status_down:
                status = 'danger'
            elif status_raw in status_paused:
                status = 'warning'
            else:
                status = 'success'
            m = (
                monitor['id'],
                monitor['friendlyname'],
                int(float(monitor['alltimeuptimeratio'])),
                status
                )
            monitors_formatted.append(m)
        return render_template('index.html', monitors=monitors_formatted,
                               page_name=page_name)
    else:
        return 501

if __name__ == '__main__':
    app.run()<commit_msg>Use namedtuple for monitor-data<commit_after>from collections import namedtuple

from flask import Flask, render_template

from uptimerobot.uptimerobot import UptimeRobot

app = Flask(__name__)
app.config.from_pyfile('settings.py')

page_name = app.config.get('PAGE_NAME', 'UptimeRobot')
robot = UptimeRobot(app.config['UPTIMEROBOT_API_KEY'])
status_down = ['8', '9']
status_paused = ['0', '1']

Monitor = namedtuple('Monitor', ['id', 'name', 'uptime', 'status'])


@app.route('/')
def hello():
    status, response = robot.getMonitors()
    if status:
        monitors = response['monitors']['monitor']
        monitors_formatted = []
        for monitor in monitors:
            status_raw = monitor['status']
            if status_raw in status_down:
                status = 'danger'
            elif status_raw in status_paused:
                status = 'warning'
            else:
                status = 'success'
            monitors_formatted.append(Monitor(
                id=monitor['id'], name=monitor['friendlyname'],
                uptime=int(float(monitor['alltimeuptimeratio'])),
                status=status
            ))
        return render_template('index.html', monitors=monitors_formatted,
                               page_name=page_name)
    else:
        return 501

if __name__ == '__main__':
    app.run()
{'fraction_non_alphanumeric': 0.11652377240841777, 'fraction_numerical': 0.005455962587685113, 'mean_word_length': 2.329442282749676, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4051845', 'n_tokens_mistral': 777, 'n_tokens_neox': 739, 'n_words': 155}