-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
59 lines (50 loc) · 1.55 KB
/
app.py
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
import requests
from flask import Flask, request, render_template
from flask_cors import CORS
app = Flask(__name__)
CORS(app, resources=r'/*')
@app.route('/subscription', methods=['GET','POST'])
def get_subscription():
queryUrl = 'https://api.openai.com/dashboard/billing/subscription'
# get Authorization
key = request.headers.get('Authorization')
print(key)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
'Authorization': key,
'Accept': '*/*',
'Host': 'api.openai.com',
'Connection': 'keep-alive'
}
print(headers)
r = requests.get(queryUrl, headers=headers)
return r.json()
@app.route('/usage', methods=['GET','POST'])
def get_usage():
queryUrl = 'https://api.openai.com/v1/dashboard/billing/usage'
# get Authorization
key = request.headers.get('Authorization')
end_date = request.args.get("end_date")
start_date = request.args.get("start_date")
print(key)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
'Authorization': key,
'Accept': '*/*',
'Host': 'api.openai.com',
'Connection': 'keep-alive'
}
print(headers)
data = {
"start_date": start_date,
"end_date": end_date
}
print(data)
r = requests.get(queryUrl, headers=headers, params=data)
return r.json()
@app.route('/')
def index():
return render_template("index.html")
if __name__ == '__main__':
# print("key:", get_usage())
app.run()