Commit 5670b1d0 authored by flynn's avatar flynn

add persistence

parent 33334757
from functools import wraps
from flask import Flask, request
from flask import Flask, request, abort
app = Flask(__name__)
import config
import csv
from pprint import pprint
def requires_token(token_name):
'''Decorator to require a correct Mattermost token'''
def decorator(f):
......@@ -40,7 +43,7 @@ app_1 | 'user_name': 'hannes'}
def handle_change(amount: int):
caller = request.form['user_name']
if caller == "flynn" or caller == "hannes":
if caller in ("flynn", "hannes"):
if 'user_mentions' not in request.form:
return "Please mention someone."
......@@ -51,6 +54,12 @@ def handle_change(amount: int):
print(amount)
print("Received data")
with open('data.csv') as csvfile:
datawriter = csv.writer(csvfile)
for user in users:
datawriter.writerow([user, amount])
return "yes"
else:
return "NO >:("
......@@ -58,7 +67,7 @@ def handle_change(amount: int):
@app.route("/troll_add_point", methods=["POST"])
@requires_token('troll_add_point')
def add():
return handle_change(1)
return handle_change(1)
@requires_token('troll_remove_point')
@app.route("/troll_remove_point", methods=["POST"])
......@@ -69,4 +78,17 @@ def remove():
@app.route('/troll_list_points', methods=["GET"])
@requires_token('troll_list_points')
def list_points():
return "many"
scores = {}
with open('data.csv', 'r') as csvfile:
datareader = csv.reader(csvfile)
for row in datareader:
user = row[0]
score = int(row[1])
if user not in scores:
scores[user] = 0
scores[user] += score
return scores
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment