完成了基本的提醒功能。
This commit is contained in:
commit
0e1c6c1c1a
|
|
@ -0,0 +1,4 @@
|
|||
publish:
|
||||
#scp -v -P 22 main.py cubie@192.168.1.130:/home/cubie/down/document/python/task_automation
|
||||
scp -v -P 24123 -i C:\\Users\\3040/.ssh/163 main.py cubie@14.18.54.194:/home/cubie/down/document/python/task_automation
|
||||
#scp -v -P 24123 -i C:\\Users\\3040/.ssh/163 requirements.txt cubie@14.18.54.194:/home/cubie/down/document/python/task_automation
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
from notion.client import NotionClient
|
||||
client = NotionClient(token_v2=r"1bc7fdf20c9b3059eeb3897fd904b02e23c17682fb30103fe886211528551adbd5ae35e3892bf8fdc8528ec9318f9c89d7cc3f8eaabb43f37187580911e29f17b3c902f4c9b813ae4552c9fe1775")
|
||||
print('client init')
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
# from notion.block import CalloutBlock, BulletedListBlock, TextBlock
|
||||
# from auth import client
|
||||
from notion_client import AsyncClient
|
||||
from pprint import pprint
|
||||
import asyncio
|
||||
import platform
|
||||
from dateutil.parser import parse
|
||||
from dateutil.tz import gettz
|
||||
import datetime
|
||||
import requests
|
||||
import json
|
||||
from loguru import logger
|
||||
|
||||
# def update_callout():
|
||||
# page_callout_extract = client.get_block(
|
||||
# "https://www.notion.so/facat/76583e3369764976868d11bc761abc93"
|
||||
# )
|
||||
# page_callout_update = client.get_block(
|
||||
# "https://www.notion.so/facat/8f4f0ed22f9f4afb9b8faee15b33d8ed"
|
||||
# )
|
||||
# page_callout_extract.locked = True
|
||||
# page_callout_update.locked = True
|
||||
# print("The old title is:", page_callout_extract.title)
|
||||
# callout_list = []
|
||||
# for child in page_callout_extract.children:
|
||||
# if type(child) == CalloutBlock:
|
||||
# callout_list.append(child.title)
|
||||
# print(f"找到Callout{child.title}")
|
||||
# # 清除重点的内容
|
||||
# for child in page_callout_update.children:
|
||||
# child.remove()
|
||||
# # 更新重点的内容
|
||||
# for callout_list in callout_list:
|
||||
# page_callout_update.children.add_new(BulletedListBlock, title=callout_list)
|
||||
# page_callout_update.children.add_new(TextBlock, title="End!")
|
||||
# page_callout_extract.locked = False
|
||||
#
|
||||
#
|
||||
# async def sdk_callout():
|
||||
# async with AsyncClient(
|
||||
# auth="secret_WoGb0MDPDdwiEMQr8ZU6i50u7fT6WD6RzXkHu6RAF4R"
|
||||
# ) as notion:
|
||||
# page = await notion.pages.retrieve("8f4f0ed22f9f4afb9b8faee15b33d8ed")
|
||||
# children_info = await notion.blocks.children.list(page["id"])
|
||||
# children = children_info["results"]
|
||||
# for child in children:
|
||||
# # text=await notion.blocks.children.list(child['id'])
|
||||
# pprint(child)
|
||||
#
|
||||
#
|
||||
# async def extract_callout():
|
||||
# async with AsyncClient(
|
||||
# auth="secret_WoGb0MDPDdwiEMQr8ZU6i50u7fT6WD6RzXkHu6RAF4R"
|
||||
# ) as notion:
|
||||
# extract_page_block_info = await notion.blocks.children.list('76583e3369764976868d11bc761abc93')
|
||||
# extract_blocks = extract_page_block_info["results"]
|
||||
# for blocks in extract_blocks:
|
||||
# if blocks['type']=='synced_block':
|
||||
# callouts=await notion.blocks.children.list(blocks['id'])
|
||||
# pprint(callouts)
|
||||
|
||||
|
||||
def test_if_mention(block):
|
||||
if "paragraph" in block:
|
||||
paragraph = block["paragraph"]
|
||||
if "text" in paragraph:
|
||||
texts = paragraph["text"]
|
||||
for text in texts:
|
||||
if "mention" in text:
|
||||
return text["mention"]
|
||||
return None
|
||||
|
||||
|
||||
def send_msg(text):
|
||||
r = requests.post(
|
||||
"https://mmssgg.happymap.xyz/sendmessage",
|
||||
headers={"Content-Type": "application/json"},
|
||||
data=json.dumps({"message": text}),
|
||||
)
|
||||
|
||||
|
||||
async def check_un_do():
|
||||
notion = AsyncClient(auth="secret_WoGb0MDPDdwiEMQr8ZU6i50u7fT6WD6RzXkHu6RAF4R")
|
||||
todo_database_id = "31ba234684e54e57a10e7e155fe7767c"
|
||||
uncompleted_todos_query = await notion.databases.query(
|
||||
**{
|
||||
"database_id": todo_database_id,
|
||||
"filter": {"property": "状态", "select": {"equals": "未完成"}},
|
||||
}
|
||||
)
|
||||
uncompleted_todos = uncompleted_todos_query["results"]
|
||||
for uncompleted_todo in uncompleted_todos:
|
||||
# pprint(uncompleted_todo)
|
||||
task_name = uncompleted_todo["properties"]["Name"]["title"][0]["plain_text"]
|
||||
task_url = uncompleted_todo["url"]
|
||||
page_id = uncompleted_todo["id"]
|
||||
page_blocks_query = await notion.blocks.children.list(page_id)
|
||||
page_blocks = page_blocks_query["results"]
|
||||
for block in page_blocks:
|
||||
mention = test_if_mention(block)
|
||||
# pprint(block)
|
||||
if mention:
|
||||
mention_date = mention["date"]["start"]
|
||||
time_zone = gettz("Asia/Chongqing")
|
||||
mention_datetime = parse(mention_date)
|
||||
now = datetime.datetime.now(time_zone)
|
||||
duration = now - mention_datetime
|
||||
duration_seconds = duration.total_seconds()
|
||||
if -5 * 60 < duration_seconds < 0: # 提前5分钟通知
|
||||
send_msg(f"任务 {task_name} 要开始了。地址:{task_url}")
|
||||
logger.info(f"提示了任务 {task_name} ")
|
||||
pass
|
||||
# pprint(mention)
|
||||
|
||||
|
||||
async def loop():
|
||||
while True:
|
||||
logger.info("检查任务。")
|
||||
await check_un_do()
|
||||
await asyncio.sleep(3 * 60) # 3分钟检查一次
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# update_callout()
|
||||
if platform.system() == "Windows":
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||
asyncio.run(loop())
|
||||
print("PyCharm")
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
# Automatically generated by https://github.com/damnever/pigar.
|
||||
|
||||
# D:\code\notion\api.py: 1
|
||||
fastapi == 0.70.1
|
||||
|
||||
# D:\code\notion\main.py: 12
|
||||
loguru == 0.5.3
|
||||
|
||||
# D:\code\notion\auth.py: 1
|
||||
notion == 0.0.28
|
||||
|
||||
# D:\code\notion\main.py: 3
|
||||
notion_client == 0.9.0
|
||||
|
||||
# D:\code\notion\main.py: 7,8
|
||||
python_dateutil == 2.8.2
|
||||
|
||||
# D:\code\notion\main.py: 10
|
||||
requests == 2.26.0
|
||||
Loading…
Reference in New Issue