Skip to content

Commit

Permalink
adapt to python3
Browse files Browse the repository at this point in the history
  • Loading branch information
cou929 committed Nov 24, 2013
1 parent e35df9e commit ffbe743
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion rug/articles.py
Expand Up @@ -46,7 +46,7 @@ def _list_articles(self, filepath):
def _extract_metadata(self, filepath):
header = ''
with open(filepath, 'r') as f:
header = f.readline().decode('utf-8')
header = f.readline()
(title, tags) = self._parse_header(header)
(mode, ino, dev, nlink, uid,
gid, size, atime, mtime, ctime) = os.stat(filepath)
Expand Down
30 changes: 15 additions & 15 deletions rug/view.py
Expand Up @@ -8,6 +8,7 @@

import os
import datetime
from functools import cmp_to_key
import markdown2
import pystache
import PyRSS2Gen
Expand All @@ -30,14 +31,14 @@ def _extract_articles(self):

def _render(self, articles):
for article in articles:
print article.title
print(article.title)


class IndivisualPage(Abstract):
def _extract_articles(self):
result = []
by_issued_date = lambda x, y: x['issued'] - y['issued']
sorted_list = sorted(self.articles, by_issued_date)
by_issued_date = cmp_to_key(lambda x, y: x['issued'] - y['issued'])
sorted_list = sorted(self.articles, key=by_issued_date)
list_length = len(sorted_list)

for i, article in enumerate(sorted_list):
Expand All @@ -58,14 +59,14 @@ def _extract_articles(self):
def _render(self, articles):
template_string = ''
with open(self.template['layout'], 'r') as f:
template_string = f.read().decode('utf-8')
template_string = f.read()
parsed = pystache.parse(template_string)

for article in articles:
markdown_string = ''
with open(article['path'], 'r') as f:
f.readline() # remove header
markdown_string = f.read().decode('utf-8')
markdown_string = f.read()
html = markdown2.markdown(markdown_string)
dt = datetime.datetime.fromtimestamp(article['issued'])
view_params = {
Expand All @@ -90,26 +91,25 @@ def _render(self, articles):
dest_path = os.path.join(self.output_path,
article['filename'] + '.html')
with open(dest_path, 'w') as f:
f.write(self.renderer.render(parsed, view_params)
.encode('utf-8'))
f.write(self.renderer.render(parsed, view_params))


class ArchivePage(Abstract):
html_filename = 'index.html'

def _extract_articles(self):
by_issued_date = lambda x, y: x['issued'] - y['issued']
result = sorted(self.articles, by_issued_date)
by_issued_date = cmp_to_key(lambda x, y: x['issued'] - y['issued'])
result = sorted(self.articles, key=by_issued_date)
result.reverse()
return result

def _render(self, articles):
template_string = ''
with open(self.template['content'], 'r') as f:
template_string = f.read().decode('utf-8')
template_string = f.read()
content_parsed = pystache.parse(template_string)
with open(self.template['layout'], 'r') as f:
template_string = f.read().decode('utf-8')
template_string = f.read()
layout_parsed = pystache.parse(template_string)

params = []
Expand All @@ -133,16 +133,16 @@ def _render(self, articles):

dest_path = os.path.join(self.output_path, self.html_filename)
with open(dest_path, 'w') as f:
f.write(self.renderer.render(layout_parsed, param).encode('utf-8'))
f.write(self.renderer.render(layout_parsed, param))


class RSS(Abstract):
rss_filename = 'rss.xml'
rss_itemnum = 10

def _extract_articles(self):
by_issued_date = lambda x, y: x['issued'] - y['issued']
result = sorted(self.articles, by_issued_date)
by_issued_date = cmp_to_key(lambda x, y: x['issued'] - y['issued'])
result = sorted(self.articles, key=by_issued_date)
result.reverse()
return result[:self.rss_itemnum]

Expand All @@ -154,7 +154,7 @@ def _render(self, articles):
markdown_string = ''
with open(article['path'], 'r') as f:
f.readline() # remove header
markdown_string = f.read().decode('utf-8')
markdown_string = f.read()
html = markdown2.markdown(markdown_string)
url = host + article['filename'] + '.html'
items.append(PyRSS2Gen.RSSItem(
Expand Down

0 comments on commit ffbe743

Please sign in to comment.