From 6c589a7dca813d55383a302f52aa11310da077cf Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Fri, 2 Aug 2024 20:07:20 +0300 Subject: [PATCH] Fix templates in virtualenv --- MANIFEST.in | 6 +++ README.md | 45 +++++++++++++++---- .../mastodon_email_bridge.py | 20 ++++++++- pyproject.toml | 12 ++--- requirements.txt | 4 +- setup.cfg | 2 +- setup.py | 7 +-- .../templates => templates}/new_post.html.j2 | 0 .../templates => templates}/new_post.txt.j2 | 0 9 files changed, 75 insertions(+), 21 deletions(-) create mode 100644 MANIFEST.in rename {mastodon_email_bridge/templates => templates}/new_post.html.j2 (100%) rename {mastodon_email_bridge/templates => templates}/new_post.txt.j2 (100%) diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..1d1a3e1 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,6 @@ +graft templates +include LICENSE +include README.md +include podman_build.sh +include podman_run.sh +include Dockerfile diff --git a/README.md b/README.md index 5f5b875..80c2768 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,50 @@ # mastodon_email_bridge +Simple script to forward your Mastodon Home timeline to your email. + ## Requirements +You need to obtain an application token with read access and provide it with the --token parameter. + +Check the requirements.txt file but the installation should take care of everything. + ## Installation ### Linux ```bash -sudo python3 setup.py install -``` - -### Windows (from PowerShell) - - ```powershell -& $(where.exe python).split()[0] setup.py install +python -m venv "${HOME}/pyenvs/mastodon_email_bridge" +source "${HOME}/pyenvs/mastodon_email_bridge/bin/activate" +pip install . +mkdir -p "${HOME}/.config/mastodon_email_bridge" +cp -r templates "${HOME}/.config/mastodon_email_bridge/" ``` ## Usage - ```bash -mastodon_email_bridge.py [--debug-level|-d CRITICAL|ERROR|WARNING|INFO|DEBUG|NOTSET] # Other parameters +``` + Usage: mastodon_email_bridge.py [OPTIONS] + + Options: + -d, --debug-level [CRITICAL|ERROR|WARNING|INFO|DEBUG|NOTSET] + Set the debug level for the standard output. + -t, --token TEXT Mastodon token with read access. [required] + -s, --server TEXT Mastodon server full qualified name. + -L, --limit INTEGER Mastodon token with read access. + -w, --wait INTEGER Seconds to wait between requests to avoid + rate limits. + -r, --recipient TEXT Recipient email to get the posts. + [required] + -S, --sender TEXT Sender email thant send the posts. + -f, --sent-items-file TEXT File to store the IDs of post already sent + by email. + -m, --mail-server TEXT SMTP Mail server to send emails. + -u, --mail-user TEXT Username for SMTP Mail server to send + emails. + -P, --mail-pass TEXT User password for SMTP Mail server to send + emails. + -p, --mail-server-port INTEGER SMTP Mail server port to send emails. + -l, --log-file TEXT File to store all debug messages. + --config FILE Read configuration from FILE. + --help Show this message and exit. ``` diff --git a/mastodon_email_bridge/mastodon_email_bridge.py b/mastodon_email_bridge/mastodon_email_bridge.py index 193a9a3..de6880f 100755 --- a/mastodon_email_bridge/mastodon_email_bridge.py +++ b/mastodon_email_bridge/mastodon_email_bridge.py @@ -18,7 +18,7 @@ import sqlite3 import click import click_config_file import requests -from jinja2 import Environment, PackageLoader, select_autoescape +from jinja2 import Environment, PackageLoader, select_autoescape, FileSystemLoader class MastodonEmailBridge: '''CLass to redirect the Mastodon home timeline to email''' @@ -50,8 +50,24 @@ class MastodonEmailBridge: ) self._init_log() self._get_sent_posts() + templates_folder = os.path.join( + os.environ.get( + 'HOME', + os.environ.get( + 'USERPROFILE', + os.getcwd() + ) + ), + '.config', + 'mastodon_email_bridge', + 'templates' + ) + if not os.path.exists(templates_folder): + os.mkdir(templates_folder) + self.j2env = Environment( - loader=PackageLoader("mastodon_email_bridge"), + #loader=PackageLoader("mastodon_email_bridge"), + loader=FileSystemLoader(templates_folder, followlinks=True), autoescape=select_autoescape() ) self.session = requests.Session() diff --git a/pyproject.toml b/pyproject.toml index 96168e1..e52d032 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,12 +3,12 @@ requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" [project.urls] -Homepage = "" +Homepage = "https://codeberg.org/adelgado/mastodon_email_bridge" [project] name = "mastodon_email_bridge" -version = "0.0.1" -description = "Redirect the home timeline to email" +version = "0.0.3" +description = "Redirect your Mastodon Home timeline to your email" readme = "README.md" authors = [{ name = "Antonio J. Delgado", email = "ad@susurrando.com" }] license = { file = "LICENSE" } @@ -17,9 +17,11 @@ classifiers = [ "Programming Language :: Python", "Programming Language :: Python :: 3", ] -#keywords = ["vCard", "contacts", "duplicates"] +keywords = ["Mastodon", "email", "fediverse", "ActivityPub"] dependencies = [ "click", "click_config_file", + "requests", + "jinja2", ] -requires-python = ">=3" \ No newline at end of file +requires-python = ">=3" diff --git a/requirements.txt b/requirements.txt index 66bf966..d0d370a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ click -click_config_file \ No newline at end of file +click_config_file +requests +jinja2 diff --git a/setup.cfg b/setup.cfg index d46dfcb..388585c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = mastodon_email_bridge -version = 0.0.1 +version = 0.0.3 [options] packages = mastodon_email_bridge diff --git a/setup.py b/setup.py index 83ecd51..1233e34 100644 --- a/setup.py +++ b/setup.py @@ -14,10 +14,11 @@ setuptools.setup( version=config['metadata']['version'], name=config['metadata']['name'], author_email="ad@susurrando.com", - url="", - description="Redirect the home timeline to email", + url="https://codeberg.org/adelgado/mastodon_email_bridge", + description="Redirect your Mastodon Home timeline to your email", long_description="README.md", long_description_content_type="text/markdown", license="GPLv3", - # keywords=["my", "script", "does", "things"] + keywords=["Mastodon", "email", "fediverse", "ActivityPub"], + include_package_data=True, ) diff --git a/mastodon_email_bridge/templates/new_post.html.j2 b/templates/new_post.html.j2 similarity index 100% rename from mastodon_email_bridge/templates/new_post.html.j2 rename to templates/new_post.html.j2 diff --git a/mastodon_email_bridge/templates/new_post.txt.j2 b/templates/new_post.txt.j2 similarity index 100% rename from mastodon_email_bridge/templates/new_post.txt.j2 rename to templates/new_post.txt.j2