├── .flake8 ├── .gitignore ├── LICENSE ├── Procfile ├── README.md ├── app.json ├── requirements.txt ├── runtime.txt ├── src ├── api.py ├── keep_awake.py └── utils.py ├── step1.png ├── step2.png ├── step3.png ├── step4.png ├── step5.png └── step6.png /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 160 3 | max-complexity = 10 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Kevin Jalbert 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn --preload --chdir ./src api:app 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This repository is ⚰️ ARCHIVED ⚰️ 2 | 3 | `notion-heroku` as an individual project has been sunsetted and merged into [`notion-toolbox`](https://github.com/kevinjalbert/notion-toolbox). In `notion-toolbox` is where this project lives on. The merge happened on December 27, 2019. 4 | 5 | --- 6 | 7 | > Heroku hosted application that performs [Notion](https://www.notion.so/) actions (i.e., new task, new note) based on voice requests via [IFTTT Webhooks](https://ifttt.com/maker_webhooks) and [Google Assistant](https://ifttt.com/google_assistant). 8 | 9 | ## Prerequisites 10 | 11 | 1. Have a [Notion](https://www.notion.so/) account 12 | 2. Have a [Heroku](https://heroku.com/) account 13 | 3. Have an [IFTTT](https://ifttt.com/) account (with Google Assistant service enabled) 14 | 4. Have [Specific Notion Template](https://www.notion.so/Week-Template-0a7ac4d03082417c929176b5ea1df07e) as described in [this blog post](https://kevinjalbert.com/my-weekly-notion-setup/) 15 | 5. Your Notion Token 16 | 6. URLs for Several Notion Object 17 | 18 | ## Install 19 | 20 | _Note:_ The required environment variables mentioned in the below steps are outlined in [kevinjalbert/alfred-notion](https://github.com/kevinjalbert/alfred-notion)'s section on [finding your Notion Token](https://github.com/kevinjalbert/alfred-notion#finding-your-notion-token) and [finding your Notion URLs](https://github.com/kevinjalbert/alfred-notion#finding-your-notion-urls). 21 | 22 | _Additional Note:_ You will want to set the `TZ` environment variable for your Heroku application to match your current timezone (i.e., `America/Toronto`). This will ensure that the correct day is used when creating a note or task. 23 | 24 | ### With Heroku Deploy Button 25 | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) 26 | 27 | 1. Use above deploy button to create/launch application on [Heroku](https://heroku.com/) 28 | 2. Navigate to application settings page (i.e., https://dashboard.heroku.com/apps/your-notion-heroku/settings) and set required environment variables. 29 | 30 | ### Manually 31 | 32 | 1. Clone the repository via `git clone git@github.com:kevinjalbert/notion-heroku.git` 33 | 2. `heroku create` 34 | 3. `git push heroku master` 35 | 4. Set all required environment variables via `heroku config:set xxxx=yyyy` 36 | 37 | ### Setting up IFTTT Actions 38 | 39 |
Click to view walkthrough (images) 40 | 41 |
42 | 43 | This walkthrough demonstrates how to setup a IFTTT action to add a Notion Task. 44 | 45 | The main difference is that the webhook URL is either `/add_note` or `/add_task` in Step 6. 46 | 47 | #### Step 1 - Choose _Trigger_ Service (Google Assistant) 48 | 49 | ![Step 1](./step1.png) 50 | 51 | #### Step 2 - Choose Google Assistant Trigger 52 | 53 | ![Step 2](./step2.png) 54 | 55 | #### Step 3 - Complete Google Assistant Trigger Fields 56 | 57 | ![Step 3](./step3.png) 58 | 59 | #### Step 4 - Choose _Action_ Service (Webhooks) 60 | 61 | ![Step 4](./step4.png) 62 | 63 | #### Step 5 - Choose Webhooks Action 64 | 65 | ![Step 5](./step5.png) 66 | 67 | #### Step 6 - Complete Webhook Action Fields 68 | 69 | ![Step 6](./step6.png) 70 | 71 |
72 | 73 | ## Author 74 | 75 | 👤 **Kevin Jalbert** 76 | 77 | * Twitter: [@kevinjalbert](https://twitter.com/kevinjalbert) 78 | * Github: [@kevinjalbert](https://github.com/kevinjalbert) 79 | 80 | ## Show your support 81 | 82 | Give a ⭐️ if this project helped you! 83 | 84 | *** 85 | _This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_ 86 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "notion-heroku", 3 | "description": "Heroku hosted application that performs Notion actions (i.e., new task, new note) based on voice requests via IFTTT Webhooks and Google Assistant.", 4 | "repository": "https://github.com/kevinjalbert/notion-heroku", 5 | "keywords": ["notion", "google assistant", "ifttt"] 6 | } 7 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | cachetools==3.1.0 2 | notion==0.0.21 3 | flake8==3.7.7 4 | Flask==1.0.3 5 | gunicorn==19.9.0 6 | Flask-APScheduler==1.11.0 7 | requests==2.22.0 8 | git+git://github.com/kevinjalbert/notion-scripts@v0.2.1#egg=notion-scripts 9 | -------------------------------------------------------------------------------- /runtime.txt: -------------------------------------------------------------------------------- 1 | python-3.7.3 2 | -------------------------------------------------------------------------------- /src/api.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S PATH="${PATH}:/usr/local/bin" python3 2 | 3 | import os 4 | from functools import wraps 5 | 6 | from notionscripts.notion_api import NotionApi 7 | from utils import app_url 8 | 9 | from flask import Flask, request, jsonify 10 | from flask_apscheduler import APScheduler 11 | app = Flask(__name__) 12 | 13 | 14 | class JobConfig(object): 15 | JOBS = [ 16 | { 17 | 'id': 'add_task_transitions', 18 | 'func': 'api:transition_tasks', 19 | 'args': (), 20 | 'trigger': 'interval', 21 | 'seconds': 60 22 | }, 23 | { 24 | 'id': 'ping', 25 | 'func': 'keep_awake:ping', 26 | 'args': (), 27 | 'trigger': 'interval', 28 | 'seconds': 600 29 | } 30 | ] 31 | 32 | SCHEDULER_API_ENABLED = True 33 | 34 | 35 | def transition_tasks(): 36 | NotionApi().transition_tasks() 37 | 38 | 39 | def token_required(f): 40 | @wraps(f) 41 | def decorated_function(*args, **kwargs): 42 | if request.headers.get('api_token') == os.getenv('API_TOKEN'): 43 | return f(*args, **kwargs) 44 | elif request.json.get('api_token') == os.getenv('API_TOKEN'): 45 | return f(*args, **kwargs) 46 | elif request.args.get('api_token') == os.getenv('API_TOKEN'): 47 | return f(*args, **kwargs) 48 | else: 49 | return 'Request api_token does not match known value', 401 50 | return decorated_function 51 | 52 | 53 | @app.route('/add_note', methods=['POST']) 54 | @token_required 55 | def add_note(): 56 | try: 57 | notion_api = NotionApi() 58 | 59 | notion_api.append_to_current_day_notes(request.json['title']) 60 | 61 | return 'Succeceed in adding note', 200 62 | except Exception: 63 | return 'Failed in adding note', 500 64 | 65 | 66 | @app.route('/add_task', methods=['POST']) 67 | @token_required 68 | def add_task(): 69 | try: 70 | notion_api = NotionApi() 71 | 72 | collection = notion_api.tasks_database().collection 73 | row = collection.add_row() 74 | row.name = request.json['title'] 75 | row.status = 'Next Up' 76 | row.tags = [notion_api.config.imported_tag_url()] 77 | 78 | return 'Succeceed in adding task', 200 79 | except Exception: 80 | return 'Failed in adding task', 500 81 | 82 | 83 | @app.route('/current_tasks.json', methods=['GET']) 84 | @token_required 85 | def get_current_tasks(): 86 | try: 87 | notion_api = NotionApi() 88 | 89 | current_tasks = [] 90 | for task in notion_api.get_current_tasks(): 91 | current_tasks.append({'id': task.id, 'title': task.title}) 92 | 93 | return jsonify( 94 | tasks=current_tasks 95 | ) 96 | except Exception: 97 | return 'Failed fetching current tasks', 500 98 | 99 | 100 | @app.route('/current_links.json', methods=['GET']) 101 | @token_required 102 | def get_links(): 103 | try: 104 | notion_api = NotionApi() 105 | 106 | current_day = notion_api.current_day() 107 | current_week = notion_api.current_week() 108 | 109 | return jsonify( 110 | current_day=app_url(current_day.get_browseable_url()), 111 | current_week=app_url(current_week.get_browseable_url()), 112 | ) 113 | except Exception: 114 | return 'Failed fetching current links', 500 115 | 116 | 117 | app.config.from_object(JobConfig()) 118 | 119 | scheduler = APScheduler() 120 | scheduler.init_app(app) 121 | scheduler.start() 122 | -------------------------------------------------------------------------------- /src/keep_awake.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S PATH="${PATH}:/usr/local/bin" python3 2 | 3 | import requests 4 | 5 | 6 | def ping(): 7 | requests.get('https://notion-heroku.herokuapp.com/') 8 | -------------------------------------------------------------------------------- /src/utils.py: -------------------------------------------------------------------------------- 1 | def app_url(browser_url): 2 | return browser_url.replace("https://", "notion://") 3 | -------------------------------------------------------------------------------- /step1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinjalbert/notion-heroku/7a991d520d340ac7055905ebd6e67c3d9532c97d/step1.png -------------------------------------------------------------------------------- /step2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinjalbert/notion-heroku/7a991d520d340ac7055905ebd6e67c3d9532c97d/step2.png -------------------------------------------------------------------------------- /step3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinjalbert/notion-heroku/7a991d520d340ac7055905ebd6e67c3d9532c97d/step3.png -------------------------------------------------------------------------------- /step4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinjalbert/notion-heroku/7a991d520d340ac7055905ebd6e67c3d9532c97d/step4.png -------------------------------------------------------------------------------- /step5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinjalbert/notion-heroku/7a991d520d340ac7055905ebd6e67c3d9532c97d/step5.png -------------------------------------------------------------------------------- /step6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinjalbert/notion-heroku/7a991d520d340ac7055905ebd6e67c3d9532c97d/step6.png --------------------------------------------------------------------------------