flaschengeist/geruecht/model.py

45 lines
1.2 KiB
Python

from geruecht import db
from threading import Timer
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
def storner(self, value):
self.sum = self.sum - value
def __repr__(self):
return f"User('{self.username}', '{self.sum}')"
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}')
'''