app.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # vim:fenc=utf-8
  4. #
  5. # Copyright © 2024 StrayWarrior <i@straywarrior.com>
  6. from flask import Flask, request, render_template
  7. from flaskext.mysql import MySQL
  8. from datetime import datetime, timedelta
  9. app = Flask(__name__)
  10. app.config['MYSQL_DATABASE_HOST'] = 'rm-bp17q95335a99272b.mysql.rds.aliyuncs.com'
  11. app.config['MYSQL_DATABASE_USER'] = 'crawler'
  12. app.config['MYSQL_DATABASE_PASSWORD'] = 'crawler123456@'
  13. app.config['MYSQL_DATABASE_DB'] = 'growth'
  14. mysql = MySQL()
  15. mysql.init_app(app)
  16. @app.route('/', methods=['GET', 'POST'])
  17. def index():
  18. if request.method == 'POST':
  19. staff_id = request.form['staff_id']
  20. video_id = request.form['video_id']
  21. if video_id:
  22. query = """
  23. SELECT a.carrier_id, a.remark, b.miniprogram_video_id, b.send_time,
  24. DATEDIFF(NOW(), b.send_time) as days
  25. FROM we_com_staff a JOIN we_com_message_attachment b
  26. ON a.id = b.staff_id
  27. WHERE a.carrier_id = %s AND b.miniprogram_video_id = %s ORDER BY send_time DESC
  28. """
  29. cursor = mysql.get_db().cursor()
  30. cursor.execute(query, (staff_id, video_id))
  31. result = cursor.fetchall()
  32. cursor.close()
  33. else:
  34. query = """
  35. SELECT a.carrier_id, a.remark, b.miniprogram_video_id, b.send_time,
  36. DATEDIFF(NOW(), b.send_time) as days
  37. FROM we_com_staff a JOIN we_com_message_attachment b
  38. ON a.id = b.staff_id
  39. WHERE a.carrier_id = %s ORDER BY send_time DESC
  40. """
  41. cursor = mysql.get_db().cursor()
  42. cursor.execute(query, (staff_id,))
  43. result = cursor.fetchall()
  44. cursor.close()
  45. return render_template('index.html', results=result, form=request.form)
  46. return render_template('index.html')
  47. if __name__ == '__main__':
  48. app.run(debug=True)