def scheduledHousekeeping(context): print("Scheduled Housekeeping ...") if isGraphAgeEncrypted(): generateAgeKeyFile() Git2Json() if isCalendarsAutogenerated(): updateCalendarsFile()
def updateCalendarsFile(): path = "pages/" + config.getcalendarFile() contents = getGitFileContent(path, True) contents = utils.generateCalendarsFile(contents) if (config.isGraphAgeEncrypted()): contents = AgeEncHandler.ageEncrypt(contents) push(path, git_messages['COMMIT_MESSAGE'].format(BotName, utils.getTimestamp()), contents, GitHubBranch, update=True)
def getGitFileContent(file, fetchContent=False): if (fetchContent): file = repo.get_contents(file, ref=GitHubBranch) # Get file from Branch try: content = file.decoded_content.decode("utf-8") # Get raw string data if (config.isGraphAgeEncrypted()): if AgeEncHandler.isAgeEncrypted( content ) == 1: # encrypted but without \n requires transformation return (AgeEncHandler.ageDecrypt( AgeEncHandler.convertToAgeString(content))) elif AgeEncHandler.isAgeEncrypted( content) == 2: # encrypted no transformation required return (AgeEncHandler.ageDecrypt(content)) else: # not encrypted return content else: return content except Exception as e: print(e) return None
def updateJournal(entry, needsBuilding=True, path=None, overwrite=False, alias='', ignoreURL=False, isJournalFile=True): if path == None: path = utils.getJournalPath() if needsBuilding: entry = buildJournalEntry(entry, ignoreURL) if (GitFileExists(path)): file = repo.get_contents(path, ref=GitHubBranch) # Get file from Branch if (overwrite): data = "---\ntitle: " + utils.getPageTitle( path) + "\nalias: " + alias + "\n---\n\n" else: data = file.decoded_content.decode("utf-8") # Get raw string data if (config.isGraphAgeEncrypted()): if AgeEncHandler.isAgeEncrypted( data ) == 1: # encrypted but without \n requires transformation data = (AgeEncHandler.ageDecrypt( AgeEncHandler.convertToAgeString(data))) elif AgeEncHandler.isAgeEncrypted( data) == 2: # encrypted no transformation required data = (AgeEncHandler.ageDecrypt(data)) data += (entry).strip() + "\n" if (config.isGraphAgeEncrypted()): data = AgeEncHandler.ageEncrypt(data) push(path, git_messages['COMMIT_MESSAGE'].format(BotName, utils.getTimestamp()), data, GitHubBranch, update=True) else: if isJournalFile: journalTemplate = config.journalTemplate if journalTemplate: data = "---\ntitle: " + utils.getJournalTitle( ) + "\n---\n\n" + journalTemplate + (entry).strip() + "\n" else: data = "---\ntitle: " + utils.getJournalTitle( ) + "\n---\n\n" + (entry).strip() + "\n" else: data = "---\ntitle: " + utils.getPageTitle( path) + "\nalias: " + alias + "\n---\n\n" + ( entry).strip() + "\n" if (config.isGraphAgeEncrypted()): data = AgeEncHandler.ageEncrypt(data) push(path, git_messages['COMMIT_MESSAGE'].format(BotName, utils.getTimestamp()), data, GitHubBranch, update=False)