-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
71 lines (55 loc) · 1.94 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
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import random
import time
from flask import Flask, request, send_file, after_this_request, redirect
import functions as f
app = Flask(__name__)
# circle-token from query-params
@app.route('/')
def hello():
return 'hello!'
@app.route('/api/v2/insights/<vcs>/<org>/<project>/workflows')
def workflows(vcs, org, project):
circle_token = request.args.get('circle-token')
df = f.insights_workflows(project_slug=f'{vcs}/{org}/{project}', circle_token=circle_token)
seconds = time.time()
rand_int = random.getrandbits(128)
f_name = f'insights_workflows_{seconds}_{rand_int}.csv'
df.to_csv(f_name, index=False)
@after_this_request
def remove_file(response):
os.remove(f_name)
return response
try:
return send_file(f_name,
attachment_filename='insights_workflows.csv',
mimetype='text/csv',
as_attachment=True,
cache_timeout=-1)
except Exception as e:
return str(e)
@app.route('/api/v2/insights/<vcs>/<org>/<project>/workflows/<workflow_name>/jobs/<job_name>')
def jobs(vcs, org, project, workflow_name, job_name):
circle_token = request.args.get('circle-token')
df = f.insights_jobs(
project_slug=f'{vcs}/{org}/{project}',
circle_token=circle_token,
workflow_name=workflow_name,
job_name=job_name
)
seconds = time.time()
rand_int = random.getrandbits(128)
f_name = f'insights_workflows_{seconds}_{rand_int}.csv'
df.to_csv(f_name, index=False)
@after_this_request
def remove_file(response):
os.remove(f_name)
return response
try:
return send_file(f_name,
attachment_filename='insights_jobs.csv',
mimetype='text/csv',
as_attachment=True,
cache_timeout=-1)
except Exception as e:
return str(e)