continue parser development
This commit is contained in:
parent
046b687017
commit
e2f249340c
|
@ -6,6 +6,8 @@ import re
|
|||
import os
|
||||
import logging
|
||||
|
||||
from slugify import slugify
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -39,15 +41,27 @@ def json_handler(obj):
|
|||
|
||||
class Article(object):
|
||||
|
||||
def __init__(self, path, content, publication_date):
|
||||
def __init__(self, path, content, publication_date=None):
|
||||
self.path = path
|
||||
self.content = content
|
||||
self.publication_date = publication_date
|
||||
|
||||
split_path = os.path.normpath(path).split(os.sep)
|
||||
|
||||
self.filename = split_path[-1:] # the last element
|
||||
self.publication_date = get_date_from_article_filename(self.filename)
|
||||
self.slug = slugify(self.filename)
|
||||
|
||||
try:
|
||||
self.category = split_path[1] #
|
||||
self.keywords = split_path[2:-1]
|
||||
except IndexError:
|
||||
self.category = ''
|
||||
self.keywords = []
|
||||
|
||||
try:
|
||||
self.title = content.splitlines()[0]
|
||||
except IndexError:
|
||||
self.title = "{Title unknown}"
|
||||
self.title = self.filename
|
||||
|
||||
def __str__(self):
|
||||
"""Returns the title and the publication date of the article."""
|
||||
|
@ -96,6 +110,8 @@ class Site(object):
|
|||
def build_article(self, filepath, filename):
|
||||
"""Build a new article from an existing file.
|
||||
|
||||
The newly built article is added to the property `self.articles`.
|
||||
|
||||
Args:
|
||||
root_path (str): the path where the file is stored.
|
||||
filename (str): the filename of the file.
|
||||
|
@ -116,6 +132,13 @@ class Site(object):
|
|||
|
||||
logger.warn('article found in %s: %s', article.category, article)
|
||||
|
||||
self.articles.append(article)
|
||||
|
||||
if article.category not in self.categories:
|
||||
self.categories[article.category] = []
|
||||
|
||||
self.categories[article.category].append(article)
|
||||
|
||||
return article
|
||||
|
||||
def to_json(self):
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -3,4 +3,5 @@ pylint==2.1.1
|
|||
clize==4.0.3
|
||||
pytest==3.7.2
|
||||
pytest-cov==2.5.1
|
||||
jinja==2.10
|
||||
jinja==2.10
|
||||
python-slugify==1.2.5
|
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.3.1/css/foundation.min.css">
|
||||
<meta charset="utf-8">
|
||||
<title>Cryptocurrency Pricing Application</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container" id="app">
|
||||
<h3 class="text-center">Cryptocurrency Pricing</h3>
|
||||
<div class="columns medium-4" v-for="(result, index) in results">
|
||||
<div class="card">
|
||||
<div class="card-section">
|
||||
<p> {{ index }} </p>
|
||||
</div>
|
||||
<div class="card-divider">
|
||||
<p>$ {{ result.USD }}</p>
|
||||
</div>
|
||||
<div class="card-section">
|
||||
<p> € {{ result.EUR }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://unpkg.com/vue"></script>
|
||||
<script src="vueApp.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,16 @@
|
|||
const vm = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
results: {
|
||||
"BTC": {
|
||||
"USD":3759.91,
|
||||
"EUR":3166.21
|
||||
},
|
||||
"ETH": {
|
||||
"USD":281.7,
|
||||
"EUR":236.25
|
||||
},
|
||||
"NEW Currency":{"USD":5.60,"EUR":4.70}
|
||||
}
|
||||
}
|
||||
});
|
|
@ -13,7 +13,32 @@ def test_article_match_date():
|
|||
assert get_date_from_article_filename('2017-02-30-divinity-origin-sin.md') == None
|
||||
assert get_date_from_article_filename('lynis.md') == None
|
||||
|
||||
|
||||
def test_article_slug():
|
||||
"""Check the article slug is well built."""
|
||||
|
||||
assert "scaleway-review" == Article('articles/sys/2018-01-01 Scaleway Review.md', '').slug
|
||||
|
||||
|
||||
def test_article_category():
|
||||
"""Asserts that the category of an article is found, based on the filepath."""
|
||||
|
||||
assert "home" == Article('articles/home', "", date(2018, 1, 1))
|
||||
assert "home" == Article('articles/home/2019-01-01-blabla.md', "").category
|
||||
|
||||
assert "dev" == Article('articles/dev/python/django/2019-01-01-blabla.md', "").category
|
||||
|
||||
assert '' == Article('articles', "").category
|
||||
|
||||
|
||||
def test_article_keywords():
|
||||
"""Asserts that the keywords of an article are found, based on the filepath."""
|
||||
|
||||
article = Article('articles/dev/python/django/2019-01-01-blabla.md', "")
|
||||
|
||||
assert "python" in article.keywords
|
||||
assert "django" in article.keywords
|
||||
assert "dev" not in article.keywords
|
||||
|
||||
article = Article('articles/dev/2019-01-01-blabla.md', "")
|
||||
|
||||
assert len(article.keywords) == 0
|
||||
|
|
Loading…
Reference in New Issue