commit c3e2b3c94e859654812622fbabe25279c059dbb6 Author: l3n Date: Mon Aug 23 01:08:25 2021 +0200 Initial commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9866359 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +scratch + diff --git a/README.org b/README.org new file mode 100644 index 0000000..fd500f6 --- /dev/null +++ b/README.org @@ -0,0 +1,35 @@ +* Mobilizon importer + + File importer into mobilizon graphql api. + +** Morganize + +This doesn't really make a lot of sense. I'm working on a script to import +events via mobilizon GraphQL api from yaml or json or whatever. Probably yaml. + +** Functionality + +*** Login + +*** Get events + +*** Create event + + - options: + - update existing + - skip existing + +**** From file + +**** User input + +**** Rss feed + +** Structure + + - python Click library for cli + - json + - graphql-core https://github.com/graphql-python/graphql-core + - https://graphql-core-3.readthedocs.io/en/latest/usage/queries.html + +*** developing in guix diff --git a/mobili_cli.egg-info/PKG-INFO b/mobili_cli.egg-info/PKG-INFO new file mode 100644 index 0000000..fdcf603 --- /dev/null +++ b/mobili_cli.egg-info/PKG-INFO @@ -0,0 +1,10 @@ +Metadata-Version: 1.0 +Name: mobili-cli +Version: 0.1 +Summary: UNKNOWN +Home-page: UNKNOWN +Author: UNKNOWN +Author-email: UNKNOWN +License: UNKNOWN +Description: UNKNOWN +Platform: UNKNOWN diff --git a/mobili_cli.egg-info/SOURCES.txt b/mobili_cli.egg-info/SOURCES.txt new file mode 100644 index 0000000..7bf1568 --- /dev/null +++ b/mobili_cli.egg-info/SOURCES.txt @@ -0,0 +1,12 @@ +setup.py +mobili_cli/__init__.py +mobili_cli/cli.py +mobili_cli.egg-info/PKG-INFO +mobili_cli.egg-info/SOURCES.txt +mobili_cli.egg-info/dependency_links.txt +mobili_cli.egg-info/entry_points.txt +mobili_cli.egg-info/requires.txt +mobili_cli.egg-info/top_level.txt +mobili_cli/commands/__init__.py +mobili_cli/commands/cmd_init.py +mobili_cli/commands/cmd_status.py \ No newline at end of file diff --git a/mobili_cli.egg-info/dependency_links.txt b/mobili_cli.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/mobili_cli.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/mobili_cli.egg-info/entry_points.txt b/mobili_cli.egg-info/entry_points.txt new file mode 100644 index 0000000..02f534b --- /dev/null +++ b/mobili_cli.egg-info/entry_points.txt @@ -0,0 +1,4 @@ + + [console_scripts] + mobili_cli=mobili_cli.cli:cli + \ No newline at end of file diff --git a/mobili_cli.egg-info/requires.txt b/mobili_cli.egg-info/requires.txt new file mode 100644 index 0000000..42d4040 --- /dev/null +++ b/mobili_cli.egg-info/requires.txt @@ -0,0 +1,3 @@ +click +graphql-core +requests diff --git a/mobili_cli.egg-info/top_level.txt b/mobili_cli.egg-info/top_level.txt new file mode 100644 index 0000000..2d18611 --- /dev/null +++ b/mobili_cli.egg-info/top_level.txt @@ -0,0 +1 @@ +mobili_cli diff --git a/mobili_cli/__init__.py b/mobili_cli/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mobili_cli/__pycache__/__init__.cpython-38.pyc b/mobili_cli/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..e3adb40 Binary files /dev/null and b/mobili_cli/__pycache__/__init__.cpython-38.pyc differ diff --git a/mobili_cli/__pycache__/cli.cpython-38.pyc b/mobili_cli/__pycache__/cli.cpython-38.pyc new file mode 100644 index 0000000..7e957c2 Binary files /dev/null and b/mobili_cli/__pycache__/cli.cpython-38.pyc differ diff --git a/mobili_cli/cli.py b/mobili_cli/cli.py new file mode 100755 index 0000000..ee80aeb --- /dev/null +++ b/mobili_cli/cli.py @@ -0,0 +1,61 @@ +import os +import sys + +import click + + +CONTEXT_SETTINGS = dict(auto_envvar_prefix="COMPLEX") + + +class Environment: + def __init__(self): + self.verbose = False + self.home = os.getcwd() + + def log(self, msg, *args): + """Logs a message to stderr.""" + if args: + msg %= args + click.echo(msg, file=sys.stderr) + + def vlog(self, msg, *args): + """Logs a message to stderr only if verbose is enabled.""" + if self.verbose: + self.log(msg, *args) + + +pass_environment = click.make_pass_decorator(Environment, ensure=True) +cmd_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "commands")) + +print(cmd_folder) + +class ComplexCLI(click.MultiCommand): + def list_commands(self, ctx): + rv = [] + for filename in os.listdir(cmd_folder): + if filename.endswith(".py") and filename.startswith("cmd_"): + rv.append(filename[4:-3]) + rv.sort() + return rv + + def get_command(self, ctx, name): + try: + mod = __import__(f"mobili_cli.commands.cmd_{name}", None, None, ["cli"]) + except ImportError: + return + return mod.cli + + +@click.command(cls=ComplexCLI, context_settings=CONTEXT_SETTINGS) +@click.option( + "--home", + type=click.Path(exists=True, file_okay=False, resolve_path=True), + help="Changes the folder to operate on.", +) +@click.option("-v", "--verbose", is_flag=True, help="Enables verbose mode.") +@pass_environment +def cli(ctx, verbose, home): + """A mobilizon command line interface.""" + ctx.verbose = verbose + if home is not None: + ctx.home = home diff --git a/mobili_cli/commands/__init__.py b/mobili_cli/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mobili_cli/commands/__pycache__/__init__.cpython-38.pyc b/mobili_cli/commands/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..685db24 Binary files /dev/null and b/mobili_cli/commands/__pycache__/__init__.cpython-38.pyc differ diff --git a/mobili_cli/commands/__pycache__/cmd_init.cpython-38.pyc b/mobili_cli/commands/__pycache__/cmd_init.cpython-38.pyc new file mode 100644 index 0000000..9d9a28a Binary files /dev/null and b/mobili_cli/commands/__pycache__/cmd_init.cpython-38.pyc differ diff --git a/mobili_cli/commands/__pycache__/cmd_status.cpython-38.pyc b/mobili_cli/commands/__pycache__/cmd_status.cpython-38.pyc new file mode 100644 index 0000000..c49bdcf Binary files /dev/null and b/mobili_cli/commands/__pycache__/cmd_status.cpython-38.pyc differ diff --git a/mobili_cli/commands/cmd_init.py b/mobili_cli/commands/cmd_init.py new file mode 100644 index 0000000..7a2eb50 --- /dev/null +++ b/mobili_cli/commands/cmd_init.py @@ -0,0 +1,13 @@ +from mobili_cli.cli import pass_environment + +import click + + +@click.command("init", short_help="Initializes a repo.") +@click.argument("path", required=False, type=click.Path(resolve_path=True)) +@pass_environment +def cli(ctx, path): + """Initializes a repository.""" + if path is None: + path = ctx.home + ctx.log(f"Initialized the repository in {click.format_filename(path)}") diff --git a/mobili_cli/commands/cmd_status.py b/mobili_cli/commands/cmd_status.py new file mode 100644 index 0000000..ff342b1 --- /dev/null +++ b/mobili_cli/commands/cmd_status.py @@ -0,0 +1,11 @@ +from mobili_cli.cli import pass_environment + +import click + + +@click.command("status", short_help="Shows file changes.") +@pass_environment +def cli(ctx): + """Shows file changes in the current working directory.""" + ctx.log("Changed files: none") + ctx.vlog("bla bla bla, debug info") diff --git a/mobili_cli/utils/authenticate.py b/mobili_cli/utils/authenticate.py new file mode 100644 index 0000000..7625832 --- /dev/null +++ b/mobili_cli/utils/authenticate.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +import sys +import json +import sgqlc.endpoint.http import HTTPEndpoint + + +mutation = """ +mutation Login($email: String, $password: String!) { + login(email: $email, password: $password) { + accessToken + refreshToken + user { + id + email + role + } + } +} +""" + +try: + username, password = sys.argv[1:] +except ValueError: + raise SystemExit('Usage: ') + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..8ba8c84 --- /dev/null +++ b/setup.py @@ -0,0 +1,13 @@ +from setuptools import setup + +setup( + name="mobili_cli", + version="0.1", + packages=["mobili_cli", "mobili_cli.commands"], + include_package_data=True, + install_requires=["click", "graphql-core", "requests"], + entry_points=""" + [console_scripts] + mobili_cli=mobili_cli.cli:cli + """, +)