浏览代码

Add web/qywx

StrayWarrior 6 月之前
父节点
当前提交
75c782600b
共有 2 个文件被更改,包括 102 次插入0 次删除
  1. 56 0
      web/qywx/app.py
  2. 46 0
      web/qywx/templates/index.html

+ 56 - 0
web/qywx/app.py

@@ -0,0 +1,56 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+# vim:fenc=utf-8
+#
+# Copyright © 2024 StrayWarrior <i@straywarrior.com>
+
+from flask import Flask, request, render_template
+from flaskext.mysql import MySQL
+from datetime import datetime, timedelta
+
+app = Flask(__name__)
+
+app.config['MYSQL_DATABASE_HOST'] = 'rm-bp17q95335a99272b.mysql.rds.aliyuncs.com'
+app.config['MYSQL_DATABASE_USER'] = 'crawler'
+app.config['MYSQL_DATABASE_PASSWORD'] = 'crawler123456@'
+app.config['MYSQL_DATABASE_DB'] = 'growth'
+
+mysql = MySQL()
+mysql.init_app(app)
+
+@app.route('/', methods=['GET', 'POST'])
+def index():
+    if request.method == 'POST':
+        staff_id = request.form['staff_id']
+        video_id = request.form['video_id']
+
+        if video_id:
+            query = """
+	            SELECT a.carrier_id, a.remark, b.miniprogram_video_id, b.send_time,
+                       DATEDIFF(NOW(), b.send_time) as days
+                FROM we_com_staff a JOIN we_com_message_attachment b
+                ON a.id = b.staff_id
+                WHERE a.carrier_id = %s AND b.miniprogram_video_id = %s ORDER BY send_time DESC
+            """
+            cursor = mysql.get_db().cursor()
+            cursor.execute(query, (staff_id, video_id))
+            result = cursor.fetchall()
+            cursor.close()
+        else:
+            query = """
+	            SELECT a.carrier_id, a.remark, b.miniprogram_video_id, b.send_time,
+                       DATEDIFF(NOW(), b.send_time) as days
+                FROM we_com_staff a JOIN we_com_message_attachment b
+                ON a.id = b.staff_id
+                WHERE a.carrier_id = %s ORDER BY send_time DESC
+            """
+            cursor = mysql.get_db().cursor()
+            cursor.execute(query, (staff_id,))
+            result = cursor.fetchall()
+            cursor.close()
+
+        return render_template('index.html', results=result, form=request.form)
+    return render_template('index.html')
+
+if __name__ == '__main__':
+    app.run(debug=True)

+ 46 - 0
web/qywx/templates/index.html

@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8">
+    <title>查询记录</title>
+  </head>
+  <body>
+    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.3/css/bootstrap.min.css" rel="stylesheet">
+    <div class="container mt-5">
+      <form class="mb-3" method="post">
+        <div>
+          <label class="form-label" for="staff_id">Staff ID:</label>
+          <input class="form-control" type="text" id="staff_id"
+                                                  name="staff_id"
+                                                  required value="{{ form["staff_id"] }}">
+        </div>
+        <div>
+          <label class="form-label" for="video_id">Video ID:</label>
+          <input class="form-control" type="text" id="video_id"
+                                                  name="video_id"
+                                                  value="{{ form["video_id"] }}">
+          <br>
+        </div>
+        <button class="btn btn-primary" type="submit">查询</button>
+      </form>
+      <table class="table table-striped" border="1">
+        <tr>
+          <th>Staff ID</th>
+          <th>Remark</th>
+          <th>Video ID</th>
+          <th>Send Time</th>
+          <th>Days Ago</th>
+        </tr>
+        {% for row in results %}
+        <tr>
+          <td>{{ row[0] }}</td>
+          <td>{{ row[1] }}</td>
+          <td>{{ row[2] }}</td>
+          <td>{{ row[3] }}</td>
+          <td>{{ row[4] }}</td>
+        </tr>
+        {% endfor %}
+      </table>
+    </div>
+  </body>
+</html>