Compare commits
No commits in common. "3e707ab004df69ecc37039c835939bc070bfc0a7" and "b7b3d126520a5b22e187dad0517ac9fa9095598b" have entirely different histories.
3e707ab004
...
b7b3d12652
15
config.ini
15
config.ini
|
@ -12,13 +12,14 @@ instance = mastodon.example.org
|
||||||
# ${instance}/settings/applications
|
# ${instance}/settings/applications
|
||||||
token = blahblah
|
token = blahblah
|
||||||
|
|
||||||
# Your user ID.
|
# Mastodon user ID. Used to filter out posts. Unfortunately, I can't find a way
|
||||||
# Doesn't necessarily yours, it can be any user's ID, but that user should be
|
# to get it using token itself. GARGROOOOOOON!!!!!
|
||||||
# on the list for crossposter to find it.
|
# Anyways, you could navigate to your profile ${instance}/@${username} and
|
||||||
# Setting it to "auto" will just grab yours instead. Don't worry about it
|
# look for your profile picture link. For example, for me it's
|
||||||
# EXCEPT if you're using Pleroma. Check #11 issue for more details:
|
# https://mastodon.astrr.ru/system/accounts/avatars/107/914/495/779/447/227/original/9651ac2f47cb2993.jpg
|
||||||
# https://github.com/hatkidchan/mastoposter/issues/11
|
# that part between "avarars" and "original" is the user ID. Grab it, remove
|
||||||
user = auto
|
# all of the slashes and you should be left with, for example, this:
|
||||||
|
user = 107914495779447227
|
||||||
|
|
||||||
# Mastodon user list ID. AGAIN, UNFORTUNATELY, there is no way to reliably use
|
# Mastodon user list ID. AGAIN, UNFORTUNATELY, there is no way to reliably use
|
||||||
# streaming API to get all of your posts. Using home timeline is unreliable and
|
# streaming API to get all of your posts. Using home timeline is unreliable and
|
||||||
|
|
|
@ -5,12 +5,7 @@ from mastoposter import execute_integrations, load_integrations_from
|
||||||
from mastoposter.integrations import FilteredIntegration
|
from mastoposter.integrations import FilteredIntegration
|
||||||
from mastoposter.sources import websocket_source
|
from mastoposter.sources import websocket_source
|
||||||
from typing import AsyncGenerator, Callable, List
|
from typing import AsyncGenerator, Callable, List
|
||||||
from mastoposter.types import Account, Status
|
from mastoposter.types import Status
|
||||||
from httpx import Client
|
|
||||||
|
|
||||||
|
|
||||||
WSOCK_TEMPLATE = "wss://{instance}/api/v1/streaming"
|
|
||||||
VERIFY_CREDS_TEMPLATE = "https://{instance}/api/v1/accounts/verify_credentials"
|
|
||||||
|
|
||||||
|
|
||||||
async def listen(
|
async def listen(
|
||||||
|
@ -55,22 +50,12 @@ def main(config_path: str):
|
||||||
|
|
||||||
modules: List[FilteredIntegration] = load_integrations_from(conf)
|
modules: List[FilteredIntegration] = load_integrations_from(conf)
|
||||||
|
|
||||||
user_id: str = conf["main"]["user"]
|
|
||||||
if user_id == "auto":
|
|
||||||
with Client() as c:
|
|
||||||
rq = c.get(
|
|
||||||
VERIFY_CREDS_TEMPLATE.format(**conf["main"]),
|
|
||||||
params={"access_token": conf["main"]["token"]},
|
|
||||||
)
|
|
||||||
account = Account.from_dict(rq.json())
|
|
||||||
user_id = account.id
|
|
||||||
|
|
||||||
url = "wss://{}/api/v1/streaming".format(conf["main"]["instance"])
|
url = "wss://{}/api/v1/streaming".format(conf["main"]["instance"])
|
||||||
run(
|
run(
|
||||||
listen(
|
listen(
|
||||||
websocket_source,
|
websocket_source,
|
||||||
modules,
|
modules,
|
||||||
user_id,
|
conf["main"]["user"],
|
||||||
url=url,
|
url=url,
|
||||||
reconnect=conf["main"].getboolean("auto_reconnect", False),
|
reconnect=conf["main"].getboolean("auto_reconnect", False),
|
||||||
list=conf["main"]["list"],
|
list=conf["main"]["list"],
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from dataclasses import dataclass, field, fields
|
from dataclasses import dataclass, field
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Callable, Optional, List, Literal, TypeVar
|
from typing import Any, Callable, Optional, List, Literal, TypeVar
|
||||||
|
|
||||||
|
@ -51,9 +51,7 @@ class Emoji:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data: dict) -> "Emoji":
|
def from_dict(cls, data: dict) -> "Emoji":
|
||||||
return cls(
|
return cls(**data)
|
||||||
**{f.name: data[f.name] for f in fields(cls) if f.name in data}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -132,7 +130,7 @@ class AttachmentMetaImage:
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data: dict) -> "AttachmentMetaImage":
|
def from_dict(cls, data: dict) -> "AttachmentMetaImage":
|
||||||
return cls(
|
return cls(
|
||||||
**{f.name: data[f.name] for f in fields(cls) if f.name in data},
|
**data,
|
||||||
original=cls.AttachmentMetaImageDimensions(**data["original"]),
|
original=cls.AttachmentMetaImageDimensions(**data["original"]),
|
||||||
small=cls.AttachmentMetaImageDimensions(**data["small"]),
|
small=cls.AttachmentMetaImageDimensions(**data["small"]),
|
||||||
focus=cls.Vec2F(**data["focus"])
|
focus=cls.Vec2F(**data["focus"])
|
||||||
|
@ -193,9 +191,7 @@ class Attachment:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data: dict) -> "Attachment":
|
def from_dict(cls, data: dict) -> "Attachment":
|
||||||
return cls(
|
return cls(**data)
|
||||||
**{f.name: data[f.name] for f in fields(cls) if f.name in data}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -206,9 +202,7 @@ class Application:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data: dict) -> "Application":
|
def from_dict(cls, data: dict) -> "Application":
|
||||||
return cls(
|
return cls(**data)
|
||||||
**{f.name: data[f.name] for f in fields(cls) if f.name in data}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -220,9 +214,7 @@ class Mention:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data: dict) -> "Mention":
|
def from_dict(cls, data: dict) -> "Mention":
|
||||||
return cls(
|
return cls(**data)
|
||||||
**{f.name: data[f.name] for f in fields(cls) if f.name in data}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -232,9 +224,7 @@ class Tag:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data: dict) -> "Tag":
|
def from_dict(cls, data: dict) -> "Tag":
|
||||||
return cls(
|
return cls(**data)
|
||||||
**{f.name: data[f.name] for f in fields(cls) if f.name in data}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
Loading…
Reference in New Issue