-
Notifications
You must be signed in to change notification settings - Fork 31
[WIP] Lastin Egor #41
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
base: master
Are you sure you want to change the base?
Changes from all commits
b4e1f1d
35d8cf0
860e3b3
e06aa72
8cc3ac7
0a0df73
6c7f5a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 ): | ||
| headlines = [] | ||
| feed = parseRSS( rss_url ) | ||
| for newsitem in feed['items']: | ||
| headlines.append(newsitem['title']) | ||
| return headlines | ||
|
|
||
| # A list to hold all headlines,links,..... | ||
|
|
||
| allheadlines=[] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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("'","'")) | ||
|
|
||
| def formatEntry(headline,date,link): | ||
| print(1) | ||
| """ | ||
|
|
||
| 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 |
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
| 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("'", "'"), "\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("'", "'"), "\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()""" |
| 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("'", "'"), "\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("'", "'"), "\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 | ||
| """ |
| 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() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. названия методом должны быть маленькими буквами через нижнее подчеркивание |
||
| """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+") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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("'", "'"), "\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("'", "'"), "\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 | ||
| """ | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| feedparser |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [egg_info] | ||
| tag_build = | ||
| tag_date = 0 | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from setuptools import setup, find_packages | ||
| setup( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. после установки утилиты в чистом докер контейнере через # 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'] | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
есть много стилистических ошибок
советую посмотреть в сторону утилиты
pycodestyle