diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..56e93f0 --- /dev/null +++ b/LICENSE @@ -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. \ No newline at end of file diff --git a/file1.py b/file1.py new file mode 100644 index 0000000..f37af25 --- /dev/null +++ b/file1.py @@ -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) + + + diff --git a/main.py b/main.py new file mode 100644 index 0000000..fd103a3 --- /dev/null +++ b/main.py @@ -0,0 +1,5 @@ +print("Please, enter your name:"); +a=str(input()) +print("Hello brave new, "+a) +print("How is the weather today?") + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..588cb5d --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +bs4 \ No newline at end of file diff --git a/rss_read.log b/rss_read.log new file mode 100644 index 0000000..946d729 --- /dev/null +++ b/rss_read.log @@ -0,0 +1 @@ +[2019-11-30 17:36:21,547] Started executing diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..62f2dcb --- /dev/null +++ b/setup.py @@ -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() + +) \ No newline at end of file