https://qiita.com/donraku/items/147fbea348657a4ffbf1 Based on the contents of ↑, I decided to use Pleasanter's "API function" using python this time. I tried to adopt a framework when using python.
These details are omitted.
I was able to register data in Pleasant using python. (With API) I found that the framework's Fast API is quite usable.
Considering future development, I decided to use the framework. I took a quick look and adopted the Fast API because it looks good. Installation work is omitted.
Click here for information. https://fastapi.tiangolo.com/ja/
Based on the manual, create the smallest source and start the web server. The web server is uvicorn.
Click here for the source. This is all you need.
main.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
Start the web server from the command prompt. Since the port conflicted with the default, specify 8010. It will start immediately.
>uvicorn main:app --reload --port 8010
INFO: Uvicorn running on http://127.0.0.1:8010 (Press CTRL+C to quit)
INFO: Started reloader process [26816] using statreload
INFO: Started server process [22304]
INFO: Waiting for application startup.
INFO: Application startup complete.
Check the display on the browser. Display is OK.
Documents can also be created without permission. It's pretty amazing. By the way.
Create an endpoint called "/ test_create" as a trial, and register the data in Pleasant in it.
main.py
import requests
import json
from fastapi import FastAPI
from requests_ntlm import HttpNtlmAuth
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/test_create")
def test_create():
url = 'http://192.168.10.10/pleasanter/api/items/12389/create'
json_str = '''\
{
"ApiVersion": 1.1,
"ApiKey": "ea55625bb586d27df01c281e5ef5464e4bbe6bc86d1451a24fd430351198ce0bbabc467cdd1d0ebdf4045ec22922dfce7a9f47a8241559229a7d5129d2329879",
"ClassHash": {
"ClassA": "Name 2",
"ClassB": "Affiliation 3",
"ClassC": "Place 4"
},
"DateHash": {
"DateA": "2020/11/08 08:00",
"DateB": "2020/11/08 17:00"
},
"Body": "I work normally"
}
'''
json_data = json.loads(json_str)
headers = {'content-type': 'application/json; charset=UTF-8'}
response = requests.post(url, json=json_data, headers=headers,
auth=HttpNtlmAuth('xxx\xxx', 'xxx'))
return (response.text)
When executed using the document above. .. ..
success! !! "{" Id \ ": 12410, " Status Code \ ": 200, " Message \ ": " \\ "Name 2 \" has been created. \ "}"
Check on the Pleasant screen and OK!
I was able to register, so that's it.
Recommended Posts