Skip to content

Commit

Permalink
refacto: use mastodonpy to broadcast comments (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts authored Apr 30, 2024
2 parents 7250505 + 66fd77b commit 03280be
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 232 deletions.
22 changes: 8 additions & 14 deletions geotribu_cli/comments/comments_broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
from geotribu_cli.comments.comments_toolbelt import find_comment_by_id
from geotribu_cli.comments.mdl_comment import Comment
from geotribu_cli.constants import GeotribuDefaults
from geotribu_cli.social.mastodon_client import broadcast_to_mastodon
from geotribu_cli.social.mastodon_client import ( # broadcast_to_mastodon,
ExtendedMastodonClient,
)
from geotribu_cli.utils.start_uri import open_uri
from geotribu_cli.utils.str2bool import str2bool

Expand Down Expand Up @@ -83,6 +85,7 @@ def parser_comments_broadcast(
choices=[
"mastodon",
],
default="mastodon",
dest="broadcast_to",
help="Canaux (réseaux sociaux) où publier le(s) commentaire(s).",
required=True,
Expand All @@ -106,16 +109,6 @@ def parser_comments_broadcast(
help="Désactive l'ouverture automatique du post à la fin de la commande.",
)

subparser.add_argument(
"--no-public",
"--private",
default=True,
action="store_false",
dest="opt_no_public",
help="Publie le commentaire en mode privé (ne fonctionne pas avec tous les "
"canaux de diffusion).",
)

subparser.set_defaults(func=run)

return subparser
Expand Down Expand Up @@ -160,9 +153,10 @@ def run(args: argparse.Namespace):
# check credentials
if args.broadcast_to == "mastodon":
try:
online_post = broadcast_to_mastodon(
in_comment=comment_obj, public=args.opt_no_public
)
mastodon_client = ExtendedMastodonClient()
online_post = mastodon_client.broadcast_comment(in_comment=comment_obj)
if not online_post:
print(f"le commentaire n'a pas encore été publié : {comment_obj.id}")
except Exception as err:
logger.error(
f"La publication du commentaire {comment_obj.id} a échoué. "
Expand Down
3 changes: 0 additions & 3 deletions geotribu_cli/social/cmd_mastodon_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
from geotribu_cli.constants import GeotribuDefaults
from geotribu_cli.social.mastodon_client import ExtendedMastodonClient

# 3rd party


# ############################################################################
# ########## GLOBALS #############
# ################################
Expand Down
Loading

0 comments on commit 03280be

Please sign in to comment.