Able to create memo
This commit is contained in:
parent
faf9695857
commit
1e40922b6c
0
memos/__init__.py
Normal file
0
memos/__init__.py
Normal file
26
memos/memos.py
Normal file
26
memos/memos.py
Normal file
@ -0,0 +1,26 @@
|
||||
import requests
|
||||
import logging
|
||||
import json
|
||||
|
||||
MEMOS_VISIBILITY_UNSPECIFIED = 'VISIBILITY_UNSPECIFIED'
|
||||
MEMOS_VISIBILITY_PRIVATE = 'PRIVATE'
|
||||
MEMOS_VISIBILITY_PROTECTED = 'PROTECTED'
|
||||
MEMOS_VISIBILITY_PUBLIC = 'PUBLIC'
|
||||
|
||||
|
||||
class Memos:
|
||||
def __init__(self, token: str, base_url: str) -> None:
|
||||
self.token = token
|
||||
self.base_url = base_url
|
||||
self.custom_header = dict(Authorization=f'Bearer {token}')
|
||||
self.create_memo_url = base_url + '/api/v1/memos'
|
||||
self.logger = logging.getLogger('memos')
|
||||
|
||||
def create_memo(self, content:str, visibility: str, **kwargs) -> None:
|
||||
body = json.dumps(dict(content=content, visibility=visibility) | kwargs)
|
||||
r = requests.post(self.create_memo_url, data=body, headers=self.custom_header)
|
||||
if r.status_code == 200:
|
||||
result = r.json()
|
||||
self.logger.info("Memo created: " + result['name'])
|
||||
else:
|
||||
self.logger.error("Failed to create memo: " + r.text)
|
||||
12
test_memo.py
Normal file
12
test_memo.py
Normal file
@ -0,0 +1,12 @@
|
||||
from memos import memos
|
||||
import logging
|
||||
import time
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
m = memos.Memos(
|
||||
token='eyJhbGciOiJIUzI1NiIsImtpZCI6InYxIiwidHlwIjoiSldUIn0.eyJuYW1lIjoidHJhZGVCb3QiLCJpc3MiOiJtZW1vcyIsInN1YiI6IjMiLCJhdWQiOlsidXNlci5hY2Nlc3MtdG9rZW4iXSwiaWF0IjoxNzMxNDIzNjU4fQ.cWQ4Z6WqTjlXPJxIfG7kjZhOO1GTTKiu4FuUIyfE0Ac',
|
||||
base_url='https://memos.gao7.cc')
|
||||
|
||||
m.create_memo(f'**Test**\n*{time.time()}*\n#api-test', memos.MEMOS_VISIBILITY_PROTECTED)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user