Example #1
0
def hypothesis(update, context):
    if (not isBotAuthorized(update.effective_chat.id)):
        context.bot.send_message(
            chat_id=update.effective_chat.id,
            text=bot_messages['UNAUTHORIZED_MESSAGE'].format(
                update.effective_chat.id))
    else:
        if (isManageHypothesis()):
            path = getAnnotationPath(context.args[0])
            #print(path)
            pageAlias = getWebPageTitle(context.args[0])

            updateJournal(getHypothesisAnnotations(context.args[0]), False,
                          path, True, pageAlias)

            if (isHypothesisEmbedded()):
                updateJournal(entry='{{embed [[' + getPageTitle(path) + ']]}}')
            else:
                updateJournal(entry="Annotations of [" + pageAlias + "](" +
                              getPageTitle(path) + ")")
        else:
            updateJournal(getHypothesisAnnotations(context.args[0]), False)

        context.bot.send_message(
            chat_id=update.effective_chat.id,
            text=bot_messages['HYPOTHESIS_MESSAGE'].format(context.args[0]))
Example #2
0
def updateJournal(entry,
                  needsBuilding=True,
                  path=getJournalPath(),
                  overwrite=False,
                  alias='',
                  ignoreURL=False):
    if needsBuilding:
        entry = buildJournalEntry(entry, ignoreURL)
    if (GitFileExists(path)):
        file = repo.get_contents(path,
                                 ref=GitHubBranch)  # Get file from Branch
        if (overwrite):
            #print(getPageTitle(path))
            data = "---\ntitle: " + getPageTitle(
                path) + "\nalias: " + alias + "\n---\n\n"
            #print(data)
        else:
            data = file.decoded_content.decode("utf-8")  # Get raw string data

        data += (entry).strip() + "\n"

        push(path,
             git_messages['COMMIT_MESSAGE'].format(BotName, getTimestamp()),
             data,
             GitHubBranch,
             update=True)
    else:
        data = "---\ntitle: " + getPageTitle(
            path) + "\nalias: " + alias + "\n---\n\n" + (entry).strip() + "\n"

        push(path,
             git_messages['COMMIT_MESSAGE'].format(BotName, getTimestamp()),
             data,
             GitHubBranch,
             update=False)
Example #3
0
File: git.py Project: pomdtr/Lupin
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)