From 7955964c01c973d6c7d53ed195fdd63f46a699bc Mon Sep 17 00:00:00 2001 From: KirushaQ <33037184+KirushaQ@users.noreply.github.com> Date: Sun, 10 Nov 2019 18:19:19 +0300 Subject: [PATCH 1/4] Created readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..9149e60 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# PythonHomework +[Introduction to Python] Homework Repository +branch with final Hometask From 596b61cd09395e8a0ba7169ad7e3568dfa63d622 Mon Sep 17 00:00:00 2001 From: KirushaQ <33037184+KirushaQ@users.noreply.github.com> Date: Sun, 1 Dec 2019 19:37:51 +0300 Subject: [PATCH 2/4] Uploaded python file with first iteration --- finale.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 finale.py diff --git a/finale.py b/finale.py new file mode 100644 index 0000000..7562a05 --- /dev/null +++ b/finale.py @@ -0,0 +1,49 @@ +import feedparser +import argparse +import json + +version = '1.0' + + +def print_function(feed, limit, js): + func_limit = 0 + d = {} + + for entry in feed.entries: + func_limit += 1 + article_title = entry.title + article_link = entry.link + article_date = entry.published + content = entry.description + + if js == 0: + print("Title: {}".format(article_title)) + print("Link: [{}]".format(article_link)) + print("Date: {}\n".format(article_date)) + print("Content: [{}]\n\n".format(content)) + else: + d["Title"] = article_title + d["Link"] = article_link + d["Date"] = article_date + d["Content"] = content + print(json.dumps(d) + '\n') + + if func_limit == limit: + break + + +parser = argparse.ArgumentParser(description='Rss reader programm') +parser.add_argument('link', help='Receive rss url in format: \"url\"') +parser.add_argument('--limit', type=int, default=0, help='Receive int \'x\' and print \'x\' block of news') +parser.add_argument('--version', action='count', default=0, help='Print current version of a program and complete work') +parser.add_argument('--json', action='count', default=0, help="print result as json") + +args = parser.parse_args() + +feed = feedparser.parse(args.link) +feed_entries = feed.entries + +if args.version == 0: + print_function(feed, args.limit, args.json) +else: + print("Current version is: ", version) From 88ef37ffd4862da131a41c7de3590e26b14e2f8e Mon Sep 17 00:00:00 2001 From: KirushaQ <33037184+KirushaQ@users.noreply.github.com> Date: Sun, 1 Dec 2019 19:39:12 +0300 Subject: [PATCH 3/4] updated readme file due first iteration --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 9149e60..c2fe073 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # PythonHomework [Introduction to Python] Homework Repository branch with final Hometask + +Package: feedparser +json format: {"Title":"title", "Link":"link", "Date":"date", "Content":"content"} From 2507fcd93bdc47b58889cec6104e566a9488a049 Mon Sep 17 00:00:00 2001 From: KirushaQ <33037184+KirushaQ@users.noreply.github.com> Date: Sun, 1 Dec 2019 21:07:29 +0300 Subject: [PATCH 4/4] uploaded 3-d iteration --- finale.py | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/finale.py b/finale.py index 7562a05..c389342 100644 --- a/finale.py +++ b/finale.py @@ -1,6 +1,8 @@ import feedparser import argparse import json +import datetime +import os version = '1.0' @@ -8,6 +10,21 @@ def print_function(feed, limit, js): func_limit = 0 d = {} + now = datetime.datetime.now() + year = now.year + month = now.month + day = now.day + year_str = str(year) + if day>9: + day_str = str(day) + else: + day_str = '' + '0' + str(day) + if month > 9: + month_str = str(month) + else: + month_str = '' + '0' + str(month) + name = '' + year_str + month_str + day_str + ".txt" + f = open(name, 'w') for entry in feed.entries: func_limit += 1 @@ -28,22 +45,44 @@ def print_function(feed, limit, js): d["Content"] = content print(json.dumps(d) + '\n') + f.write("Title : " + article_title) + f.write("\nLink: [" + article_link + "]") + f.write("\nDate: " + article_date) + f.write("\nContent: [" + content + "]\n\n") + if func_limit == limit: break + f.close() + + +def date_function(date): + name = '' + str(date) + '.txt' + if os.path.isfile(name): + f = open(name, 'r') + for line in f: + print(line) + f.close() + else: + print("ERROR") + parser = argparse.ArgumentParser(description='Rss reader programm') parser.add_argument('link', help='Receive rss url in format: \"url\"') parser.add_argument('--limit', type=int, default=0, help='Receive int \'x\' and print \'x\' block of news') parser.add_argument('--version', action='count', default=0, help='Print current version of a program and complete work') parser.add_argument('--json', action='count', default=0, help="print result as json") +parser.add_argument('--date', type=int, default=0, help='Receive yyyymmdd and print news, checked at that day, if they exist') args = parser.parse_args() feed = feedparser.parse(args.link) feed_entries = feed.entries -if args.version == 0: - print_function(feed, args.limit, args.json) -else: +if args.version != 0: print("Current version is: ", version) +else: + if args.date == 0: + print_function(feed, args.limit, args.json) + else: + date_function(args.date)