diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 50073d2..06f6dc1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ __pycache__/ /nele.egg-info/ /build/ /dist/ +/.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7507e30 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1789073787, + "narHash": "sha256-xfX/toC2QV707s06GbP4II/TxYF0fNQj7s5/LClNDKc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "aff8a0b28396750446e5537a96461bc4facdb287", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..27f92f9 --- /dev/null +++ b/flake.nix @@ -0,0 +1,81 @@ +{ + description = "nele devshell"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + outputs = + { + nixpkgs, + ... + }: + let + systems = nixpkgs.lib.platforms.unix; + eachSystem = + f: + nixpkgs.lib.genAttrs systems ( + system: + f ( + import nixpkgs { + inherit system; + config = { }; + overlays = [ ]; + } + ) + ); + deps = + p: with p; [ + cmarkgfm + python-frontmatter + jinja2 + docopt + ]; + in + { + devShells = eachSystem (pkgs: { + default = pkgs.mkShell { + packages = with pkgs; [ + (python3.withPackages ( + p: + (deps p) + ++ [ + p.flake8 + p.setuptools + ] + )) + ]; + }; + }); + + packages = eachSystem ( + pkgs: + let + fs = pkgs.lib.fileset; + root = ./.; + pypkgs = pkgs.python3Packages; + nele = pypkgs.buildPythonPackage { + pname = "nele"; + version = "0.5.0"; + src = fs.toSource { + inherit root; + fileset = fs.intersection (fs.gitTracked root) ( + fs.fileFilter ( + f: + (f.hasExt "py") + || (f.name == "requirements.txt") + || (f.name == "setup.py") + || (f.name == "setup.cfg") + ) root + ); + }; + propagatedBuildInputs = deps pypkgs; + pyproject = true; + build-system = [ pypkgs.setuptools ]; + }; + in + { + inherit nele; + default = nele; + } + ); + }; +} diff --git a/nele/__init__.py b/nele/__init__.py index 11d2832..8c3f5de 100644 --- a/nele/__init__.py +++ b/nele/__init__.py @@ -31,8 +31,7 @@ from docopt import docopt import yaml import frontmatter -import markdown -from mdx_gfm import GithubFlavoredMarkdownExtension +import cmarkgfm from jinja2 import Template @@ -69,8 +68,8 @@ def load_recipients(config): titles = [x[0] for x in c.description] for row in rows: recipient = {} - for idx in range(len(titles)): - recipient[titles[idx]] = row[idx] + for idx, title in enumerate(titles): + recipient[title] = row[idx] recipients.append(recipient) conn.close() @@ -83,10 +82,9 @@ def send_newsletter(source, config, recipients): # Load E-Mail contents post = frontmatter.load(source) - # Load markdown parser - md = markdown.Markdown(extensions=[GithubFlavoredMarkdownExtension()]) + options = cmarkgfm.Options.CMARK_OPT_UNSAFE - with open(config['email']['template'], 'r') as f: + with open(config['email']['template'], 'r', encoding="utf-8") as f: html_template = Template(f.read()) markdown_template = Template(post.content) @@ -104,7 +102,7 @@ def send_newsletter(source, config, recipients): context.update(post) plain = markdown_template.render(**context) - context['content'] = md.convert(plain) + context['content'] = cmarkgfm.github_flavored_markdown_to_html(plain, options=options) html = html_template.render(**context) textmsg = MIMEMultipart('alternative') textmsg.attach(MIMEText(plain, 'plain', 'utf-8')) @@ -133,7 +131,7 @@ def main(): # Work relative to the config file config_file = os.path.abspath(arguments['--config']) os.chdir(os.path.dirname(config_file)) - config = yaml.safe_load(open(config_file)) + config = yaml.safe_load(open(config_file, encoding="utf-8")) if arguments['send']: print('Are you sure you want to send a newsletter to EVERYONE? [y/N]', end=' ') diff --git a/requirements.txt b/requirements.txt index 26c5e89..df3b90f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -py-gfm +cmarkgfm python-frontmatter jinja2 docopt diff --git a/setup.py b/setup.py index d70f7c7..dcf3768 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name="nele", - version="0.5.0.dev", + version="0.5.0", packages=['nele'], author="Raphael Zimmermann", author_email="dev@raphael.li", @@ -18,7 +18,7 @@ platforms=["Linux"], include_package_data=False, zip_safe=False, - install_requires=['py-gfm', 'python-frontmatter', 'jinja2', 'docopt'], + install_requires=['cmarkgfm', 'python-frontmatter', 'jinja2', 'docopt'], entry_points={ 'console_scripts': ['nele = nele:main']