2021-02-03 12:20:28 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
# Misskey API Docs: https://misskey.io/api-doc
|
|
|
|
import requests
|
2021-02-04 08:00:07 +01:00
|
|
|
import re
|
2021-02-03 12:20:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Misskey:
|
|
|
|
debug = True
|
2021-02-04 08:00:07 +01:00
|
|
|
baseurl = ""
|
2021-02-03 12:20:28 +01:00
|
|
|
|
2021-02-04 08:00:07 +01:00
|
|
|
def post(self, content, i, channel="", visibility="public",):
|
|
|
|
print("Creating new post to", self.baseurl, ":", content)
|
|
|
|
req_url = self.baseurl + "/api/notes/create"
|
2021-02-03 12:20:28 +01:00
|
|
|
body = {
|
2021-02-06 04:58:25 +01:00
|
|
|
"noExtractMentions": True,
|
|
|
|
"noExtractHashtags": True,
|
|
|
|
"noExtractEmojis": True,
|
2021-02-04 01:22:39 +01:00
|
|
|
"visibility": visibility,
|
2021-02-03 12:20:28 +01:00
|
|
|
"text": content,
|
|
|
|
"localOnly": channel != "",
|
2021-02-04 08:00:07 +01:00
|
|
|
"i": i
|
2021-02-03 12:20:28 +01:00
|
|
|
}
|
|
|
|
if channel != "":
|
|
|
|
body["channelId"] = channel
|
|
|
|
result = requests.post(req_url, json=body)
|
|
|
|
if result.status_code == 200:
|
2021-02-04 08:00:07 +01:00
|
|
|
return True
|
2021-02-03 12:20:28 +01:00
|
|
|
else:
|
|
|
|
print("Failed to post:", result.json()['error']['message'])
|
|
|
|
return False
|
2021-02-04 08:00:07 +01:00
|
|
|
|
|
|
|
def upload_from_url(self, i, url):
|
|
|
|
print("Uploading img to misskey")
|
|
|
|
req_url = self.baseurl + "/api/drive/files/upload-from-url"
|
|
|
|
body = {
|
|
|
|
"url": url,
|
|
|
|
"i": i
|
|
|
|
}
|
|
|
|
r = requests.post(req_url, json=body)
|
|
|
|
if r.status_code == 204:
|
|
|
|
print("Done!")
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
print("Failed to upload:", r.json()['error']['message'])
|
|
|
|
return False
|