-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
70 lines (57 loc) · 1.74 KB
/
app.py
File metadata and controls
70 lines (57 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from flask import Flask, request, jsonify
import requests
import pandas as pd
import json
import os
app = Flask(__name__)
# URL of the API endpoint
api_url = 'https://example.com/api/endpoint'
@app.route('/')
def index():
return '''
<!doctype html>
<title>Upload JSON File</title>
<h1>Upload JSON File</h1>
<form action="/upload" method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=submit value=Upload>
</form>
'''
@app.route('/upload', methods=['POST'])
def upload_file():
if 'file' not in request.files:
return "No file part"
file = request.files['file']
if file.filename == '':
return "No selected file"
if file:
# Save the uploaded file
file_path = os.path.join('uploads', file.filename)
file.save(file_path)
# Process the JSON file
with open(file_path, 'r') as f:
data = json.load(f)
# Extract static data
static_data = {
'id': data['id'],
'channel': data['channel']
}
responses = []
# Extract dynamic data and make API requests
dynamic_data = {
'dynamicData1': data['dynamicData1'],
'dynamicData2': data['dynamicData2']
}
# Combine static and dynamic data
request_data = {**static_data, **dynamic_data}
# Make the API request
response = requests.post(api_url, json=request_data)
responses.append({
'id': data['id'],
'status_code': response.status_code,
'response_text': response.text
})
return jsonify(responses)
if __name__ == '__main__':
os.makedirs('uploads', exist_ok=True)
app.run(debug=True)