예제 #1
0
def main():
    token = notionToken()
    client = NotionClient(token_v2=token)
    taskId = client.post('enqueueTask', exportTask()).json().get('taskId')
    url = exportUrl(client, taskId)
    downloadFile(url, 'export.zip')

    service_account_info = json.loads(os.getenv('GDRIVE_SERVICE_ACCOUNT'))
    google_credentials = service_account.Credentials.from_service_account_info(
        service_account_info, scopes=['https://www.googleapis.com/auth/drive'])
    authed_session = AuthorizedSession(google_credentials)
    folderId = createFolder(authed_session)
    upload('export.zip', authed_session, folderId, 'application/zip')
예제 #2
0
def createNotionMeetingNote(token, collectionURL, data):
    # notion
    client = NotionClient(token)
    cv = client.get_collection_view(collectionURL)
    row = cv.collection.add_row()

    row.title = data.get('title')

    person_str = data.get('person')
    if person_str:
        people_cv = client.get_collection_view(
            'https://www.notion.so/brocoders/b4fee3350c234fa8a5a4a89677fb21c3?v=d6b07641b1f84e37863ad1ddde29d5f6'
        )
        filter_params = {
            "operator":
            "and",
            "filters": [{
                "property": "title",
                "filter": {
                    "operator": "string_is",
                    "value": {
                        "type": "exact",
                        "value": person_str
                    }
                }
            }]
        }
        result = people_cv.build_query(filter=filter_params).execute()

        row.person = client.get_block(result[0].id)

    str_date = data.get('date')  #6/25/2020 22:35:33
    if str_date:
        row.date = datetime.datetime.strptime(str_date, '%m/%d/%Y').date()
    row.mood = data.get('mood').split(", ")
    row.tags = data.get('tags').split(", ")
    row.type = data.get('type')

    interviewer_str = data.get('interviewer')
    if interviewer_str:
        subscriptionData = client.post(
            "getSubscriptionData", {
                "spaceId": "9f910372-8d4d-469e-a834-81199f575be7"
            }).json()

        req = {
            "recordVersionMap": {
                "notion_user":
                functools.reduce(lambda a, b: {
                    **a,
                    **{
                        b['userId']: -1
                    }
                }, subscriptionData['members'], {})
            }
        }
        users = client.post("syncRecordValues", req).json()

        for id, val in users['recordMap']['notion_user'].items():
            if val['value']['email'] == interviewer_str:
                row.interviewer = client.get_user(id)

    about_str = data.get('about')
    if about_str:
        row.children.add_new(SubsubheaderBlock, title="About")
        lines = io.StringIO(about_str)
        lines.name = '/'
        upload(lines, row)
        #row.children.add_new(TextBlock, title=about_str)

    summary_str = data.get('summary')
    if summary_str:
        row.children.add_new(SubsubheaderBlock, title="Summary")
        lines = io.StringIO(summary_str)
        lines.name = '/'
        upload(lines, row)
        #row.children.add_new(TextBlock, title=summary_str)

    action_points_str = data.get('action_points')
    if action_points_str:
        row.children.add_new(SubsubheaderBlock, title="Action points")
        lines = io.StringIO(action_points_str)
        lines.name = '/'
        upload(lines, row)