2019-01-13 19:07:46 +00:00
|
|
|
from geruecht import db
|
2019-01-13 23:25:25 +00:00
|
|
|
from threading import Timer
|
2019-01-13 19:07:46 +00:00
|
|
|
|
|
|
|
class User(db.Model):
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
username = db.Column(db.String(20), unique=True, nullable=False)
|
|
|
|
sum = db.Column(db.Float, nullable=False, default=0.0)
|
|
|
|
|
|
|
|
def add(self, value):
|
|
|
|
self.sum += value
|
2019-01-13 23:25:25 +00:00
|
|
|
def storner(self, value):
|
|
|
|
self.sum = self.sum - value
|
2019-01-13 19:07:46 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return f"User('{self.username}', '{self.sum}')"
|
2019-01-13 23:25:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class History:
|
|
|
|
history = []
|
|
|
|
user = None
|
|
|
|
|
|
|
|
def __init__(self, history, user, value):
|
|
|
|
self.history=history
|
|
|
|
self.history.append(self)
|
|
|
|
self.user = user
|
|
|
|
self.value = value
|
|
|
|
self.timer = Timer(60, self.kill)
|
|
|
|
self.timer.start()
|
|
|
|
|
|
|
|
def exec(self):
|
|
|
|
self.timer.cancel()
|
|
|
|
User.query.filter_by(username=self.user.username).first().storner(self.value)
|
|
|
|
self.kill()
|
|
|
|
|
|
|
|
def kill(self):
|
|
|
|
print("{} deledet from history".format(self.user))
|
|
|
|
self.history.remove(self)
|
|
|
|
print(self.history)
|
|
|
|
'''
|
|
|
|
def __repr__(self):
|
|
|
|
print(f'self:{self}, history:{self.history}, user:{self.user}, value:{self.value}')
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
print(f'self:{self}, history:{self.history}, user:{self.user}, value:{self.value}')
|
|
|
|
'''
|