This project is a simple database server and API built with Python and Flask. It connects to a MySQL database, provides endpoints for updating and retrieving records, and serves data from a CSV file. It also includes integration with WeChat for token and openid retrieval.
- REST API using Flask
- MySQL database setup and access
- CSV to JSON conversion and MD5 hash checking
- WeChat API integration for token and openid
- Example client scripts for making requests
app.py: Main Flask application, API endpoints, CSV handling, and database logic.database.py: MySQL database setup and table creation.access.py: WeChat API token and openid retrieval functions.request.py: Example script to POST to/updateendpoint.request2.py: Example script to POST to root endpoint.info.csv: Data file served as JSON via API.
- Python 3.x
- Flask
- mysql-connector-python
- requests
- MySQL server
- Install dependencies:
pip install flask mysql-connector-python requests
- Ensure MySQL server is running and accessible with the credentials in
database.pyandapp.py. - Run the database setup (automatically called in
app.py). - Start the Flask server:
python app.py
POST /update: Update or get a record in the database. Requires JSON withid,activity, andtoken.POST /mapdata: Get CSV data as JSON if MD5 does not match. Requires JSON withmd5andtoken.POST /mini_id: Get WeChat openid. Requires JSON withusercodeandtoken.
See request.py and request2.py for example client requests.
MIT License (add details if needed)