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
86 changes: 86 additions & 0 deletions FinalTaskEgorLastin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import feedparser
import argparse

def parseRSS( rss_url ):
return feedparser.parse( rss_url )

def getTimes(rss_url):
times=[]
feed=parseRSS(rss_url)
for newsitem in feed['items']:
times.append(newsitem['published'])
return times

def getLinks(rss_url):
links=[]
feed= parseRSS(rss_url)
for newsitem in feed['items']:
links.append(newsitem[ 'link'])
return links

#def getTimes( rs_url)
def getHeadlines( rss_url ):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

есть много стилистических ошибок
советую посмотреть в сторону утилиты pycodestyle

headlines = []
feed = parseRSS( rss_url )
for newsitem in feed['items']:
headlines.append(newsitem['title'])
return headlines

# A list to hold all headlines,links,.....

allheadlines=[]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в глобальной секции не должно быть никакой логики. нужно перенести в функции/классы.

alllinks=[]
alltimes=[]
allpics=[]

# List of RSS feeds that we will fetch and combine
newsurls = {'yahoonews': 'http://news.yahoo.com/rss/'}
# Iterate over the feed urls
for key,url in newsurls.items():
print(key,url)
# Call getHeadlines() and combine the returned headlines with allheadlines
allheadlines.extend( getHeadlines( url ) )
alllinks.extend( getLinks(url ))
alltimes.extend( getTimes( url))
res = "\n".join("Link: {}\nTitle: {}\nTime published: {}\n".format( x, y, z) for x, y, z in zip(alllinks, allheadlines, alltimes))
# Iterate over the allheadlines list and print each headline
for i in res:
print(i)
#print(ln,"\n",hl.replace("'","'"))

#
#
#
"""
import feedparser
import webbrowser
import argparse
parser = argparse.ArgumentParser(description='This is the python-built RSS reader.')
parser.add_argument('-u','--ur',action='store',dest='url',default=None,help='<Required> url link',required=True)
results = parser.parse_args()#output from all of this
feed = feedparser.parse(results.url)
feed_entries = feed.entries

def parseRSS(feed):
return feedparser.parse(feed)#used
def getHeadlines( results.url ):
headlines = []
feed = parseRSS(results.url)
for newsitem in feed['items']:
headlines.append(newsitem['title'])

return headlines

allheadlines = []

for key,url in newsurls.items():
#
allheadlines.extend(getHeadlines(url))
#
for hl in allheadlines:
print(hl.replace("&#39;","'"))

def formatEntry(headline,date,link):
print(1)
"""

10 changes: 10 additions & 0 deletions PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Metadata-Version: 1.0
Name: RSS-READER.py
Version: 0.1
Summary: UNKNOWN
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
7 changes: 7 additions & 0 deletions SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
finalTaskPart1.py
setup.py
RSS_READER.py.egg-info/PKG-INFO
RSS_READER.py.egg-info/SOURCES.txt
RSS_READER.py.egg-info/dependency_links.txt
RSS_READER.py.egg-info/requires.txt
RSS_READER.py.egg-info/top_level.txt
1 change: 1 addition & 0 deletions dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

123 changes: 123 additions & 0 deletions finalTask part3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import feedparser
import argparse
import json
import requests
import datetime
import base64
"""import section"""


version = 0.1
parser = argparse.ArgumentParser()
parser.add_argument("URL", help="This is the full adress of the rss feed.use ' ' ")
parser.add_argument("-l", "--lim", help="outputs the latest X articles. can be run without lim to get all articles")
parser.add_argument("-o", "--output", help="outputs news to file", action="store_true")
parser.add_argument("-j", "--json", help="outputs a jsonDump", action="store_true")
parser.add_argument("-d", "--dl", help="downloads data.makes a file as date right now", action="store_true")
parser.add_argument("-r", help="reads the dl version of the feed. arg is the date of dl, you dont need a working url")
#parser.add_argument("--pdf", help="converts the output to the specified format (.pdf) ")
#parser.add_argument("--html", help="converts the output to the specified format (.html) ")
args = parser.parse_args()
limit = args.lim


