mirror of
https://gitea.phreedom.club/localhost_frssoft/FMN_bot.git
synced 2025-07-27 03:54:16 +00:00
Large initial commit
This commit is contained in:
commit
838c25b639
12 changed files with 585 additions and 0 deletions
56
src/fedi_api.py
Normal file
56
src/fedi_api.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
import json
|
||||
import requests
|
||||
from config import instance
|
||||
|
||||
instance_point = f"https://{instance}/api/v1"
|
||||
|
||||
with open(".auth", mode='rt') as auth:
|
||||
tkn = auth.read().replace('\n', '')
|
||||
|
||||
headers= {
|
||||
"Authorization": "Bearer " + tkn
|
||||
}
|
||||
|
||||
def get_notifications():
|
||||
params = {
|
||||
"limit": 15,
|
||||
"type": "mention"
|
||||
}
|
||||
r = requests.get(instance_point + "/notifications", params, headers=headers)
|
||||
return r.json()
|
||||
|
||||
|
||||
def mark_as_read_notification(id_notification):
|
||||
r = requests.post(instance_point + f"/notifications/{id_notification}/dismiss", headers=headers)
|
||||
return r.json()
|
||||
|
||||
|
||||
def get_status_context(status_id):
|
||||
r = requests.get(instance_point + f"/statuses/{status_id}/context", headers=headers)
|
||||
return r.json()
|
||||
|
||||
|
||||
def get_status(status_id):
|
||||
r = requests.get(instance_point + f"/statuses/{status_id}", headers=headers)
|
||||
return r.json()
|
||||
|
||||
|
||||
def post_status(text, reply_to_status_id=None, poll_options=None, poll_expires=345600):
|
||||
poll = None
|
||||
if poll_options is not None:
|
||||
poll = {
|
||||
"options": poll_options,
|
||||
"expires_in": poll_expires,
|
||||
"multiple": True
|
||||
}
|
||||
print(poll_options)
|
||||
params = {
|
||||
"status": text,
|
||||
"in_reply_to_id": reply_to_status_id,
|
||||
"visibility": "unlisted",
|
||||
"content_type": "text/plain",
|
||||
"poll": poll
|
||||
}
|
||||
r = requests.post(instance_point + "/statuses", json=params, headers=headers)
|
||||
return r.json()
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue