Guest User

Untitled

a guest
Nov 27th, 2021
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. def to_sbor(user_id):
  2. with closing(pymysql.connect(host=host, user=user, password=password, db=db, cursorclass=cc)) as con:
  3. with con.cursor() as c:
  4. c.execute(f'SELECT can_get_dt FROM invests WHERE user_id={user_id}')
  5. for row in c:
  6. end = row['can_get_dt']
  7. now = datetime.now()
  8. to_end = end - now
  9. try:
  10. to_end = datetime.strptime(str(to_end), '%H:%M:%S.%f')
  11. except ValueError:
  12. try:
  13. to_end = datetime.strptime(str(to_end), '%H:%M:%S')
  14. except ValueError:
  15. to_end = datetime.strptime(str(to_end), '-%d day, %H:%M:%S.%f')
  16. now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  17. now = datetime.strptime(now, '%Y-%m-%d %H:%M:%S')
  18. can_get = now + timedelta(hours=int(to_end.strftime('%H')))
  19. can_get = can_get.strftime('%Y-%m-%d %H:%M:%S')
  20. with closing(pymysql.connect(host=host, user=user, password=password, db=db, cursorclass=cc)) as con:
  21. with con.cursor() as c:
  22. c.execute(f"UPDATE invests SET can_get_dt='{can_get}' WHERE user_id={user_id}")
  23. c.execute(f'SELECT sum, sbor_sum FROM invests WHERE user_id={user_id}')
  24. con.commit()
  25. for row in c:
  26. summ = int(row['sum'])
  27. sbor_sum = int(row['sbor_sum'])
  28. sbor_sum += round((summ / 100) * cfg.percent, 2)
  29. with closing(pymysql.connect(host=host, user=user, password=password, db=db, cursorclass=cc)) as con:
  30. with con.cursor() as c:
  31. c.execute(f'UPDATE invests SET sbor_sum={sbor_sum} WHERE user_id={user_id}')
  32. con.commit()
  33. return to_end.strftime('%H:%M:%S')
  34.  
Advertisement
Add Comment
Please, Sign In to add comment