def captureFeed(URL):
"""Gets a feed fo everything to use"""
feed = feedparser.parse(args.URL)
return feed


def fileOutput():
"""Outputs a json dump of feed.entries to a file that is called "news.txt".works """
open("news.txt", "w").close()
feed = captureFeed(args.URL)
f = open("news.txt", "w+")
input1 = json.dumps(feed.entries)
f.write(input1)
f.close()


def standardOutput():
"""This is what happens when there are no tail commands added"""
if not args.r:
feed = captureFeed(args.URL)
else:
remoteFeed = remoteRead()
feed = remoteFeed
for article in feed.entries:
print("Title: ", article.title.replace("&#39;", "'"), "\nDate: ",
article.published, "\nLinks: ", article.link, "\n")

def jsonOutput():
"""Outputs a json Dump to the console"""
feed = captureFeed(args.URL)
print(json.dumps(feed.entries))


def limitedOutput(limit):
if not args.r:
feed = captureFeed(args.URL)
else:
remoteFeed = remoteRead()
feed = remoteFeed
try:
for Index in range(int(limit)):
T = str(feed.entries[Index].title)
P = feed.entries[Index].published
L = feed.entries[Index].link
print("Title: ", T.replace("&#39;", "'"), "\nDate: ",
P, "\nLinks: ", L, "\n")
print("your limit was: ", limit)
except IndexError:
print("no")
"""Output if the user uses the --limit args, protected by indexError"""


def cacheDate(URL):
response = requests.get(URL)
today = datetime.date.today()
dateNow = today.strftime("%d-%m-%Y")
filename = dateNow + ".xml"
with open(filename, 'wb') as file:
file.write(response.content)


def remoteRead():
remoteFeed = feedparser.parse(args.r)
return remoteFeed


def getPics():
feed = captureFeed(args.URL)
listOfPics = []
try:
for i in range(len(feed.entries)-1):
pics = feed.entries[i].media_content[0].get('url')
listOfPics.append(pics)
except IndexError:
print("not all posts have images")
print(listOfPics)

getPics()
if limit and not args.r:
limitedOutput(limit)
elif args.json:
jsonOutput()
elif not limit and not args.r:
standardOutput()

if args.r and not limit:
remoteRead()
if limit and args.r:
limitedOutput(limit)


if args.dl:
cacheDate(args.URL)



if args.output:
feed = captureFeed(args.URL)
fileOutput()
"""Has to go away from the global score. could try to put it into a main()"""
50 changes: 50 additions & 0 deletions finalTaskPart1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import feedparser
import argparse
import gc


version = 0.1
parser = argparse.ArgumentParser()
parser.add_argument("URL", help="This is the full adress of the rss feed.use ' ' ")
parser.add_argument("-l", "--lim", help="outputs the latest X(int)articles. can be run without lim to get all articles")
args = parser.parse_args()
limit=args.lim

def captureFeed(url):
feed = feedparser.parse(args.URL)
return feed


def standardOutput():
"""This is what happens when there are no tail commands added"""
feed = captureFeed(args.URL)
for article in feed.entries:
print("Title: ", article.title.replace("&#39;", "'"), "\nDate: ",
article.published, "\nLinks: ", article.link, "\n")


def limitedOutput(limit):
"""This is what happens when there is only parameter on limmit"""
feed = captureFeed(args.URL)
for i in range(int(limit)):
T=feed.entries[i].title
P=feed.entries[i].published
L=feed.entries[i].link
print("Title: ", T.replace("&#39;", "'"), "\nDate: ",
P, "\nLinks: ", L, "\n")
print("your limit was: ",limit)


if limit:
limitedOutput(limit)
else:
standardOutput()


