Skip to content

Commit

Permalink
Introduce 'home page' view
Browse files Browse the repository at this point in the history
  • Loading branch information
vyahello committed Apr 15, 2020
1 parent eaad54f commit 459e167
Show file tree
Hide file tree
Showing 19 changed files with 342 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ max-function-length = 30
statistics = True
count = True
eradicate-aggressive = True
ignore = I201
ignore = I100, I201
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ _**Note**: please take into account that it is built for demo purpose but not fo

## Usage

![Usage](usage.gif)
![Usage]()

### Quick start

Expand Down
2 changes: 1 addition & 1 deletion analyse-source-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ check-pylint() {
:<<DOC
Runs "pylint" code analyser
DOC
pretty-printer-box "pylint" && ( find ${PACKAGE} -type f -print0 -name "*.py" | xargs pylint )
pretty-printer-box "pylint" && ( find ${PACKAGE} -type f -name "*.py" | xargs pylint )
}


Expand Down
4 changes: 2 additions & 2 deletions article.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Module contains executable entrypoint for an app."""
"""Module contains executable entrypoint for an app (used for deployment e.g `heroku`)."""
# pylint:disable=unused-import
from article import app # noqa: F401
from article import application # noqa: F401
5 changes: 4 additions & 1 deletion article/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""Package contains a set of interfaces to operate `article` application."""
from flask import Flask
from .views import home

__author__: str = "Volodymyr Yahello"
__email__: str = "vyahello@gmail.com"
__version__: str = "0.0.0"

app = None
application: Flask = Flask(__name__)
application.register_blueprint(home.to_register)
8 changes: 4 additions & 4 deletions article/__main__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Represents executable entrypoint for `article` application."""
from article import application


def main() -> None:
def easyrun(host: str = "0.0.0.0", port: int = 5001, debug: bool = True) -> None:
"""Runs `article` application."""

pass
application.run(host, port, debug)


if __name__ == "__main__":
main()
easyrun()
133 changes: 133 additions & 0 deletions article/static/css/prism.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/* http://prismjs.com/download.html?themes=prism&languages=markup */
/**
* prism.js default theme for JavaScript, CSS and HTML
* Based on dabblet (http://dabblet.com)
* @author Lea Verou
*/

code[class*="language-"],
pre[class*="language-"] {
color: black;
text-shadow: 0 1px white;
font-family: Consolas, Monaco, 'Andale Mono', monospace;
direction: ltr;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
line-height: 1.5;

-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;

-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}

pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
text-shadow: none;
background: #b3d4fc;
}

pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
code[class*="language-"]::selection, code[class*="language-"] ::selection {
text-shadow: none;
background: #b3d4fc;
}

@media print {
code[class*="language-"],
pre[class*="language-"] {
text-shadow: none;
}
}

/* Code blocks */
pre[class*="language-"] {
padding: 1em;
margin: .5em 0;
overflow: auto;
}

:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: #f5f2f0;
}

/* Inline code */
:not(pre) > code[class*="language-"] {
padding: .1em;
border-radius: .3em;
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: slategray;
}

.token.punctuation {
color: #999;
}

.namespace {
opacity: .7;
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
color: #905;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
color: #690;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
color: #a67f59;
background: hsla(0, 0%, 100%, .5);
}

.token.atrule,
.token.attr-value,
.token.keyword {
color: #07a;
}

.token.function {
color: #DD4A68;
}

.token.regex,
.token.important,
.token.variable {
color: #e90;
}

.token.important {
font-weight: bold;
}

.token.entity {
cursor: help;
}

90 changes: 90 additions & 0 deletions article/static/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* Wide styles */
body {
font-family: 'Open Sans', Arial, sans-serif;
background: #fafafa;
font-weight: 300;
margin: 0;
padding: 0;
}

p {
padding-bottom: 30px;
}

img {
display: block;
margin-left: auto;
margin-right: auto;
max-width: 100% !important;
height: auto;
}

.btn, .btn-lg, .input-lg {
border-radius: 3px;
}

.form-control {
border-radius: 3px;
-webkit-box-shadow: none;
box-shadow: none;
border: 0;
}

.input-lg {
height: 50px;
}

.btn-lg, .btn-group-lg>.btn {
padding: 10px 28px;
height: 52px;
}

.btn-large {
font-size: 18px;
padding: 20px 50px;
margin: 5px 10px;
}

.btn-success {
background-color: rgba(108, 199, 108, 1.0);
background-image: none;
border: 0;
line-height: 1.8;
}

.btn-success:hover, .btn-success:focus, .btn-success:active {
background-color: rgba(94, 182, 94, 1.0);
color: #fff;
border: 0;
}

/* Specific styles */
.container.landing-page {
position: relative;
padding: 100px 15px;
text-align: center;
}

.container.article-page {
padding: 20px 15px 50px;
background-color: #fff;
color: rgba(0,0,0,0.8);
font-family: 'Lora', serif;
letter-spacing: 0.01rem;
font-weight: 400;
font-style: normal;
font-size: 15px;
line-height: 1.5;
}

.article {
padding-top: 30px;
}

tr td:first-child {
width: 15%;
}

tr td:last-child {
max-width: 700px;
}
13 changes: 13 additions & 0 deletions article/status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Contains interfaces to work with application statuses."""
from enum import Enum


class HttpStatus(Enum):
"""Represents http status code item."""

NOT_FOUND: int = 404

@property
def code(self) -> int:
"""Returns value of status code."""
return self.value
29 changes: 29 additions & 0 deletions article/templates/home/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends "shared/_layout.html" %}
{% block body %}
<div class="container landing-page">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h2>Newspaper Parser</h2>
</div>
</div>

<div class="row">
<div class="col-md-6 col-md-offset-3">
<form method=get>
<div class="form-group">
<div class="col-md-12">
<input class="form-control input-lg"
type="url"
name="url_to_clean"
placeholder="Paste the URL of an article">
</div>
<div class="col-md-12">
<br/>
<button class="btn btn-success btn-lg">Extract</button>
</div>
</div>
</form>
</div>
</div>
<div>
{% endblock %}
30 changes: 30 additions & 0 deletions article/templates/shared/_layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<title>Newspaper Parser</title>

<!-- External CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">

<!-- External Fonts -->
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300,600' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Lora:400,700' rel='stylesheet' type='text/css'>

<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

<!-- Site -->
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/style.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/prism.css') }}">
</head>
<body>
<section class="main">
{% block body %}{% endblock %}
</section>
</body>
</html>
1 change: 1 addition & 0 deletions article/views/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Package contains API for application views."""
18 changes: 18 additions & 0 deletions article/views/home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Contains API for home page views."""
from flask import Response, blueprints as bprint, render_template
from article.status import HttpStatus

to_register: bprint.Blueprint = bprint.Blueprint(name=__name__, import_name=__name__)


@to_register.route(rule="/")
@to_register.route(rule="/index")
def home() -> str:
"""Returns home page content."""
return render_template(template_name_or_list="home/index.html")


@to_register.errorhandler(code_or_exception=HttpStatus.NOT_FOUND.code)
def not_found() -> Response:
"""Returns page not found response."""
return Response(response="The page was not found", status=HttpStatus.NOT_FOUND.code)
3 changes: 1 addition & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ disallow_subclassing_any = False
disallow_any_generics = True
warn_unused_ignores = True
warn_unused_configs = True
show_column_numbers = True
strict = True
show_column_numbers = True
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ pytest-clarity==0.3.0a0
pytest-cov==2.8.1
pytest-mock==3.0.0
pytest-sugar==0.9.2
flask==1.1.2

0 comments on commit 459e167

Please sign in to comment.