-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnotion.py
68 lines (51 loc) · 2.05 KB
/
notion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from flask import Flask
import os
from notion_client import Client
import json
from datetime import datetime
notion = Client(auth=os.getenv('NOTION_API_KEY'))
app = Flask(__name__)
def query(database_id: str):
my_page = notion.databases.query(
**{
"database_id": database_id,
}
)
# Create a new page
'''
your_name = "Hello"
new_page = {
"Name": {"title": [{"text": {"content": your_name}}]},
"Tags": {"type": "multi_select", "multi_select": [{"name": "API"}]},
}
notion.pages.create(parent={"database_id": database_id}, properties=new_page)
'''
return my_page
def add_trx_rows(database_id: str, trx_data:dict):
rows = trx_data['result']['rows']
for row in rows:
new_page = {
"Wallet Address": {"title": [{"text": {"content": row["tx_from"]}, "plain_text":row["tx_from"]}]},
"Number of Transactions": {"number": row["total_count"]},
"Total USD Transacted": {"number": row["total_usd_volume"]},
"Average Value Transacted": {"number": row["avg_trade_volume"]},
}
notion.pages.create(parent={"database_id": database_id}, properties=new_page)
def create_db(parent_id: str):
"""
parent_id(str): ID of the parent page
"""
db_name = "Top 10 Whale Transactions last 4 hours at "+ datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
print(f"\n\nCreate database '{db_name}' in page {parent_id}...")
properties = {
"Wallet Address": {"title": {}}, # This is a required property
"Number of Transactions": {"number": {"format": "number"}},
"Total USD Transacted": {"number": {"format": "dollar"}},
"Average Value Transacted": {"number":{"format": "dollar"}},
}
title = [{"type": "text", "text": {"content": db_name}}]
icon = {"type": "emoji", "emoji": "🎉"}
parent = {"type": "page_id", "page_id": parent_id}
return notion.databases.create(
parent=parent, title=title, properties=properties, icon=icon
)