Download data/test/dynogen_easy_045/server.py from bPtBvkTP/DynoGen-Benchmark: direct link, hf CLI and curl.
- Browser
- Download file 2.42 kB
-
https://huggingface.co/datasets/bPtBvkTP/DynoGen-Benchmark/resolve/main/data/test/dynogen_easy_045/server.py
- Command line
-
hf download hf://datasets/bPtBvkTP/DynoGen-Benchmark/data/test/dynogen_easy_045/server.py
-
curl -L -o server.py https://huggingface.co/datasets/bPtBvkTP/DynoGen-Benchmark/resolve/main/data/test/dynogen_easy_045/server.py
2.42 kB
| from flask import Flask, jsonify, request | |
| from flask_cors import CORS | |
| import random | |
| from datetime import datetime, timedelta | |
| app = Flask(__name__) | |
| CORS(app) | |
| # Mock data | |
| ACTIVITY_INFO = { | |
| "bannerUrl": "https://via.placeholder.com/750x400/ff5722/ffffff?text=新用户首单优惠", | |
| "title": "新用户首单立减", | |
| "endTime": (datetime.now() + timedelta(days=7)).isoformat() | |
| } | |
| COUPONS = [ | |
| { | |
| "id": "coupon_001", | |
| "value": 10, | |
| "expiryDate": "2024-12-31", | |
| "condition": "满50元可用" | |
| }, | |
| { | |
| "id": "coupon_002", | |
| "value": 20, | |
| "expiryDate": "2024-12-31", | |
| "condition": "满100元可用" | |
| }, | |
| { | |
| "id": "coupon_003", | |
| "value": 50, | |
| "expiryDate": "2024-12-31", | |
| "condition": "满200元可用" | |
| } | |
| ] | |
| def get_activity_info(): | |
| activity_id = request.args.get('activityId', '') | |
| return jsonify(ACTIVITY_INFO) | |
| def get_coupon_list(): | |
| return jsonify(COUPONS) | |
| def receive_coupon(): | |
| data = request.get_json() | |
| coupon_id = data.get('couponId', '') | |
| # Simulate success/failure randomly | |
| success = random.random() > 0.2 # 80% success rate | |
| if success: | |
| return jsonify({ | |
| "success": True, | |
| "message": f"优惠券 {coupon_id} 领取成功" | |
| }) | |
| else: | |
| return jsonify({ | |
| "success": False, | |
| "message": "优惠券库存不足" | |
| }) | |
| def track_event(): | |
| data = request.get_json() | |
| event_name = data.get('eventName', '') | |
| payload = data.get('payload', {}) | |
| # Log the event (in real app, this would go to analytics service) | |
| print(f"Event tracked: {event_name}, Payload: {payload}") | |
| return jsonify({ | |
| "success": True | |
| }) | |
| def health_check(): | |
| return jsonify({"status": "ok"}) | |
| if __name__ == '__main__': | |
| print("Starting server on http://localhost:5000") | |
| print("Available endpoints:") | |
| print(" GET /api/activity/info") | |
| print(" GET /api/coupon/list") | |
| print(" POST /api/coupon/receive") | |
| print(" POST /api/track/event") | |
| print(" GET /health") | |
| app.run(debug=True, host='0.0.0.0', port=5000) |