api_bbs_w_comment.py 984 B

1234567891011121314151617181920212223242526272829
  1. from .tool.func import *
  2. def api_bbs_w_comment(sub_code = ''):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. curs.execute(db_change('select set_name, set_data, set_code, set_id from bbs_data where (set_name = "comment" or set_name = "comment_date" or set_name = "comment_user_id") and set_id = ? order by set_code + 0 asc'), [sub_code])
  6. db_data = curs.fetchall()
  7. if not db_data:
  8. return flask.jsonify({})
  9. else:
  10. temp_id = ''
  11. temp_dict = {}
  12. temp_list = []
  13. for for_a in db_data:
  14. if temp_id != for_a[2]:
  15. if temp_dict != {}:
  16. temp_list += [dict(temp_dict)]
  17. temp_id = for_a[2]
  18. temp_dict['code'] = for_a[2]
  19. temp_dict[for_a[0]] = for_a[1]
  20. if temp_dict != {}:
  21. temp_list += [dict(temp_dict)]
  22. return flask.jsonify(temp_list)