Add config for folders

This commit is contained in:
Antonio J. Delgado 2024-09-20 11:08:51 +03:00
parent 273200f8a4
commit d5aac011a1
3 changed files with 39 additions and 22 deletions

View file

@ -51,6 +51,9 @@ class MastodonEmailBridge:
) )
self._init_log() self._init_log()
self._get_sent_posts() self._get_sent_posts()
if 'templates_folder' in self.config:
templates_folder=self.config['templates_folder']
else:
templates_folder = os.path.join( templates_folder = os.path.join(
os.environ.get( os.environ.get(
'HOME', 'HOME',
@ -187,6 +190,7 @@ class MastodonEmailBridge:
data=data, data=data,
json_raw=json.dumps(data, indent=2) json_raw=json.dumps(data, indent=2)
) )
if 'sent_folder' not in self.config:
sent_folder = os.path.join( sent_folder = os.path.join(
os.environ.get( os.environ.get(
'HOME', 'HOME',
@ -197,6 +201,8 @@ class MastodonEmailBridge:
), ),
'.mastodon_email_bridge_sent_items' '.mastodon_email_bridge_sent_items'
) )
else:
sent_folder = self.config['sent_folder']
if not os.path.exists(sent_folder): if not os.path.exists(sent_folder):
os.mkdir(sent_folder) os.mkdir(sent_folder)
sent_file = os.path.join(sent_folder, data['id'] + '.html') sent_file = os.path.join(sent_folder, data['id'] + '.html')
@ -328,6 +334,17 @@ class MastodonEmailBridge:
default='{{ data["account"]["display_name"] }} ({{ data["account"]["username"] }}) {% if data["in_reply_to_id"] %}replied {% else %}posted{% endif %}{% for tag in data["tags"] %} #{{ tag["name"] }}{% endfor %}', default='{{ data["account"]["display_name"] }} ({{ data["account"]["username"] }}) {% if data["in_reply_to_id"] %}replied {% else %}posted{% endif %}{% for tag in data["tags"] %} #{{ tag["name"] }}{% endfor %}',
help='Jinja2 template for the subject of the emails.' help='Jinja2 template for the subject of the emails.'
) )
@click.option(
'--sent-folder',
'-F',
help='Folder to store generated HTML files to be sent.'
)
@click.option(
'--templates-folder',
'-T',
help='Folder with the templates to generate HTML and text files to be sent.'
)
@click.option('--log-file', '-l', help="File to store all debug messages.") @click.option('--log-file', '-l', help="File to store all debug messages.")
# @click.option("--dummy","-n", is_flag=True, # @click.option("--dummy","-n", is_flag=True,
# help="Don't do anything, just show what would be done.") # help="Don't do anything, just show what would be done.")

View file

@ -7,7 +7,7 @@ Homepage = "https://codeberg.org/adelgado/mastodon_email_bridge"
[project] [project]
name = "mastodon_email_bridge" name = "mastodon_email_bridge"
version = "1.0.0" version = "1.0.1"
description = "Redirect your Mastodon Home timeline to your email" description = "Redirect your Mastodon Home timeline to your email"
readme = "README.md" readme = "README.md"
authors = [{ name = "Antonio J. Delgado", email = "ad@susurrando.com" }] authors = [{ name = "Antonio J. Delgado", email = "ad@susurrando.com" }]

View file

@ -1,6 +1,6 @@
[metadata] [metadata]
name = mastodon_email_bridge name = mastodon_email_bridge
version = 1.0.0 version = 1.0.1
[options] [options]
packages = mastodon_email_bridge packages = mastodon_email_bridge