From 2c3850c38b0e2c75fb1fc7023563ab3d9a6a357b Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Thu, 11 Jan 2018 11:30:15 +0800 Subject: + init --- all.rss.xml | 18 ++++++++++++++++ blog.iml | 9 -------- rss.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 all.rss.xml delete mode 100644 blog.iml create mode 100644 rss.py diff --git a/all.rss.xml b/all.rss.xml new file mode 100644 index 0000000..cafc7fd --- /dev/null +++ b/all.rss.xml @@ -0,0 +1,18 @@ + + + + {{ site.name }} + {{ site.url }} + {{ site.tagline }} + + {% for post in posts[:20] %} + + {{ post.title | e }} + {{ post.body | e }} + {{ post.date_rss }} + {{ site.url }}/{{ post.permalink }} + {{ site.url }}/{{ post.permalink }} + + {% endfor %} + + diff --git a/blog.iml b/blog.iml deleted file mode 100644 index ad3c0a3..0000000 --- a/blog.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/rss.py b/rss.py new file mode 100644 index 0000000..fbf70d1 --- /dev/null +++ b/rss.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Created by i@BlahGeek.com at 2015-07-30 + +import os +import argparse +import yaml + +import jinja2 + + +class FilePathLoader(jinja2.BaseLoader): + """ Custom Jinja2 template loader which just loads a single template file """ + + def __init__(self, cwd): + self.cwd = cwd + + def get_source(self, environment, template): + # Path + filename = os.path.join(self.cwd, template) + + # Read + try: + with open(filename, 'r') as f: + contents = f.read() + except IOError: + raise jinja2.TemplateNotFound(filename) + + # Finish + uptodate = lambda: False + return contents, filename, uptodate + + +def render_template(cwd, template_path, context): + env = jinja2.Environment(loader=FilePathLoader(cwd)) + + return env \ + .get_template(template_path) \ + .render(context) + + +def main(): + parser = argparse.ArgumentParser() + + parser.add_argument('--dir', default='.', help='Template directory') + parser.add_argument('--data', nargs='*', help='One or more YAML data file') + parser.add_argument('--template', help='Template file to process') + parser.add_argument('--body', help='Body content') + args = parser.parse_args() + + context = dict() + for data_f in args.data if args.data else []: + key, filename = data_f.split(':') + if filename: + context[key] = yaml.load(open(filename).read()) + else: + context[key] = {'_': True} + if args.body: + context['body'] = open(args.body).read() + + return render_template( + args.dir, + args.template, + context + ) + +if __name__ == '__main__': + print(main()) -- cgit v1.2.3 From 78760ab08d1d2ca51004934ac8ff690be38fd7ce Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Thu, 11 Jan 2018 16:59:47 +0800 Subject: + fix --- _posts/2017/12/movies.rst | 76 +++++++++++++++++++++++++++++++++++++++++++++++ _posts/2017/movies.rst | 74 --------------------------------------------- rss.py | 73 +++++++++++++++++++++++---------------------- 3 files changed, 113 insertions(+), 110 deletions(-) create mode 100644 _posts/2017/12/movies.rst delete mode 100644 _posts/2017/movies.rst diff --git a/_posts/2017/12/movies.rst b/_posts/2017/12/movies.rst new file mode 100644 index 0000000..94ecee5 --- /dev/null +++ b/_posts/2017/12/movies.rst @@ -0,0 +1,76 @@ +:orphan: + +.. _2017movie: + + +2017观影记录 +=================== + +:Publish Date: 2010-01-01 + +2017年马上就结束了。掐指一算,2017年看了好多电影。包括线上和线下电影院的。 + +线下电影院观影记录(按时间顺序,以中国大陆上映时的片名为准): + +- `星球大战外传:侠盗一号 `__ (Rogue One: A Star Wars Story) +- `太空旅客 `__ (Passengers) +- `降临 `__ (Arrival) +- `极限特工:终极回归 `__ (xXx: The Return of Xander Cage) +- `生化危机6:终章 `__ (Resident Evil: The Final Chapter) +- `金刚狼3:殊死一战 `__ (Logan) +- `攻壳机动队 `__ (Ghost in the Shell) +- `速度与激情8 `__ (The Fate of the Furious) +- `拆弹专家 `__ +- `大护法 `__ +- `战狼2 `__ +- `星际特工:千星之城 `__ (Valérian et la Cité des mille planètes) +- `看不见的客人 `__ (Contratiempo) +- `英伦对决 `__ (The Foreigner) +- `天才枪手 `__ (ฉลาดเกมส์โกง) +- `王牌特工2:黄金圈 `__ (Kingsman: The Golden Circle) +- `全球风暴 `__ (Geostorm) +- `东方快车谋杀案 `__ (Murder on the Orient Express) +- `雷神3:诸神黄昏 `__ (Thor: Ragnarok) +- `追捕 `__ +- `至暗时刻 `__ (Darkest Hour) +- `寻梦环游记 `__ (Coco) +- `至爱梵高·星空之谜 `__ (Loving Vincent) +- `芳华 `__ + +线上观影记录(包括BT下载以及Netflix,包括电影/纪录片/部分美剧,不完全): + +- `Blade Runner `__ (1982) +- `Blade Runner 2049 `__ +- `Love Actually `__ +- `World War Z `__ +- `Dunkirk `__ +- `Everst `__ +- `霸王别姬 `__ +- `Titanic `__ +- `隧道 `__ (터널) +- `London Has Fallen `__ +- `出租车司机 `__ (택시운전사) +- `Ocean's Eleven `__ +- `Ocean's Twelve `__ +- `Shooter `__ +- `Knight Day `__ +- `2001: A Space Odyssey `__ +- `Minority Report `__ +- `Deep Impact `__ +- `Area 51 `__ +- `San Andreas `__ +- `I, Origin `__ +- `Particle Fever `__ +- `City 40 `__ +- `Stranger Things `__ +- `House Of Cards `__, Season 1 + +现在回忆一下,很多电影的质量其实很一般,属于看完之后走出电影院差不多就能忘记剧情的那种。这种电影很多都是所谓的「商业大片」,追求特效和画面,完全不考虑剧情的质量和观众的观影感受。 + +简单分析了一下,线下观影的统计 + +.. image:: ../../../_static/img/2017movie.png + :alt: 2017movie + :align: center + +6月居然一部都没看,是因为工作太饱和了还是因为没有好看的电影呢? \ No newline at end of file diff --git a/_posts/2017/movies.rst b/_posts/2017/movies.rst deleted file mode 100644 index 10fcbc3..0000000 --- a/_posts/2017/movies.rst +++ /dev/null @@ -1,74 +0,0 @@ -:orphan: - -.. _2017movie: - -2017观影记录 -=================== - - -2017年马上就结束了。掐指一算,2017年看了好多电影。包括线上和线下电影院的。 - -线下电影院观影记录(按时间顺序,以中国大陆上映时的片名为准): - -- `星球大战外传:侠盗一号 `__ (Rogue One: A Star Wars Story) -- `太空旅客 `__ (Passengers) -- `降临 `__ (Arrival) -- `极限特工:终极回归 `__ (xXx: The Return of Xander Cage) -- `生化危机6:终章 `__ (Resident Evil: The Final Chapter) -- `金刚狼3:殊死一战 `__ (Logan) -- `攻壳机动队 `__ (Ghost in the Shell) -- `速度与激情8 `__ (The Fate of the Furious) -- `拆弹专家 `__ -- `大护法 `__ -- `战狼2 `__ -- `星际特工:千星之城 `__ (Valérian et la Cité des mille planètes) -- `看不见的客人 `__ (Contratiempo) -- `英伦对决 `__ (The Foreigner) -- `天才枪手 `__ (ฉลาดเกมส์โกง) -- `王牌特工2:黄金圈 `__ (Kingsman: The Golden Circle) -- `全球风暴 `__ (Geostorm) -- `东方快车谋杀案 `__ (Murder on the Orient Express) -- `雷神3:诸神黄昏 `__ (Thor: Ragnarok) -- `追捕 `__ -- `至暗时刻 `__ (Darkest Hour) -- `寻梦环游记 `__ (Coco) -- `至爱梵高·星空之谜 `__ (Loving Vincent) -- `芳华 `__ - -线上观影记录(包括BT下载以及Netflix,包括电影/纪录片/部分美剧,不完全): - -- `Blade Runner `__ (1982) -- `Blade Runner 2049 `__ -- `Love Actually `__ -- `World War Z `__ -- `Dunkirk `__ -- `Everst `__ -- `霸王别姬 `__ -- `Titanic `__ -- `隧道 `__ (터널) -- `London Has Fallen `__ -- `出租车司机 `__ (택시운전사) -- `Ocean's Eleven `__ -- `Ocean's Twelve `__ -- `Shooter `__ -- `Knight Day `__ -- `2001: A Space Odyssey `__ -- `Minority Report `__ -- `Deep Impact `__ -- `Area 51 `__ -- `San Andreas `__ -- `I, Origin `__ -- `Particle Fever `__ -- `City 40 `__ -- `Stranger Things `__ -- `House Of Cards `__, Season 1 - -现在回忆一下,很多电影的质量其实很一般,属于看完之后走出电影院差不多就能忘记剧情的那种。这种电影很多都是所谓的「商业大片」,追求特效和画面,完全不考虑剧情的质量和观众的观影感受。 - -简单分析了一下,线下观影的统计 - -.. image:: ../../_static/img/2017movie.png - :alt: 2017movie - :align: center - -6月居然一部都没看,是因为工作太饱和了还是因为没有好看的电影呢? \ No newline at end of file diff --git a/rss.py b/rss.py index fbf70d1..faa004c 100644 --- a/rss.py +++ b/rss.py @@ -1,68 +1,69 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Created by i@BlahGeek.com at 2015-07-30 - import os -import argparse -import yaml - import jinja2 +import glob +from bs4 import BeautifulSoup -class FilePathLoader(jinja2.BaseLoader): - """ Custom Jinja2 template loader which just loads a single template file """ +class FilePathLoader(jinja2.BaseLoader): def __init__(self, cwd): self.cwd = cwd def get_source(self, environment, template): - # Path filename = os.path.join(self.cwd, template) - # Read try: with open(filename, 'r') as f: contents = f.read() except IOError: raise jinja2.TemplateNotFound(filename) - # Finish - uptodate = lambda: False - return contents, filename, uptodate + return contents, filename, lambda: False def render_template(cwd, template_path, context): env = jinja2.Environment(loader=FilePathLoader(cwd)) + return env.get_template(template_path).render(context) - return env \ - .get_template(template_path) \ - .render(context) + +def _remove_attrs(soup): + for tag in soup.findAll(True): + tag.attrs = None + return soup def main(): - parser = argparse.ArgumentParser() - - parser.add_argument('--dir', default='.', help='Template directory') - parser.add_argument('--data', nargs='*', help='One or more YAML data file') - parser.add_argument('--template', help='Template file to process') - parser.add_argument('--body', help='Body content') - args = parser.parse_args() - - context = dict() - for data_f in args.data if args.data else []: - key, filename = data_f.split(':') - if filename: - context[key] = yaml.load(open(filename).read()) - else: - context[key] = {'_': True} - if args.body: - context['body'] = open(args.body).read() + + filenames = glob.glob("./_build/html/_posts/*/*/*.html") + print(filenames) + + posts = [] + + for p in filenames: + soup = BeautifulSoup(open(p), "html5lib") + body = soup.find_all("div", class_="body") + posts.append({ + "title": soup.title.string, + "body": body[0].text, + "date_rss": "", + "permalink": "/".join(p.split("/")[3:]) + }) + + context = { + "site": { + "name": "Hello World", + "url": "https://blog.jinwei.me", + "tagline": "Freedom is my birthright and I shall have it." + }, + "posts": posts + } return render_template( - args.dir, - args.template, + ".", + "all.rss.xml", context ) + if __name__ == '__main__': print(main()) -- cgit v1.2.3 From 866436c73338c2d0caa0cb35dff4949048943fee Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Thu, 11 Jan 2018 20:54:06 +0800 Subject: + add rss --- Dockerfile | 2 +- Makefile | 5 ++- _posts/2017/12/movies.rst | 2 +- rss.py | 15 +++----- rss.xml | 94 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 13 deletions(-) create mode 100644 rss.xml diff --git a/Dockerfile b/Dockerfile index be6aae8..9560268 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ ADD . /app WORKDIR /app -RUN /bin/bash -c "source /app/.venv/bin/activate && make html" +RUN /bin/bash -c "source /app/.venv/bin/activate && make html && make rss" FROM alpine:latest diff --git a/Makefile b/Makefile index 6a109aa..223cadf 100644 --- a/Makefile +++ b/Makefile @@ -12,9 +12,12 @@ BUILDDIR = _build help: @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) +rss: + python rss.py > rss.xml + .PHONY: help Makefile # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/_posts/2017/12/movies.rst b/_posts/2017/12/movies.rst index 94ecee5..6be761d 100644 --- a/_posts/2017/12/movies.rst +++ b/_posts/2017/12/movies.rst @@ -6,7 +6,7 @@ 2017观影记录 =================== -:Publish Date: 2010-01-01 +:Publish Date: 2017-12-30 2017年马上就结束了。掐指一算,2017年看了好多电影。包括线上和线下电影院的。 diff --git a/rss.py b/rss.py index faa004c..fdf4b53 100644 --- a/rss.py +++ b/rss.py @@ -26,12 +26,6 @@ def render_template(cwd, template_path, context): return env.get_template(template_path).render(context) -def _remove_attrs(soup): - for tag in soup.findAll(True): - tag.attrs = None - return soup - - def main(): filenames = glob.glob("./_build/html/_posts/*/*/*.html") @@ -41,11 +35,12 @@ def main(): for p in filenames: soup = BeautifulSoup(open(p), "html5lib") - body = soup.find_all("div", class_="body") + body = soup.find_all("div", class_="body")[0].text + posts.append({ "title": soup.title.string, - "body": body[0].text, - "date_rss": "", + "body": body, + "date_rss": body[body.find("Publish Date:")+13:body.find("Publish Date:")+23], "permalink": "/".join(p.split("/")[3:]) }) @@ -53,7 +48,7 @@ def main(): "site": { "name": "Hello World", "url": "https://blog.jinwei.me", - "tagline": "Freedom is my birthright and I shall have it." + "tagline": "Freedom is my birth right and I shall have it." }, "posts": posts } diff --git a/rss.xml b/rss.xml new file mode 100644 index 0000000..6e8bbcd --- /dev/null +++ b/rss.xml @@ -0,0 +1,94 @@ +['./_build/html/_posts/2017/12/movies.html'] + + + + Hello World + https://blog.jinwei.me + Freedom is my birth right and I shall have it. + + + + 2017观影记录 — Hello World + + + +2017观影记录¶ + + + + +Publish Date:2010-01-01 + + + +2017年马上就结束了。掐指一算,2017年看了好多电影。包括线上和线下电影院的。 +线下电影院观影记录(按时间顺序,以中国大陆上映时的片名为准): + +星球大战外传:侠盗一号 (Rogue One: A Star Wars Story) +太空旅客 (Passengers) +降临 (Arrival) +极限特工:终极回归 (xXx: The Return of Xander Cage) +生化危机6:终章 (Resident Evil: The Final Chapter) +金刚狼3:殊死一战 (Logan) +攻壳机动队 (Ghost in the Shell) +速度与激情8 (The Fate of the Furious) +拆弹专家 +大护法 +战狼2 +星际特工:千星之城 (Valérian et la Cité des mille planètes) +看不见的客人 (Contratiempo) +英伦对决 (The Foreigner) +天才枪手 (ฉลาดเกมส์โกง) +王牌特工2:黄金圈 (Kingsman: The Golden Circle) +全球风暴 (Geostorm) +东方快车谋杀案 (Murder on the Orient Express) +雷神3:诸神黄昏 (Thor: Ragnarok) +追捕 +至暗时刻 (Darkest Hour) +寻梦环游记 (Coco) +至爱梵高·星空之谜 (Loving Vincent) +芳华 + +线上观影记录(包括BT下载以及Netflix,包括电影/纪录片/部分美剧,不完全): + +Blade Runner (1982) +Blade Runner 2049 +Love Actually +World War Z +Dunkirk +Everst +霸王别姬 +Titanic +隧道 (터널) +London Has Fallen +出租车司机 (택시운전사) +Ocean’s Eleven +Ocean’s Twelve +Shooter +Knight Day +2001: A Space Odyssey +Minority Report +Deep Impact +Area 51 +San Andreas +I, Origin +Particle Fever +City 40 +Stranger Things +House Of Cards, Season 1 + +现在回忆一下,很多电影的质量其实很一般,属于看完之后走出电影院差不多就能忘记剧情的那种。这种电影很多都是所谓的「商业大片」,追求特效和画面,完全不考虑剧情的质量和观众的观影感受。 +简单分析了一下,线下观影的统计 + +6月居然一部都没看,是因为工作太饱和了还是因为没有好看的电影呢? + + + + + 2010-01-01 + https://blog.jinwei.me/_posts/2017/12/movies.html + https://blog.jinwei.me/_posts/2017/12/movies.html + + + + -- cgit v1.2.3