Skip to content

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
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
21 changes: 21 additions & 0 deletions LICENSE
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.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include requirements.txt
31 changes: 31 additions & 0 deletions README.md
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 added rss_reader/__init__.py
Empty file.
110 changes: 110 additions & 0 deletions rss_reader/rss_reader.py
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:
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"}}])
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
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()
1 change: 1 addition & 0 deletions rss_reader/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__="0.8"
33 changes: 33 additions & 0 deletions setup.py
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',
)