api_topic_sub.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from .tool.func import *
  2. def api_topic_sub(topic_num = 1, tool = 'normal', num = ''):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. topic_num = str(topic_num)
  6. if tool == 'normal':
  7. if num != '':
  8. curs.execute(db_change(
  9. "select id, data, date, ip, block, top from topic where code = ? and id + 0 = ? + 0 order by id + 0 asc"
  10. ), [
  11. topic_num,
  12. num
  13. ])
  14. else:
  15. curs.execute(db_change(
  16. "select id, data, date, ip, block, top from topic where code = ? order by id + 0 asc"
  17. ), [
  18. topic_num
  19. ])
  20. else:
  21. curs.execute(db_change(
  22. "select id, data, date, ip, block, top from topic where code = ? and top = 'O' order by id + 0 asc"
  23. ), [
  24. topic_num
  25. ])
  26. data = curs.fetchall()
  27. if data:
  28. data_a = {}
  29. admin = admin_check(3)
  30. curs.execute(db_change("select ip from topic where code = ? order by id + 0 asc limit 1"), [topic_num])
  31. data_f = curs.fetchall()
  32. data_f = data_f[0][0] if data_f else ''
  33. data_a['data_main'] = {
  34. "ip_first" : ip_pas(data_f, 1),
  35. "admin" : str(admin)
  36. }
  37. ip_a = ip_pas([i[3] for i in data])
  38. ip_a_2 = ip_pas([i[3] for i in data], 1)
  39. for i in data:
  40. data_v = i[1] if i[4] != 'O' or admin == 1 else ''
  41. data_a[i[0]] = {
  42. "data" : data_v,
  43. "date" : i[2],
  44. "ip" : ip_a_2[i[3]],
  45. "blind" : i[4],
  46. "ip_pas" : ip_a[i[3]],
  47. "data_pas" : render_set(
  48. doc_data = data_v,
  49. data_type = 'api_view',
  50. data_in = 'topic_' + topic_num + '_' + i[0],
  51. doc_acl = 0
  52. )
  53. }
  54. return flask.jsonify(data_a)
  55. else:
  56. return flask.jsonify({})