Skip to content

Commit

Permalink
Option to add disclaimer and date at the top of each imported page
Browse files Browse the repository at this point in the history
Added option to add disclaimer and original update date at the top of each imported card + minor cosmetic change.
  • Loading branch information
podlisk authored Feb 6, 2024
1 parent a39eece commit 34a169e
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions guruCollectionToConfluence.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import requests
import os
import mimetypes
import datetime

from bs4 import BeautifulSoup
from pathlib import Path
Expand All @@ -13,16 +14,24 @@
parser = argparse.ArgumentParser(description='Import Guru collections to Atlassian Confluence.')
parser.add_argument('--collection-dir', dest='collectiondir',
help='directory where the collection file is located (default: none)', required=True)
parser.add_argument('--user', dest='username', help='sum the integers (default: none)', required=True)
parser.add_argument('--api-key', dest='apikey', help='the api key (default: none)', required=False)
parser.add_argument('--user', dest='username', help='authorized user name (default: none)', required=True)
parser.add_argument('--api-key', dest='apikey', help='the api key for the authorized user (default: none)', required=False)
parser.add_argument('--space-key', dest='spacekey', help='the space key (default: none)', required=True)
parser.add_argument('--organization', dest='org', help='the atlassian organization (default: none)', required=True)
parser.add_argument('--parent', dest='parent', help='the parent page for the import (default: none)', required=True)
parser.add_argument('--date-disclaimer', dest='datedisclaimer', help='[yes|no] add disclaimer and original update '
'date on the the top of each card (default: '
'none)', required=False)

args = parser.parse_args()
print(args)
seed(1) # insecure

if args.datedisclaimer is None:
datedisclaimer = 'no'
else:
datedisclaimer = args.datedisclaimer.lower()


class ConfluencePage:
name_cache = {'root': 1}
Expand Down Expand Up @@ -254,6 +263,16 @@ def fill_card(confluence_node, card_id, cards_path):
except yaml.YAMLError as e:
print(e)

if datedisclaimer == 'yes':
externalLastUpdated = definition['externalLastUpdated']
lastUpdatedUTC = datetime.datetime.fromtimestamp(externalLastUpdated / 1000.0, datetime.timezone.utc)
lastUpdatedDateStr = lastUpdatedUTC.strftime('%Y-%m-%d')
lastUpdatedTimeStr = lastUpdatedUTC.strftime('%H:%M:%S %Z')
disclaimer = '<h6><span style="color: rgb(191,38,0);">Imported from Guru. ' \
'Original update on <time datetime="{}"/> at {}</span></h6>'.format(lastUpdatedDateStr,
lastUpdatedTimeStr)
content = disclaimer + content

confluence_node.update_title(definition['Title'])
confluence_node.set_content(content)

Expand Down

0 comments on commit 34a169e

Please sign in to comment.