-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdateChart.py
More file actions
88 lines (73 loc) · 3.83 KB
/
updateChart.py
File metadata and controls
88 lines (73 loc) · 3.83 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import json
import random
import datetime
#https://pypi.org/project/atlassian-python-api/
#https://atlassian-python-api.readthedocs.io/
from atlassian import Confluence
####################################################################################
print ("Importing config")
input_file = open ('config.json')
c = json.load(input_file)
confluenceURL=c["confluence"]
confluenceUser=c["user"]
confluencePass=c["password"]
confluenceSpace=c["space"]
confluencePage=c["page"]
####################################################################################
print ("Connecting to Confluence : " + confluenceURL)
try:
confluence = Confluence(url=confluenceURL,username=confluenceUser,password=confluencePass)
except Exception as e:
print("Uh oh, can't connect to confluence at " + confluenceURL)
print(e)
####################################################################################
print ("Generating sample data")
records = []
today = datetime.datetime.today()
numdays = 30
for i in range (0, numdays):
d1=today - datetime.timedelta(days = i)
records.append({"date": d1.strftime("%Y.%m.%d"), "downloadspeed":random.randint(70,120)})
####################################################################################
print ("Making body")
chartHeading = "Download Speeds last " + str(numdays) + " days"
bodyPart_1 = ""
bodyPart_2 = ""
bodyPart_3 = ""
bodyPart_1 = bodyPart_1 + "<ac:structured-macro ac:name=\"chart\" ac:schema-version=\"1\" ac:macro-id=\"03427ec1-7dcf-4b60-a195-3c0b80e63ae7\">"
bodyPart_1 = bodyPart_1 + " <ac:parameter ac:name=\"timeSeries\">true</ac:parameter>"
bodyPart_1 = bodyPart_1 + " <ac:parameter ac:name=\"orientation\">vertical</ac:parameter>"
bodyPart_1 = bodyPart_1 + " <ac:parameter ac:name=\"dataDisplay\">after</ac:parameter>"
bodyPart_1 = bodyPart_1 + " <ac:parameter ac:name=\"showShapes\">false</ac:parameter>"
bodyPart_1 = bodyPart_1 + " <ac:parameter ac:name=\"dateFormat\">yyyy/MM/dd</ac:parameter>"
bodyPart_1 = bodyPart_1 + " <ac:parameter ac:name=\"timePeriod\">Second</ac:parameter>"
bodyPart_1 = bodyPart_1 + " <ac:parameter ac:name=\"width\">800</ac:parameter>"
bodyPart_1 = bodyPart_1 + " <ac:parameter ac:name=\"dataOrientation\">vertical</ac:parameter>"
bodyPart_1 = bodyPart_1 + " <ac:parameter ac:name=\"title\">" + chartHeading + "</ac:parameter>"
bodyPart_1 = bodyPart_1 + " <ac:parameter ac:name=\"type\">timeSeries</ac:parameter>"
bodyPart_1 = bodyPart_1 + " <ac:rich-text-body>"
bodyPart_1 = bodyPart_1 + " <table class=\"wrapped\">"
bodyPart_1 = bodyPart_1 + " <colgroup><col /><col /><col /></colgroup>"
bodyPart_1 = bodyPart_1 + " <tbody><tr><th>Date</th><th>" + chartHeading + "</th></tr>"
for r in records:
bodyPart_2 = bodyPart_2 + "\n <tr><td><div class=\"content-wrapper\"><p>" + str(r["date"]) + "</p></div></td><td>" + str(r["downloadspeed"]) + "</td></tr>"
bodyPart_3 = " </tbody></table></ac:rich-text-body></ac:structured-macro>"
newBody = bodyPart_1 + bodyPart_2 + bodyPart_3
print("########################################################################")
print("Looking for page \"" + confluencePage + "\" in space " + confluenceSpace)
pageID=confluence.get_page_id(confluenceSpace, confluencePage)
if pageID is None:
print("Page not found: " + confluencePage + " in space " + confluenceSpace)
exit()
else:
print ("Found page : " + confluencePage + " pageID: " + str(pageID) )
print("########################################################################")
print("Updating page: " + str(pageID))
try:
status=confluence.update_page(pageID, confluencePage, newBody, parent_id=None, type='page', representation='storage', minor_edit=False)
#print (status)
except Exception as e:
print("Uh oh, can't update pageID " + str(pageID))
print("Makesure page exists")
traceback.print_exc()
exit()