-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add subcomand to export Mastodon data
- Loading branch information
Showing
3 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#! python3 # noqa: E265 | ||
|
||
# ############################################################################ | ||
# ########## IMPORTS ############# | ||
# ################################ | ||
|
||
# standard library | ||
import argparse | ||
import logging | ||
from os import getenv | ||
from pathlib import Path | ||
|
||
# package | ||
from geotribu_cli.constants import GeotribuDefaults | ||
from geotribu_cli.social.mastodon_client import ExtendedMastodonClient | ||
|
||
# 3rd party | ||
|
||
|
||
# ############################################################################ | ||
# ########## GLOBALS ############# | ||
# ################################ | ||
|
||
logger = logging.getLogger(__name__) | ||
defaults_settings = GeotribuDefaults() | ||
|
||
|
||
# ############################################################################ | ||
# ########## CLI ################# | ||
# ################################ | ||
|
||
|
||
def parser_mastodon_export( | ||
subparser: argparse.ArgumentParser, | ||
) -> argparse.ArgumentParser: | ||
"""Set the argument parser for subcommand. | ||
Args: | ||
subparser (argparse.ArgumentParser): parser to set up | ||
Returns: | ||
argparse.ArgumentParser: parser ready to use | ||
""" | ||
|
||
subparser.add_argument( | ||
"-w", | ||
"--where", | ||
help="Dossier dans lequel exporter les fichiers.", | ||
default=getenv( | ||
"GEOTRIBU_MASTODON_EXPORT_DEST_FOLDER", | ||
defaults_settings.geotribu_working_folder.joinpath("mastodon/"), | ||
), | ||
type=Path, | ||
dest="dest_export_folder", | ||
) | ||
|
||
subparser.set_defaults(func=run) | ||
|
||
return subparser | ||
|
||
|
||
# ############################################################################ | ||
# ########## MAIN ################ | ||
# ################################ | ||
|
||
|
||
def run(args: argparse.Namespace): | ||
"""Run the sub command logic. | ||
Open result of a previous command. | ||
Args: | ||
args (argparse.Namespace): arguments passed to the subcommand | ||
""" | ||
logger.debug(f"Running {args.command} with {args}") | ||
|
||
mastodon_client = ExtendedMastodonClient() | ||
mastodon_client.export_data( | ||
dest_path_following_accounts=Path(args.dest_export_folder).joinpath( | ||
"mastodon_comptes_suivis_geotribu.csv" | ||
), | ||
dest_path_lists=Path(args.dest_export_folder).joinpath( | ||
"mastodon_listes_geotribu.csv" | ||
), | ||
dest_path_lists_only_accounts=Path(args.dest_export_folder).joinpath( | ||
"mastodon_comptes_des_listes_geotribu.csv" | ||
), | ||
) | ||
|
||
|
||
# -- Stand alone execution | ||
if __name__ == "__main__": | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters