Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def to_sbor(user_id):
- with closing(pymysql.connect(host=host, user=user, password=password, db=db, cursorclass=cc)) as con:
- with con.cursor() as c:
- c.execute(f'SELECT can_get_dt FROM invests WHERE user_id={user_id}')
- for row in c:
- end = row['can_get_dt']
- now = datetime.now()
- to_end = end - now
- try:
- to_end = datetime.strptime(str(to_end), '%H:%M:%S.%f')
- except ValueError:
- try:
- to_end = datetime.strptime(str(to_end), '%H:%M:%S')
- except ValueError:
- to_end = datetime.strptime(str(to_end), '-%d day, %H:%M:%S.%f')
- now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
- now = datetime.strptime(now, '%Y-%m-%d %H:%M:%S')
- can_get = now + timedelta(hours=int(to_end.strftime('%H')))
- can_get = can_get.strftime('%Y-%m-%d %H:%M:%S')
- with closing(pymysql.connect(host=host, user=user, password=password, db=db, cursorclass=cc)) as con:
- with con.cursor() as c:
- c.execute(f"UPDATE invests SET can_get_dt='{can_get}' WHERE user_id={user_id}")
- c.execute(f'SELECT sum, sbor_sum FROM invests WHERE user_id={user_id}')
- con.commit()
- for row in c:
- summ = int(row['sum'])
- sbor_sum = int(row['sbor_sum'])
- sbor_sum += round((summ / 100) * cfg.percent, 2)
- with closing(pymysql.connect(host=host, user=user, password=password, db=db, cursorclass=cc)) as con:
- with con.cursor() as c:
- c.execute(f'UPDATE invests SET sbor_sum={sbor_sum} WHERE user_id={user_id}')
- con.commit()
- return to_end.strftime('%H:%M:%S')
Advertisement
Add Comment
Please, Sign In to add comment