This is a sample code to fetch (query) the database and get the page information contained in it by quering the API of Notion. It also includes sample code to write the retrieved page information to Pixe.la and Slack.
It is intended to be used to record the frequency of page creation in Notion in Pixe.la. It is designed to be run in the AWS Lambda environment, but it can also be run on your own machine (Mac).
To use the Notion API, prepare the Notion access token, the target database ID, and the user ID if you want to filter pages by user ID, and set them in lines 6, 7, and 8 of the source code.
If you want to export to Pixe.la, prepare the URL of the target graph and access token of Pixe.la, and set them in lines 10 and 11 of the source code.
If you want to export to Slack, prepare the Slack webhook URL and target channel, and set them in lines 13 and 14.
If you want to use it with AWS Lambda, comment out or uncomment the lambda_handler function from line 85. In the version on git, Notion is accessed and the result is printed, so comment it out and enable line 90 or 91 instead.
If you want to use it on the command line, edit the lines from line 98 as you see fit.
In Notion Database query, you can set filter and sort conditions. In this code, we filter by user ID and update date (updated today), and sort in reverse order (from lines 29 to 54).
The results obtained are set to the return value of notion_fetch(), but pixela_pixelpost_today() and send_message() only use the number of items respectively. The return value of notion_fetch() is a dict type that contains various kinds of property information (e.g., page title), so it can be extracted and used.