Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ __pycache__/
/nele.egg-info/
/build/
/dist/
/.direnv
27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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;
}
);
};
}
16 changes: 7 additions & 9 deletions nele/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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()

Expand All @@ -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)
Expand All @@ -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'))
Expand Down Expand Up @@ -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=' ')
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
py-gfm
cmarkgfm
python-frontmatter
jinja2
docopt
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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']
Expand Down
Loading