This repository has been archived by the owner on May 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-credits.py
54 lines (45 loc) · 1.63 KB
/
deploy-credits.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
import json
import matplotlib.pyplot as plt
import pandas as pd
import requests
import datetime
import configparser
cfg = configparser.ConfigParser()
cfg.read('main.cfg')
CIRCLE_TOKEN = cfg['main']['CIRCLE_TOKEN']
VCS = cfg['main']['VCS']
ORG = cfg['main']['ORG']
REPO = cfg['main']['REPO']
VCS_SLUG = VCS + '/' + ORG + '/' + REPO
MAX_PAGES = 8
WORKFLOW = cfg['main']['DEPLOY_WORKFLOW']
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Circle-Token': CIRCLE_TOKEN
}
response = requests.get('https://circleci.com/api/v2/insights/' +
VCS_SLUG + '/workflows/' + WORKFLOW, headers=headers)
jsonData = response.json()
nextPageToken = str(jsonData['next_page_token'])
for page in range(MAX_PAGES):
if nextPageToken is not None:
response = requests.get('https://circleci.com/api/v2/insights/' + VCS_SLUG +
'/workflows/' + WORKFLOW + '?page-token=' + nextPageToken, headers=headers)
newJsonData = response.json()
jsonData['items'] = jsonData['items'] + newJsonData['items']
nextPageToken = newJsonData['next_page_token']
successfulDeploys = [item for item in jsonData['items']
if item['status'] == "success"]
for item in successfulDeploys:
startedDate = datetime.datetime.strptime(
item['created_at'], '%Y-%m-%dT%H:%M:%S.%fZ')
item['date'] = startedDate.strftime('%m/%d')
# dump json into file
# with open('data.json', 'w') as data_file:
# data = json.dump(jsonData, data_file)
df = pd.DataFrame(successfulDeploys)
print(df)
df.plot(x='date', y='credits_used')
plt.gca().invert_xaxis()
plt.show()