-
Notifications
You must be signed in to change notification settings - Fork 24
Kirill_Stepanishin_kirill.stpn.by@gmail.com #23
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
kirill-stp
wants to merge
18
commits into
epam-python-courses-7-bsu:master
Choose a base branch
from
kirill-stp:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
00b35d5
Iteration 1 without test
e70c840
Delete single_article.py
kirill-stp fe73959
Fixed some bugs, iteration 1 ready
3e1ae17
Fixed some bugs, iteration 1 ready
d1cd5a6
Fixed some bugs, iteration 1 ready
37a2f03
Fixein some bugs, iteration 1 ready
a20b444
Merge branch 'master' of https://github.com/kirill-stp/FinalTaskRssPa…
890744f
Iteration 1
dfe75ba
Iteration 2 and 3 implemented(without tests), resolved commented issu…
kirill-stp 5a9491d
deleted .tar.gz file, fixed database problems (i hope), now using fo…
kirill-stp 07871d0
Update README.md
kirill-stp d6156ed
Update README.md
kirill-stp 5003202
Iteration 4
kirill-stp ee7ddc5
Fixed some iteration 4 problems (font and images)
kirill-stp 9eaba80
iteration 5
kirill-stp 6d536ef
Fixed last commit problems
kirill-stp 61b6d86
Updated Readme.md, added more logging and comments
kirill-stp 030faee
Final version
kirill-stp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,63 @@ | ||
| # Your readme here | ||
| Some text. | ||
| Checkout how to write this file using *markdown*. | ||
| # Pyhton RSS reader | ||
|
|
||
| ## How to install: | ||
| **1st way** | ||
| * You need to have git installed. Run: | ||
| > $ git clone https://github.com/kirill-stp/FinalTaskRssParser.git | ||
| * when you are in your workspace folder. Then run: | ||
| > $ python setup.py install | ||
| * when you are in **final task** folder | ||
| **2nd way:** | ||
| * To install this package, you must have Python added to your user environment. | ||
| * Download the distribution archive | ||
| * run $ pip install ./python_rss_reader-1.0.tar.gz | ||
|
|
||
| ## Usage: | ||
| This app provide following interface: | ||
| ```shell | ||
| usage: rss_reader.py [-h] [--version] [--json] [--verbose] [--limit LIMIT] | ||
| [--date DATE] | ||
| source | ||
|
|
||
| Pure Python command-line RSS reader | ||
|
|
||
| positional arguments: | ||
| source RSS URL | ||
|
|
||
| optional arguments: | ||
| -h, --help show this help message and exit | ||
| --version Print version info | ||
| --json Print result as JSON in stdout | ||
| --verbose Outputs verbose | ||
| --limit LIMIT Limit news topics | ||
| --date DATE Read news from given date (YMD) | ||
| ``` | ||
| for example: | ||
| > $ python3 rss_reader.py https://news.yahoo.com/rss --date 20191120 --limit 2 --verbose --json | ||
|
|
||
| ## JSON structure: | ||
| ```shell | ||
| {'Article 1': {'date':time.struct_time, | ||
| 'images': {'image desription': 'url'}, | ||
| 'link': '', | ||
| 'summary': '', | ||
| 'title': ''}, | ||
| 'Article 2': {date': time.struct_time, | ||
| 'images': {'image desription': 'url'}, | ||
| 'link': '', | ||
| 'summary': '', | ||
| 'title': ''}, | ||
| 'Feed': 'Feeds from 'url'', | ||
| 'Link': 'rss link'} | ||
|
|
||
| ``` | ||
| ## Local news storage: | ||
| When **--date** argument is not provided, the news that you received will be saved to the database, if it wasn’t there yet. | ||
| Cached data stored in rss_reder/cached_feeds.db file using **shelve**. Database stores dictionary-like object, where the key is the publication date and the value is instance of **Article** class. | ||
|
|
||
| ## HTML and PDF converting: | ||
| You can use **--to-html** and **--to-pdf** to save feed in given format. If there is no internet connection, it will paste image links (clickable in pdf). If we have internet connection, then program will download images and paste it to the file. Titles in pdf also clickable. | ||
|
|
||
| ## Colorizing | ||
| This program can colorize normal and json output, using **termcolor**. To add some color to your life, use **--colorize** argument | ||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import argparse | ||
|
|
||
|
|
||
| def arguments(): | ||
| """create command line arguments""" | ||
|
|
||
| parser = argparse.ArgumentParser(description='Pure Python command-line RSS reader') | ||
| parser.add_argument('source', type=str, help='RSS URL') | ||
| parser.add_argument('--version', action='version', version='%(prog)s 1.0', help='Print version info') | ||
| parser.add_argument('--json', action='store_true', help='Print result as JSON in stdout') | ||
| parser.add_argument('--verbose', action='store_true', help='Outputs verbose') | ||
| parser.add_argument('--limit', type=int, help='Limit news topics') | ||
| parser.add_argument('--date', type=str, help='Read news from given date') | ||
| parser.add_argument('--to-html', action='store_true', help='Save feed in html format') | ||
| parser.add_argument('--to-pdf', action='store_true', help='Save feed in pdf format') | ||
| parser.add_argument('--colorize', action='store_true', help='Print result in colorize mode') | ||
| return parser.parse_args() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| from string_operations import * | ||
| import logging | ||
| import datetime | ||
| from termcolor import colored | ||
|
|
||
|
|
||
|
|
||
| class Article: | ||
| """single article class""" | ||
|
|
||
| def __init__(self, parsed, source): | ||
| """receive parsed article and extracts data from it""" | ||
| self.title = make_string_readable(parsed.title) | ||
| self.link = parsed.link | ||
| self.feed_link = source | ||
| self.published = extract_date(parsed) | ||
| summary_ = extract_topic_info_from_summary(parsed.summary) | ||
| self.summary = make_string_readable(summary_) | ||
| self.media = parsed.media_content | ||
|
|
||
| description_ = extract_image_info_from_summary(parsed.summary) | ||
| self.media_description = make_string_readable(description_) | ||
|
|
||
| def print_readable_article(self, is_colored): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is large which lowers readability. It is better to split it somehow into the smaller ones. |
||
| """print article to stdout in human-readable format""" | ||
| print( "_" * 79) | ||
| date = self.published | ||
| date_for_print = f'{date.tm_year}/{date.tm_mon}/{date.tm_mday}, {date.tm_hour}:{date.tm_min}:{date.tm_sec}\n' | ||
| if is_colored: | ||
| print(colored(date_for_print, 'red')) | ||
| else: | ||
| print(date_for_print) | ||
|
|
||
| cutted_title = cut_string_to_length_with_space(self.title, 77) | ||
| for str_number, string in enumerate(cutted_title): | ||
| if str_number + 1 == len(cutted_title): | ||
| if is_colored: | ||
| print(colored(string + '[1]', 'red')) | ||
| else: | ||
| print(string + '[1]') | ||
| else: | ||
| if is_colored: | ||
| print(colored(string, 'red')) | ||
| else: | ||
| print(string) | ||
|
|
||
| # images description and their links numbers (like [2] - [5]) | ||
| str_number_of_img = ' ' | ||
| if len(self.media) > 1: | ||
| str_number_of_img = f' - [{len(self.media) + 1}]' | ||
| images_and_link_numbers = f'\n\nImages:\n{self.media_description} [2] - {str_number_of_img}\n' | ||
| if is_colored: | ||
| print(colored(images_and_link_numbers, 'blue')) | ||
| else: | ||
| print(images_and_link_numbers) | ||
|
|
||
|
|
||
| cutted_summary = cut_string_to_length_with_space(self.summary, 79) | ||
| for string in cutted_summary: | ||
| if is_colored: | ||
| print(colored(string, 'cyan')) | ||
| else: | ||
| print(string) | ||
|
|
||
| # Links of article and images | ||
| if is_colored: | ||
| print(colored('\n\nLinks:\n[1]' + self.link, 'green')) | ||
| else: | ||
| print('\n\nLinks:\n[1]', self.link) | ||
| for number, img in enumerate(self.media): | ||
| if is_colored: | ||
| print(colored(f'[{number+2}] ' + img['url'], 'green')) | ||
| else: | ||
| print(f'[{number+2}]', img['url']) | ||
|
|
||
| print("_" * 79) | ||
|
|
||
| def make_article_json(self): | ||
| """convert article data in json format""" | ||
| json = { | ||
| 'images': {self.media_description: img['url'] for img in self.media}, | ||
| 'link': self.link, | ||
| 'summary': self.summary, | ||
| 'date': self.published, | ||
| 'title': self.title, | ||
| } | ||
| return json | ||
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import requests | ||
| import exceptions as ex | ||
|
|
||
|
|
||
| def internet_connection_check(): | ||
| url = 'http://www.google.com/' | ||
| timeout = 5 | ||
| is_internet = True | ||
| try: | ||
| requests.get(url, timeout=timeout) | ||
| except requests.ConnectionError: | ||
| is_internet = False | ||
| finally: | ||
| return is_internet |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| class InvalidURLAddress(Exception): | ||
| pass | ||
|
|
||
|
|
||
| class NoInternetConnection(Exception): | ||
| pass | ||
|
|
||
|
|
||
| class EmptyDataBase(Exception): | ||
| pass | ||
|
|
||
|
|
||
| class DateNotInDatabase(Exception): | ||
| pass | ||
|
|
||
| class PathError(Exception): | ||
| pass |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to not use wildcard import at all.