-
Notifications
You must be signed in to change notification settings - Fork 32
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
Dydyshko Andrey #35
base: master
Are you sure you want to change the base?
Dydyshko Andrey #35
Conversation
Empty project
Description of news is readable now Also added docstrings
also refactored get_feed() method in RSSreader class
added info logs also refactored --version argument also added modules docstrings
the project has been restructured
Added cache_mews_json(), get_cached_json_news(), print_chached_feed(), print_cached_feed_json() methods Added argument --date
added class Converter in converter.py added new fonts for PDF in fonts directory does not contain images yet
added class PDFConverter
long_description = f.read() | ||
|
||
|
||
setup( |
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.
Забавная ситуация вышла)
Пакет установился успешно и вполне себе успешно распарсил новости с tut.by
но по какой-то причине не работачет обычный help :)
# rss-reader --help
Traceback (most recent call last):
File "/usr/local/bin/rss-reader", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.8/site-packages/app/rss_reader.py", line 17, in main
arguments = ArgParser()
File "/usr/local/lib/python3.8/site-packages/app/argparser.py", line 15, in __init__
self.args = self.parse_args()
File "/usr/local/lib/python3.8/site-packages/app/argparser.py", line 61, in parse_args
args = argparser.parse_args()
File "/usr/local/lib/python3.8/argparse.py", line 1768, in parse_args
args, argv = self.parse_known_args(args, namespace)
File "/usr/local/lib/python3.8/argparse.py", line 1800, in parse_known_args
namespace, args = self._parse_known_args(args, namespace)
File "/usr/local/lib/python3.8/argparse.py", line 2006, in _parse_known_args
start_index = consume_optional(start_index)
File "/usr/local/lib/python3.8/argparse.py", line 1946, in consume_optional
take_action(action, args, option_string)
File "/usr/local/lib/python3.8/argparse.py", line 1874, in take_action
action(self, namespace, argument_values, option_string)
File "/usr/local/lib/python3.8/argparse.py", line 1044, in __call__
parser.print_help()
File "/usr/local/lib/python3.8/argparse.py", line 2493, in print_help
self._print_message(self.format_help(), file)
File "/usr/local/lib/python3.8/argparse.py", line 2477, in format_help
return formatter.format_help()
File "/usr/local/lib/python3.8/argparse.py", line 282, in format_help
help = self._root_section.format_help()
File "/usr/local/lib/python3.8/argparse.py", line 213, in format_help
item_help = join([func(*args) for func, args in self.items])
File "/usr/local/lib/python3.8/argparse.py", line 213, in <listcomp>
item_help = join([func(*args) for func, args in self.items])
File "/usr/local/lib/python3.8/argparse.py", line 213, in format_help
item_help = join([func(*args) for func, args in self.items])
File "/usr/local/lib/python3.8/argparse.py", line 213, in <listcomp>
item_help = join([func(*args) for func, args in self.items])
File "/usr/local/lib/python3.8/argparse.py", line 529, in _format_action
help_text = self._expand_help(action)
File "/usr/local/lib/python3.8/argparse.py", line 621, in _expand_help
return self._get_help_string(action) % params
ValueError: unsupported format character 'Y' (0x59) at index 26
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.
Проблема была в атрибуте help аргумента date (написал там пример формата даты с процентами %Y%m%d, чего не стоило делать) Сейчас все работает
ну или почти все
app/pdf_converter.py
Outdated
self.logger.info('Creating directory images') | ||
os.mkdir(directory_path) | ||
split_list = img_url.split('/') | ||
img_name = split_list[len(split_list) - 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.
- строка
split_list[len(split_list) - 1]
эквивалентнаsplit_list[-1]
- что значит
-1
и-2
? Магические числа. возможно есть смысл это как-нибудь отрефакторить
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.
Сделал получше
(а может только хуже :/)
Вынес все это дело в отдельный метод и обошелся без -2
app/RSSreader.py
Outdated
# already cached | ||
return | ||
except FileNotFoundError: | ||
pass |
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.
в данном случае стоило хотя бы залогировать факт возникновения такого эксепшена
а то два pass
подряд в except блоках смотрится странно)
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.
Сделано
app/RSSreader.py
Outdated
print('========================================================') | ||
|
||
def to_json(self, entry): | ||
""" Returns feed in JSON (actually dict()) format """ |
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.
Сам факт такого док стринга должен навести на мысль, что тут что-то не так.
Эта функция не производит конвертацию в json.
Она создает словарь
название метода to_dict
в данном случае подойдет намного лучше (ну или что-то другое, но точно не to_json)
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.
Исправлено
app/RSSreader.py
Outdated
|
||
for entry in entries: | ||
print('========================================================') | ||
print(f'Title: {entry.title}') |
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.
А почему не печатается информация об изображениях?
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.
Оформил вывод url изображения во всех форматах для консоли и кэша
А в pdf так вообще саму картинку иногда показывает
app/RSSreader.py
Outdated
|
||
for entry in entries: | ||
feed = self.to_json(entry) | ||
print('========================================================') |
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.
эти строки тут не нужны
в аутпут должен пойти только JSON (чтобы аутпут можно было распарсить другой утилитой или записать результат в файл)
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.
то есть аутпутом должен являться валидный json
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.
Сделяль
now image imformation prints in stdout
Fixed packages_data in setup.py Now it should work correctly on clean machine
README.md
Outdated
internet connection | ||
* Btw i use fonts for .pdf files to avoid encoding issues, | ||
hope they will be installed correctly by 'pip install .' | ||
* P.S. Ля, ребята, 4 курс птуира, уже распред идет во всю, работа нужна кааапец |
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.
Лучше удалить эту строку :)
app/RSSReader.py
Outdated
class RSSReader: | ||
""" Reads news from RSS url and prints them """ | ||
|
||
def __init__(self, args, logger): |
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.
Советую заменить аргумент args
на те три аргумента, которые используется в этом классе
то есть путь вместо этого аргумента оно принимает url, limit, date
таким образом будет больше гибкости в использовании этого класса. И интерфейс будет более понятным и прозрачным.
from app.RSSReader import RSSReader | ||
|
||
|
||
warnings.filterwarnings("ignore") |
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.
А для чего необходимо игнорировать варнинги?
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.
Я использую BeautifulSoup чтобы достать ссылку на картинку из тега img src=""
А скачиваю картинку уже при помощи urllib.request
Но BeautifulSoup все равно печатает в консоль такие warnings
C:\Users\F5\Documents\GitHub\PythonHomework\venv\lib\site-packages\bs4_init_.py:371: UserWarning: "https://img.tyt.by/thumbnails/n/01/3/novostroyka_dzerzhinskogo_obrushenie_1.jpg" looks like a URL. Beautiful Soup is not an HTTP client. You should probably use an HTTP client like requests to get the document behind the URL, and feed that document to Beautiful Soup.
warnings.warn(
Added class RSSException(Exception), implemented argument --colorize Added 2 tests for RSSReader class methods
was -> args now -> limit url date etc.
Не могу понять в чем дело |
Может дело в передаваемом пути аргументу |
now feedparser receives response from requests.get(url) added exception to write(img)
Моменты, которые можно улучшить:
|
Progress