Skip to content

Klimets Artyom #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5ef7237
Realize most functions without using OOP(first iteration without json)
Zavxoz Nov 10, 2019
3eb31f1
small rethinking of the project structure (using __main__.py and the …
Zavxoz Nov 17, 2019
5074bb9
utility wrapped into distribution package(iteration 2)
Zavxoz Nov 17, 2019
3fd793f
small changes in architecture of the application (update of __main__.py)
Zavxoz Nov 17, 2019
aa4f182
adding installing required packages into setup.py
Zavxoz Nov 17, 2019
ae0466a
add sqlalchemy to support caching in app
Zavxoz Nov 17, 2019
621e934
finish work with adding information into database
Zavxoz Nov 17, 2019
a00ecba
add some functionality for print news
Zavxoz Nov 17, 2019
8d2b64b
Add classes to work with json format
Zavxoz Nov 18, 2019
6753bfe
adding check for news in the database
Zavxoz Nov 21, 2019
f9f4e79
adding getting and printing cached news by date(iteration 3)
Zavxoz Nov 21, 2019
5a5e5e5
change the method of determining the news that will be printed(gettin…
Zavxoz Nov 22, 2019
1d67d20
use context manager to use sqlalchemy session
Zavxoz Nov 22, 2019
fb2a223
added classes for converters and some little changes in rss_reader.py
Zavxoz Nov 22, 2019
d5d590d
commit for checking how system work on clean machine(docker container)
Zavxoz Nov 26, 2019
e624dba
commit for checking how system work on clean machine(docker container)
Zavxoz Nov 26, 2019
77dc6d2
Merge branch 'final_task' of https://github.com/Zavxoz/PythonHomework…
Zavxoz Nov 26, 2019
853640a
changed news storage database to cimplify application deployment
Zavxoz Nov 26, 2019
fcc72d0
upgrading validation of arguments
Zavxoz Nov 27, 2019
c4df599
fix working with sqlalchemy after previous changes with checking of a…
Zavxoz Nov 27, 2019
743ba9c
some changes after first review
Zavxoz Nov 27, 2019
c091803
fix serialization into JSON format
Zavxoz Nov 27, 2019
5070317
adding methods to initialization directories where files in pdf or ht…
Zavxoz Nov 28, 2019
7f9fd83
adding first version of html converter
Zavxoz Nov 29, 2019
e39ede7
adding first version of html converter
Zavxoz Nov 29, 2019
a5949b4
Merge branch 'final_task' of https://github.com/Zavxoz/PythonHomework…
Zavxoz Nov 29, 2019
daf1d30
pdf converter created
Zavxoz Nov 30, 2019
231fd00
all features are finished
Zavxoz Nov 30, 2019
093b223
Codestyle was checked
Zavxoz Nov 30, 2019
3d8202b
Adding docstrings
Zavxoz Nov 30, 2019
31d48e5
adding unittests and some fixes after second review
Zavxoz Dec 1, 2019
73e8160
Update requirements.txt
Zavxoz Dec 1, 2019
de87465
Revert "Update requirements.txt"
Zavxoz Dec 1, 2019
7d802e9
Update requirements.txt
Zavxoz Dec 1, 2019
8e43e9c
Revert "Update requirements.txt"
Zavxoz Dec 1, 2019
e6115d5
Update requirements.txt
Zavxoz Dec 1, 2019
2a7d9e7
Update tests directory
Zavxoz Dec 1, 2019
c5d042b
Update tests
Zavxoz Dec 1, 2019
19c4d12
Add readme and json schema
Zavxoz Dec 1, 2019
efa2c82
font file was replaced to package directory and fix path to this file…
Zavxoz Dec 7, 2019
fe4efab
little bugfix
Zavxoz Dec 8, 2019
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 MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include rss_reader/times-new-roman.ttf
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Command-line RSS reader

Final task for the Introduction to Python Epam courses.

* [Code coverage](Test_coverage.png) -- Code coverage percentage with tests
* [Json schema](json_schema.json) -- Scheme of JSON structure
Binary file added Test_coverage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions json_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"News": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"Feed#": {
"type": "object",
"title": "Feed",
"properties": {
"Feed source": {
"type": "string",
"title": "Source ",
"description": "Source where the news came from"
},
"Title": {
"type": "string",
"title": "Title",
"description": "Title of the feed"
},
"Date": {
"type": "string",
"title": "Publication date",
"description": "Date when the news was published"
},
"Link": {
"type": "string",
"title": "Link",
"description": "News link"
},
"Description": {
"type": "string",
"title": "Description",
"description": "A description of the feed"
},
"Media_content": {
"type": "array",
"title": "Image links",
"description": "Array of image links",
"items": [
{
"type": "string"
"title": "URL",
"description": "URL of image"
}
]
}
},
"required": [
"Feed source",
"Title",
"Date",
"Link",
"Description",
"Media_content"
]
}
},
"required": [
"Feed0"
]
}
]
}
},
"required": [
"News"
]
}
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
beautifulsoup4>=4.8.0
validator_collection>=1.3.7
sqlalchemy>=1.2.7
feedparser>=5.2.1
fpdf>=1.7.2
httplib2>=0.14.0
Pillow>=6.2.1
2 changes: 2 additions & 0 deletions rss_reader/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'''Package implements command-line RSS reader with some advanced features'''
__version__ = '1.4'
3 changes: 3 additions & 0 deletions rss_reader/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'''Module contain entry point to the package'''
from .cli import main
main()
98 changes: 98 additions & 0 deletions rss_reader/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
'''Module implements a CLI of the application'''
import logging
from argparse import ArgumentParser
from datetime import datetime
from os import path, makedirs
from validator_collection.checkers import is_url
from .rssreader import RSSReader
from collections import defaultdict


