vote_close.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. from .tool.func import *
  2. def vote_close(num = 1):
  3. num = str(num)
  4. with get_db_connect() as conn:
  5. curs = conn.cursor()
  6. if admin_check() != 1:
  7. return re_error('/ban')
  8. curs.execute(db_change('select type from vote where id = ? and user = ""'), [num])
  9. data_list = curs.fetchall()
  10. if not data_list:
  11. return redirect('/vote')
  12. if data_list[0][0] == 'close':
  13. type_set = 'open'
  14. elif data_list[0][0] == 'n_close':
  15. type_set = 'n_open'
  16. elif data_list[0][0] == 'open':
  17. type_set = 'close'
  18. else:
  19. type_set = 'n_close'
  20. curs.execute(db_change("update vote set type = ? where user = '' and id = ? and type = ?"), [type_set, num, data_list[0][0]])
  21. curs.execute(db_change('delete from vote where name = "end_date" and type = "option" and id = ?'), [num])
  22. conn.commit()
  23. if data_list[0][0] == 'close' or data_list[0][0] == 'n_close':
  24. return redirect('/vote')
  25. else:
  26. return redirect('/vote/list/close')