40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
import memos
|
|
import re
|
|
|
|
|
|
token = ''
|
|
api_client = memos.ApiClient()
|
|
api_client.configuration.host = 'https://memos.tunpok.com'
|
|
api_client.set_default_header('Authorization', f'Bearer {token}')
|
|
memo_client = memos.MemoServiceApi(api_client)
|
|
|
|
|
|
def add_url_tag(memo):
|
|
""" if memo has url, add tag '网页' to it.
|
|
"""
|
|
# if content has url that starts with http or https
|
|
# get the url
|
|
url = None
|
|
if re.search(r'http[s]?://', memo.content):
|
|
url = re.search(r'http[s]?://[^\s]+', memo.content).group()
|
|
modified = False
|
|
if url:
|
|
# if not already has tag '#网页 ', add it
|
|
if not re.search(r'#网页 ', memo.content):
|
|
memo.content += ' #网页 '
|
|
modified = True
|
|
if modified:
|
|
memo_client.memo_service_update_memo(memo, memo.id)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
next_page_token = None
|
|
while next_page_token != '':
|
|
if next_page_token is None:
|
|
next_page_token = ''
|
|
memos_resp = memo_client.memo_service_list_memos(page_token=next_page_token)
|
|
for memo in memos_resp.memos:
|
|
add_url_tag(memo)
|
|
next_page_token = memos_resp.next_page_token
|
|
|