Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2019 The Python Packaging Authority

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.
117 changes: 117 additions & 0 deletions file1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/usr/bin/env python

from bs4 import BeautifulSoup
import requests
import urllib
import urllib.request
import argparse
import sys
import json
import logging

parser=argparse.ArgumentParser()
parser.add_argument('url',type=str)
parser.add_argument('--version',action='store_true')
parser.add_argument('--limit', type=int)
parser.add_argument('--json', action='store_true')
agrs=parser.parse_args()

logging.basicConfig( filename='rss_read/rss_read.log',level=logging.INFO,format=u'[%(asctime)s] %(message)s')

class Feed():
""" """

def __init__(self, url):
self.url=url
self.list_news=[]
self.class_news=[]

def setupconnection(self):
self.webUrl = urllib.request.urlopen(self.url)
if self.webUrl.getcode()!=200:
print("Cannot get a proper connection to the web-site")
logging.error('Cannot get a proper conncetion to the web-site')




def createfields(self):
self.handler=self.webUrl.read()
self.soup=BeautifulSoup(self.handler,"xml")
if agrs.limit==None:
self.list_news = self.soup.find_all('item')
else:
self.list_news = self.soup.find_all('item',limit=agrs.limit)

for item in self.list_news:


title=item.find('title')
date=item.find('pubDate')
des=item.find('description')
link=item.find('link')
des=BeautifulSoup(des.text,'xml')
img=des.find('img')['src']
description=des.find('a')

self.class_news.append(News(title.text,date.text,link.text,img,description.text))



def printout(self):
for i in self.class_news:
i.printnews()
def tojson(self):
try:
print("ss")
jsonfile=open('news_json.json','w+')
json_list: list=[]
for i in self.class_news:
data=i.converttojson()
json_list.append(data)
json.dump(json_list,jsonfile)
except IOError:
print("Error: Can't create the json file")
sys.exit()


class News():
""""""
def __init__(self,title, date, link,img,des):
self.title="Title: "+title
self.date="Publicatiob date: "+date
self.des="Description : "+des
self.img="Image link: "+img
self.link="Link: "+link
def printnews(self):
print(self.title)
print(self.date)
print(self.des)
print(self.link)
print(self.img)
def converttojson(self):
to_dict= self.__dict__
return to_dict

def vers():
print('Current version is 1')
sys.exit()
def main(url):
logging.info('Started executing')
if agrs.version==True:
vers()

work=Feed(url)
work.setupconnection()
work.createfields()
if agrs.json==True:


work.tojson()
work.printout()


main(agrs.url)



5 changes: 5 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
print("Please, enter your name:");
a=str(input())
print("Hello brave new, "+a)
print("How is the weather today?")

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bs4
1 change: 1 addition & 0 deletions rss_read.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[2019-11-30 17:36:21,547] Started executing
18 changes: 18 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from setuptools import setup, find_packages
from os import path
here = path.abspath(path.dirname(__file__))

with open(path.join(here, 'README.txt'), encoding='utf-8') as f:
long_description = f.read()

setup(
name = "rss_read",
version = "0.0.1",
author = "Kseniya Chystova",
author_email = "lublubulbu@gmail.com",
description = ("A simple reader for rss format"),
long_description=long_description,
keywords = ("rss", "parsing"),
packages=find_packages()

)