user_watch_list_name.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from .tool.func import *
  2. def user_watch_list_name(tool, name = 'Test'):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. ip = ip_check()
  6. if ip_or_user(ip) != 0:
  7. return redirect(conn, '/login')
  8. name_from = 0
  9. if tool == 'watch_list_from':
  10. name_from = 1
  11. tool = 'watch_list'
  12. elif tool == 'star_doc_from':
  13. name_from = 1
  14. tool = 'star_doc'
  15. if tool == 'watch_list':
  16. type_data = 'watchlist'
  17. else:
  18. type_data = 'star_doc'
  19. curs.execute(db_change("select data from user_set where name = ? and id = ? and data = ?"), [type_data, ip, name])
  20. if curs.fetchall():
  21. curs.execute(db_change("delete from user_set where name = ? and id = ? and data = ?"), [type_data, ip, name])
  22. else:
  23. if tool == 'watch_list':
  24. curs.execute(db_change("select count(*) from user_set where id = ? and name = ?"), [ip, type_data])
  25. count = curs.fetchall()
  26. if count and count[0][0] > 10:
  27. return re_error(conn, 28)
  28. curs.execute(db_change("insert into user_set (id, name, data) values (?, ?, ?)"), [ip, type_data, name])
  29. if name_from == 1:
  30. return redirect(conn, '/w/' + url_pas(name))
  31. else:
  32. if tool == 'watch_list':
  33. return redirect(conn, '/watch_list')
  34. else:
  35. return redirect(conn, '/star_doc')