api_topic_sub.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from .tool.func import *
  2. def api_topic_sub_2(conn, name, sub, time):
  3. curs = conn.cursor()
  4. if flask.request.args.get('num', None):
  5. if flask.request.args.get('over', '0') == '0':
  6. curs.execute("select id, data, date, ip from topic where title = ? and sub = ? and id + 0 = ? + 0 order by id + 0 asc", [name, sub, flask.request.args.get('num', '')])
  7. elif flask.request.args.get('over', '0') == '1':
  8. curs.execute("select id, data, date, ip from topic where title = ? and sub = ? and id + 0 >= ? + 0 order by id + 0 asc", [name, sub, flask.request.args.get('num', '')])
  9. else:
  10. curs.execute("select id, data, date, ip from topic where title = ? and sub = ? and id + 0 <= ? + 0 order by id + 0 asc", [name, sub, flask.request.args.get('num', '')])
  11. elif flask.request.args.get('time', None):
  12. if flask.request.args.get('over', '0') == '0':
  13. curs.execute("select id, data, date, ip from topic where title = ? and sub = ? and date = ? order by id + 0 asc", [name, sub, flask.request.args.get('time', '')])
  14. if flask.request.args.get('over', '0') == '1':
  15. curs.execute("select id, data, date, ip from topic where title = ? and sub = ? and date >= ? order by id + 0 asc", [name, sub, flask.request.args.get('time', '')])
  16. else:
  17. curs.execute("select id, data, date, ip from topic where title = ? and sub = ? and date <= ? order by id + 0 asc", [name, sub, flask.request.args.get('time', '')])
  18. else:
  19. curs.execute("select id, data, date, ip from topic where title = ? and sub = ? order by id + 0 asc", [name, sub])
  20. data = curs.fetchall()
  21. if data:
  22. json_data = {}
  23. for i in data:
  24. json_data[i[0]] = {
  25. "data" : i[1],
  26. "date" : i[2],
  27. "id" : i[3]
  28. }
  29. return flask.jsonify(json_data)
  30. else:
  31. return flask.jsonify({})