def main():
'''Entry point of the app'''
parser = adding_arguments()
args = parser.parse_args()
init_logging(args.verbose)
source, date = validate_arguments(args)
configuration_for_conversion = mk_config_for_conversion(args.to_pdf, args.to_html)
rss = RSSReader(source, args.limit, date, args.json, configuration_for_conversion, args.all)
rss.exec()


def adding_arguments():
'''Function initializes arguments of the RSS Reader'''
parser = ArgumentParser(description='Pure Python command-line RSS reader')
parser.add_argument('source', metavar='source', type=str, help='RSS URL')
parser.add_argument('--version', action='version', version='ver 1.4', help='Print version info')
parser.add_argument('--limit', metavar='LIMIT', type=int, help='Amount of news output')
parser.add_argument('--verbose', action='store_true', help='Print all logs in stdout')
parser.add_argument('--json', action='store_true', help='Print news in json format')
parser.add_argument('--date', type=str, help='Print news published on a given day')
parser.add_argument('--to-pdf', type=str, help='Conversion news to the PDF format')
parser.add_argument('--to-html', type=str, help='Conversion news to the HTML format')
parser.add_argument('--all', action='store_true', help='Getting all cached news.\
Compatible with the following arguments: --verbose, --json, --to-pdf, --to-html')
return parser


def init_logging(verbose):
'''Logging initialization'''
if verbose:
logging.basicConfig(format='%(module)s %(asctime)s %(message)s',
datefmt='%I:%M:%S', level=logging.INFO)


def validate_arguments(args):
'''Function validates of all received arguments'''
source = validate_url(args.source)
date = None
if args.date:
date = validate_date(args.date)
if args.to_html:
validate_path(args.to_html)
if args.to_pdf:
validate_path(args.to_pdf)
return source, date


def validate_url(source):
'''Function validates the URL that is the source of the news'''
logging.info('URL validation')
if not is_url(source):
raise ValueError('Invalid url')
return source


def validate_date(date):
'''Function validates date'''
logging.info('Date validation')
try:
checked_date = datetime.strptime(date, '%Y%m%d').date()
return checked_date
except ValueError as e:
print('Wrong date')


def validate_path(dir_for_save):
'''Function validates the path where the exported file will be saved'''
if path.exists(dir_for_save):
logging.info(f'Directory {dir_for_save} already exists')
else:
makedirs(dir_for_save)
logging.info(f'Create directory {dir_for_save} for saving file')
return dir_for_save


def mk_config_for_conversion(pdf, html):
'''Function creates a dictionary which contain which type of files and where news will be saved'''
logging.info('Making dict with configuration of conversion')
dict_with_directories = defaultdict(str)
if pdf:
dict_with_directories['pdf'] = pdf
if html:
dict_with_directories['html'] = html
return dict_with_directories


if __name__ == "__main__":
main()
Loading