-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblogversion.py
54 lines (52 loc) · 3.1 KB
/
blogversion.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
from atlassian import Confluence
from dateutil.relativedelta import relativedelta
from datetime import datetime
personal_access_token_prod = "prod server token goes here"
production_server = "https://prod server url goes here"
confluence = Confluence(url = production_server, token = personal_access_token_prod, timeout = 1800)
space_counter = 0
current_day = datetime.strftime(datetime.today(), '%Y_%m_%d')
logger = open(current_day +'_blog_post_version_purge_result.txt', 'w', encoding='UTF-8')
three_months = datetime.strptime(datetime.strftime(datetime.today() + relativedelta(months = -3), '%Y-%m-%d'), '%Y-%m-%d')
logger.writelines("Start Time: " + str(datetime.now()) + "\n")
mod = 0
while True:
for space in confluence.get_all_spaces(start=space_counter, limit=500, expand=None)["results"]:
mod = mod + 1
print("Checking space: " + space["key"])
blog_post_counter = 0
while True:
if len(confluence.get_all_pages_from_space(space["key"], start=blog_post_counter, limit=1, status=None, expand=None, content_type='blogpost')) == 1:
for blog_post in confluence.get_all_pages_from_space(space["key"], start=blog_post_counter, limit=100, status=None, expand=None, content_type='blogpost'):
print("Checking blog post: " + blog_post["title"])
if confluence.history(blog_post["id"])["lastUpdated"]["number"] > 1:
print("Attempting to remove blog post history", end = "", flush = True)
while True:
try:
version_one = confluence.get_content_history_by_version_number(blog_post["id"], 1)["when"]
except:
print("\nPossible issue in versioning. Space: {} | Blog Post: {}".format(space["key"],blog_post["title"]))
logger.write("Possible issue in versioning. Space: {} | Blog Post: {}\n".format(space["key"],blog_post["title"]))
break
version_date = datetime.strptime(str(version_one).split("T")[0], '%Y-%m-%d')
if version_date <= three_months:
if confluence.history(blog_post["id"])["lastUpdated"]["number"] > 1:
confluence.remove_content_history(blog_post["id"], 1)
print(".", end = "", flush = True)
else:
print("Done!")
break
else:
print("\nIt's not been more than 3 months since the current remaining versions have been edited.")
break
blog_post_counter = blog_post_counter + 1
if not blog_post_counter % 100 == 0:
break
else:
break
if not mod % 500 == 0:
break
else:
space_counter = space_counter + 500
logger.writelines("End Time: " + str(datetime.now()) + "\n")
exit()