From 70f14c5ab860929a08ffe757174eabe03ad2bdad Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Wed, 8 Jan 2025 10:50:57 +1100 Subject: [PATCH] Added some example bot scripts which I tested --- pyproject.toml | 2 +- src/gotosocial/bot_example.py | 21 +++++++++++++++++++++ src/gotosocial/image_bot_example.py | 21 +++++++++++++++++++++ src/gotosocial/register.py | 4 +++- 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/gotosocial/bot_example.py create mode 100644 src/gotosocial/image_bot_example.py diff --git a/pyproject.toml b/pyproject.toml index 96a40d8..b52a645 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ version = "0.1.0" description = "A Python library for GoToSocial clients" readme = "README.md" authors = [ - { name = "Mike Lynch", email = "m.lynch@sydney.edu.au" } + { name = "Mike Lynch", email = "mike@llull.club" } ] requires-python = ">=3.9" dependencies = [ diff --git a/src/gotosocial/bot_example.py b/src/gotosocial/bot_example.py new file mode 100644 index 0000000..d66f5a4 --- /dev/null +++ b/src/gotosocial/bot_example.py @@ -0,0 +1,21 @@ +# example bot script + +from gotosocial.client import GoToSocialBot +import json + +CONFIG = "config.json" + +# the config file should look like +# +# { +# "base_url": "https://your.gts.instance.here", +# "access_token": "YOURACCESSTOKENGOESHERE" +# } +# + +if __name__ == "__main__": + with open(CONFIG, "r") as cfh: + cf = json.load(cfh) + bot = GoToSocialBot() + bot.auth(cf) + bot.post("A test post", {"spoiler_text": "test post"}) diff --git a/src/gotosocial/image_bot_example.py b/src/gotosocial/image_bot_example.py new file mode 100644 index 0000000..20d86c7 --- /dev/null +++ b/src/gotosocial/image_bot_example.py @@ -0,0 +1,21 @@ +# example bot script + +from gotosocial.client import GoToSocialBot +import json + +CONFIG = "config.json" + +# the config file should look like +# +# { +# "base_url": "https://your.gts.instance.here", +# "access_token": "YOURACCESSTOKENGOESHERE" +# } +# + +if __name__ == "__main__": + with open(CONFIG, "r") as cfh: + cf = json.load(cfh) + bot = GoToSocialBot() + bot.auth(cf) + bot.post_image("./my_image.png", "A test post", {"spoiler_text": "test post"}) diff --git a/src/gotosocial/register.py b/src/gotosocial/register.py index 77a9fac..a261e22 100644 --- a/src/gotosocial/register.py +++ b/src/gotosocial/register.py @@ -42,7 +42,9 @@ class Application: print("Visit this URL in a private browser window to authenticate:") print(auth_url) print("\nThen run this script again with the OOB token, like:") - print("> uv run register -u {self.base_ur} -n {self.name} -t OOB_TOKEB") + print( + "> uv run register -u {self.base_ur} -n {self.name} -t REPLACEMEWITHTOKEN" + ) return True except Exception as e: print("Something went wrong:")