"""
I have created the bare minimal working rss reader.
It has 2 parameters other than help. LIMIT and URL. i will include more as time progresses.
I need to remove logic from the global scope. i have done most of it but i want to use a class
for this,yet I dont know enough about them yet as I was ill on the date of the lecture and the powerpoint was complex for me at this stage
setuptools havent been made yet, Ill try to make them now
"""
90 changes: 90 additions & 0 deletions k.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import feedparser
import argparse
import json
"""import section"""

version = 0.1
parser = argparse.ArgumentParser()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

все еще есть много кода, который хранится в глобальной секции
нужно все перетащить как минимум в функции

parser.add_argument("URL", help="This is the full adress of the rss feed.use ' ' ")
parser.add_argument("-l", "--lim", help="outputs the latest X articles. can be run without lim to get all articles")
parser.add_argument("-o", "--output", help="outputs news to file", action="store_true")
parser.add_argument("-j", "--json", help="outputs a jsonDump", action="store_true")
parser.add_argument("-d","-date", help="caches the data and makes a file named by the time right now")
parser.add_argument("-c","--con", help="converts the output to some specified format like .pdf and .html")
args = parser.parse_args()
limit = args.lim
"""ALL MUST GO. I might try to pull an if __main__()"""


def cacheDate():
print("a")


def captureFeed(URL):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

названия методом должны быть маленькими буквами через нижнее подчеркивание
например capture_feed

"""Gets a feed fo everything to use"""
feed = feedparser.parse(args.URL)
return feed


def fileOutput():
"""Outputs a json dump of feed.entries to a file that is called "news.txt".works """
open("news.txt", "w").close()
feed = captureFeed(args.URL)
f = open("news.txt", "w+")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

для работы с файлами имеет смысл использовать контекстные менеджеры

input1 = json.dumps(feed.entries)
f.write(input1)
f.close()


def standardOutput():
"""This is what happens when there are no tail commands added"""
feed = captureFeed(args.URL)
for article in feed.entries:
print("Title: ", article.title.replace("&#39;", "'"), "\nDate: ",
article.published, "\nLinks: ", article.link, "\n")


def jsonOutput():
"""Outputs a json Dump to the console"""
feed = captureFeed(args.URL)
print(json.dumps(feed.entries))


def limitedOutput(limit):
feed = captureFeed(args.URL)
try:
for Index in range(int(limit)):
T = str(feed.entries[Index].title)
P = feed.entries[Index].published
L = feed.entries[Index].link
print("Title: ", T.replace("&#39;", "'"), "\nDate: ",
P, "\nLinks: ", L, "\n")
print("your limit was: ", limit)
except IndexError:
print("no")
"""Output if the user uses the --limit args, protected by indexError"""


if limit:
limitedOutput(limit)
elif args.json:
jsonOutput()
else:
standardOutput()

if args.output:
feed = captureFeed(args.URL)
fileOutput()
"""Has to go away from the global score. could try to put it into a main()"""

"""
I have created the bare minimal working rss reader.
It has 2 parameters other than help. LIMIT and URL.
I will include more as time progresses.
I need to remove logic from the global scope.
I have done most of it but i want to use a class
for this,yet I dont know enough about them yet as I
was ill on the date of the lecture and the powerpoint
was complex for me at this stage
setuptools havent been made yet, Ill try to make them now
"""
1 change: 1 addition & 0 deletions news.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feedparser
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[egg_info]
tag_build =
tag_date = 0

8 changes: 8 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from setuptools import setup, find_packages
setup(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

после установки утилиты в чистом докер контейнере через pip install . не появляется утилита rss-reader

# rss-reader --help
bash: rss-reader: command not found

name="RSS-READER.py",
version="0.1",
packages=find_packages(include=["feedparser","feedparser.*"]),
scripts=["finalTaskPart1.py"],
install_requires=['feedparser']
)
1 change: 1 addition & 0 deletions top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@