Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
flynn
tractor
Commits
5670b1d0
Commit
5670b1d0
authored
Nov 15, 2020
by
flynn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add persistence
parent
33334757
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
4 deletions
+26
-4
app.py
app.py
+26
-4
No files found.
app.py
View file @
5670b1d0
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 >:("
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment