-
Notifications
You must be signed in to change notification settings - Fork 32
Onishchouk Elia #21
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
el0ny
wants to merge
10
commits into
introduction-to-python-bsuir-2019:master
Choose a base branch
from
el0ny:final_task
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
Onishchouk Elia #21
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4df8dea
Initial commit. Added a simple RSS-reader functionality
el0ny 03f00f8
--json argument is working now
el0ny 27dcea6
--json now works as intedent. main() function divided into smaller fu…
el0ny 46014ec
--verbose atribute now prints log in console as well as --json
el0ny 019d68f
Polished according to pep8
el0ny a283958
Added requirements and json schema files. Now some exceptions are tra…
el0ny ee431b9
Now news can be cached and loaded using --date argument
el0ny c0b02b5
Prefinal commit. The program can convert news into fb2 and html forma…
el0ny 6040437
small bug with html encoding fixed
el0ny ca23266
final commit: colorization of cmd output was added and a few unittests
el0ny 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Elia Onishchouk | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
include requirements.txt |
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,31 @@ | ||
# Introduction to Python. Hometask | ||
|
||
RSS reader is a command-line utility which receives [RSS](wikipedia.org/wiki/RSS) URL and prints results in human-readable format. | ||
|
||
|
||
Utility provides the following interface: | ||
```shell | ||
usage: rss_reader.py [-h] [--version] [--json] [--verbose] [--limit LIMIT] | ||
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 status messages | ||
--limit LIMIT Limit news topics if this parameter provided | ||
|
||
``` | ||
|
||
With the argument `--json` the program converts the news into [JSON](https://en.wikipedia.org/wiki/JSON) format.(Still in progress) | ||
|
||
With the argument `--limit` the program prints given number of news. | ||
|
||
With the argument `--verbose` the program prints all logs in stdout.(Still in progress) | ||
|
||
Withe the argument `--version` the program prints in stdout it's current version and complete it's work. |
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,110 @@ | ||
import argparse | ||
import feedparser | ||
import html | ||
from bs4 import BeautifulSoup | ||
import json | ||
from tqdm import tqdm | ||
|
||
import version | ||
|
||
class Item: | ||
def __init__(self, title, date, link, description, links): | ||
self.title=title | ||
self.date=date | ||
self.link=link | ||
self.description=description | ||
self.links=links | ||
|
||
|
||
def main() -> None: | ||
el0ny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 v'+version.__version__, 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 status messages') | ||
parser.add_argument('--limit', type=int, default=-1, help='Limit news topics if this parameter provided') | ||
args = parser.parse_args() | ||
NewsFeed = feedparser.parse(args.source) | ||
if args.limit==-1 : | ||
args.limit=len(NewsFeed.entries) | ||
|
||
|
||
d=json.dumps([{"title": "title1","description": "description1","link": "link2","pubDate": "pubDate1","source": {"url1": "url1","__url2": "url2"}}, {"title": "title2","description": "description2","link": "link2","pubDate": "pubDate2","source": {"url1": "url1","__url2": "url2"}}]) | ||
el0ny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
open("out.json","w").write(d) | ||
for i in range(args.limit) : | ||
|
||
entry = NewsFeed.entries[i] | ||
soup = html.unescape(BeautifulSoup(entry['summary'], "html.parser")) | ||
|
||
print ('Title: {0}'.format(html.unescape(entry['title']))) | ||
print ('Date: {0}'.format(entry['published'])) | ||
print ('Link: {0}'.format(entry['link'])) | ||
print () | ||
|
||
j=1 | ||
el0ny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
images_links=[] | ||
for img in soup.findAll('img') : | ||
|
||
if 'alt' in img.attrs: | ||
alt=img['alt'] | ||
if alt!='': | ||
final=' [image {0} | {1}] '.format(j,alt) | ||
else: | ||
final=' [image {0}]'.format(j) | ||
|
||
else: | ||
final=' [image {0}]'.format(j) | ||
src=img['src'] | ||
images_links.append('[{0}]: {1}'.format(j, src)) | ||
j+=1 | ||
|
||
soup.find('img').replace_with(final) | ||
j=1 | ||
href_links=[] | ||
for href in soup.findAll('a'): | ||
if 'href' in href.attrs: | ||
link=href['href'] | ||
if href.text!='': | ||
final=' [link {0} | {1}] '.format(j,href.text) | ||
else: | ||
final=' [link {0}] '.format(j) | ||
soup.find('a').replace_with(final) | ||
href_links.append('[{0}]: {1}'.format(j, link)) | ||
j+=1 | ||
j=1 | ||
video_links=[] | ||
for video in soup.findAll('iframe'): | ||
if 'src' in video.attrs: | ||
link=video['src'] | ||
final=' [video {0}] '.format(j) | ||
soup.find('iframe').replace_with(final) | ||
video_links.append('[{0}]: {1}'.format(j, link)) | ||
j+=1 | ||
links={'images_links':images_links,'href_links':href_links,'video_links':video_links} | ||
item=Item(html.unescape(entry['title']),entry['published'],entry['link'],soup.text,links) | ||
print(soup.text) | ||
print () | ||
print () | ||
if href_links: | ||
print ('Links:') | ||
for link in href_links: | ||
print (link) | ||
if images_links: | ||
print () | ||
print ('Images:') | ||
for link in images_links: | ||
print (link) | ||
|
||
if video_links: | ||
print () | ||
print ('Videos:') | ||
for link in video_links: | ||
print (link) | ||
print () | ||
print () | ||
print () | ||
|
||
if __name__ == '__main__': | ||
|
||
main() |
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 @@ | ||
__version__="0.8" |
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,33 @@ | ||
import setuptools | ||
from rss_reader import version | ||
|
||
with open("README.md", "r") as fh: | ||
long_description = fh.read() | ||
|
||
setuptools.setup( | ||
name="rss-reader", | ||
version=version.__version__, | ||
author="Elia Onishchouk", | ||
author_email="elias0n@mail.ru", | ||
description="A simple command-line RSS reader", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
url="https://github.com/el0ny/PythonHomework", | ||
packages=setuptools.find_packages(), | ||
classifiers=[ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
], | ||
entry_points={ | ||
|
||
'console_scripts': [ | ||
|
||
'rss_reader = rss_reader.rss_reader:main', | ||
|
||
], | ||
|
||
}, | ||
install_requires=['feedparser', 'bs4'], | ||
python_requires='>=3.6', | ||
) |
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.
Uh oh!
There was an error while loading. Please reload this page.