Anastasiya_Merkushova_st.merkush@gmail.com - PLS REVIEW#31
Conversation
| return cls._instances[cls] | ||
|
|
||
|
|
||
| class DatabaseEmulation(metaclass=Singleton): |
There was a problem hiding this comment.
What is the reason to implement this class as Singleton? You create it only once anyway.
There was a problem hiding this comment.
It’s a good practice to make such objects as singleton. It doesn’t matter that in this case the object of this class is used once, it is much more important that if it is used a lot where, it was the same object.
| self.write_data_stream = open(self.path_to_data, "ab") | ||
| self.read_data_stream = open(self.path_to_data, "rb") | ||
|
|
||
| def __exit__(self, *args): |
There was a problem hiding this comment.
This magic method doesn't make any sense without __enter__(self) magic method since both of those method are required for context manager protocol. Moreover, you never call it and opened files will not be closed.
Magic method exit always have 3 positional arguments. There is no reason to use *args.
There was a problem hiding this comment.
I didn’t know about this, thanks!
Fixed.
| self.dates_file.write("{} {}\n".format(date, idx)) | ||
|
|
||
|
|
||
| def get_txt_date(data) -> None: |
There was a problem hiding this comment.
Function called get_txt_date, but it doesn't return anything.
There was a problem hiding this comment.
Sorry, missed this! Already fixed!
| @@ -0,0 +1,93 @@ | |||
| import pickle | |||
There was a problem hiding this comment.
Module name doesn't not follow PEP standard. It should be in lower case.
|
|
||
| def get_txt_date(data) -> None: | ||
| date_id = {} | ||
| with open("dates.txt", "r", encoding="utf-8") as f: |
There was a problem hiding this comment.
"r", encoding="utf-8" these are default parameters for open() function.
| if element.endswith(".png") or element.endswith(".jpg"): | ||
| image = r.get(element) | ||
| try: | ||
| img_path = str(len(element)) + str(random.randint(1, 128)) + str(img_url[-4:]) |
There was a problem hiding this comment.
Here and below: you can't use random in path generation.
| ' '.join(item_xml['content']), | ||
| 1 | ||
| ) | ||
| prepared_news = OrderedDict() |
There was a problem hiding this comment.
In python version 3.7+ dictionary is ordered by default.
There was a problem hiding this comment.
I know this, but if someone accidentally uses python3.6 for example, it will not be good if he has undefined behavior.
|
|
||
| log.info("Start script") | ||
|
|
||
| database = DatabaseEmulation.DatabaseEmulation( |
There was a problem hiding this comment.
This class should support context manager protocol and use it.
|
First two commits should be squashed. |
…nd verification(PEP) is done using flake8
| arguments==76 | ||
| beautifulsoup4==4.8.1 | ||
| bs4==0.0.1 | ||
| certifi==2019.9.11 | ||
| cffi==1.13.2 | ||
| chardet==3.0.4 | ||
| colorama==0.4.1 | ||
| colorize==1.1.0 | ||
| cycler==0.10.0 | ||
| dominate==2.4.0 | ||
| entrypoints==0.3 | ||
| feedparser==5.2.1 | ||
| flake8==3.7.9 | ||
| fpdf==1.7.2 | ||
| idna==2.8 | ||
| kiwisolver==1.1.0 | ||
| lxml==4.4.1 | ||
| mccabe==0.6.1 | ||
| numpy==1.17.4 | ||
| pycodestyle==2.5.0 | ||
| pycparser==2.19 | ||
| pyflakes==2.1.1 | ||
| pyparsing==2.4.5 | ||
| python-dateutil==2.8.1 | ||
| requests==2.22.0 | ||
| six==1.13.0 | ||
| soupsieve==1.9.5 | ||
| urllib3==1.25.7 |
There was a problem hiding this comment.
There are too many redundant libs here. Keep in mind that you should specify only libs that are directly required by your application.
| <<<<<<< HEAD | ||
| ======= | ||
|
|
||
| >>>>>>> a9c6fd52b1a59d83145cc3e869cfe9f7a0a6c2fe |
There was a problem hiding this comment.
You have unresolved conflicts here.
| parser = argparse.ArgumentParser( | ||
| description='Pure Python command-line RSS reader.', | ||
| prog='rss-reader') |
There was a problem hiding this comment.
Here and below: it is better to make this into one line, it will be still pretty readable.
Also it is better to use f"" instead of .format().
| @@ -0,0 +1,146 @@ | |||
| import logging as log | |||
| import requests as r | |||
There was a problem hiding this comment.
It is better to avoid one-letter variable names.
| img_path = str(len(element)) + \ | ||
| str(img_url[-4:]) |
There was a problem hiding this comment.
It is better to use os.path for operations with filesystem paths because Windows OS and Linux OS have different separators
| log.info("Successful converting into html") | ||
|
|
||
|
|
||
| def create_pdf(items: list) -> None: |
There was a problem hiding this comment.
This function is too large. It is better to split it.
| class Singleton(type): | ||
| _instances = {} | ||
|
|
||
| def __call__(cls, *args, **kwargs): | ||
| if cls not in cls._instances: | ||
| cls._instances[cls] = super(Singleton, cls).__call__( | ||
| *args, | ||
| **kwargs | ||
| ) | ||
| return cls._instances[cls] |
There was a problem hiding this comment.
It is better to not use such thing as singleton in this app. It is not needed at all.
| def __del__(self): | ||
| self.dates_file.close() | ||
| self.write_data_stream.close() | ||
| self.read_data_stream.close() |
There was a problem hiding this comment.
It is better to use context manager's __enter__ and __exit__ for this purpose, not __del__
| print("There isn't any news from this day") | ||
|
|
||
|
|
||
| def cash_news() -> None: |
There was a problem hiding this comment.
A typo here: cache
|
|
||
|
|
||
| def filter_title(title: str) -> str: | ||
| new_title = title.replace("'", '') |
There was a problem hiding this comment.
It is better to have a bit more universal solution, as there might be other troublesome symbols.
| month = { | ||
| 'Dec': '12', 'Jan': '01', 'Feb': '02', | ||
| 'Mar': '03', 'Apr': '04', 'May': '05', | ||
| 'Jun': '06', 'Jul': '07', 'Aug': '08', | ||
| 'Sep': '09', 'Oct': '10', 'Nov': '11' | ||
| } | ||
| new_date = date |
There was a problem hiding this comment.
It is better to use datetime lib for this
|
Hi |


1-5 done (without test), fix some problems with commits.