Skip to content

Anastasiya_Merkushova_st.merkush@gmail.com - PLS REVIEW#31

Open
clonder wants to merge 10 commits into
epam-python-courses-7-bsu:masterfrom
clonder:master
Open

Anastasiya_Merkushova_st.merkush@gmail.com - PLS REVIEW#31
clonder wants to merge 10 commits into
epam-python-courses-7-bsu:masterfrom
clonder:master

Conversation

@clonder

@clonder clonder commented Nov 24, 2019

Copy link
Copy Markdown

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

return cls._instances[cls]


class DatabaseEmulation(metaclass=Singleton):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What is the reason to implement this class as Singleton? You create it only once anyway.

@clonder clonder Nov 25, 2019

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@clonder clonder Nov 25, 2019

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I didn’t know about this, thanks!
Fixed.

self.dates_file.write("{} {}\n".format(date, idx))


def get_txt_date(data) -> None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Function called get_txt_date, but it doesn't return anything.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sorry, missed this! Already fixed!

@@ -0,0 +1,93 @@
import pickle

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Module name doesn't not follow PEP standard. It should be in lower case.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed, thanks!


def get_txt_date(data) -> None:
date_id = {}
with open("dates.txt", "r", encoding="utf-8") as f:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

"r", encoding="utf-8" these are default parameters for open() function.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same for code below.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed this, Thanks!

Comment thread final_task/rss_reader/converting.py Outdated
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:])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Here and below: you can't use random in path generation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed!

' '.join(item_xml['content']),
1
)
prepared_news = OrderedDict()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In python version 3.7+ dictionary is ordered by default.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I know this, but if someone accidentally uses python3.6 for example, it will not be good if he has undefined behavior.

Comment thread final_task/rss_reader/rss_reader.py Outdated

log.info("Start script")

database = DatabaseEmulation.DatabaseEmulation(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This class should support context manager protocol and use it.

@dzhigailo

Copy link
Copy Markdown
Collaborator

First two commits should be squashed.
Tests are required by task definition.

@dzhigailo dzhigailo changed the title Anastasiya_Merkushova_st.merkush@gmail.com - PLS REVIEW Anastasiya_Merkushova_st.merkush@gmail.com Nov 25, 2019
@clonder clonder changed the title Anastasiya_Merkushova_st.merkush@gmail.com Anastasiya_Merkushova_st.merkush@gmail.com - PLS REVIEW Nov 25, 2019
Comment on lines +1 to +28
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There are too many redundant libs here. Keep in mind that you should specify only libs that are directly required by your application.

Comment on lines +1 to +4
<<<<<<< HEAD
=======

>>>>>>> a9c6fd52b1a59d83145cc3e869cfe9f7a0a6c2fe

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You have unresolved conflicts here.

Comment on lines +9 to +11
parser = argparse.ArgumentParser(
description='Pure Python command-line RSS reader.',
prog='rss-reader')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is better to avoid one-letter variable names.

Comment on lines +89 to +90
img_path = str(len(element)) + \
str(img_url[-4:])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This function is too large. It is better to split it.

Comment on lines +12 to +21
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]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is better to not use such thing as singleton in this app. It is not needed at all.

Comment on lines +39 to +42
def __del__(self):
self.dates_file.close()
self.write_data_stream.close()
self.read_data_stream.close()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A typo here: cache



def filter_title(title: str) -> str:
new_title = title.replace("&#39;", '')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is better to have a bit more universal solution, as there might be other troublesome symbols.

Comment on lines +108 to +114
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is better to use datetime lib for this

@HenadziStantchik

Copy link
Copy Markdown
Collaborator

Here is feedback on your application:
It does not work right away
image

It does not work if installed using setuptools either (using python setup.py install):
image

Your app was tested both on clean machine and inside docker container.

The code is mostly readable, corresponds to the PEP8 guidelines.
Tests are almost nonexistent and coverage percentage is barely high enough.
Commits mostly are not informative enough and do not correspond to the recommended commit message style.

@clonder

clonder commented Dec 4, 2019

Copy link
Copy Markdown
Author

Hi
1)I found a problem in the fact that I have a file dates in the folder _database in which for some reason there were strange lines with an error. (and it booted). If you delete them, my whole program works.
If there is such an opportunity - please look again. (I try it on two other machines)
2) for other screen I think you should try "python3 rss_reader.py -h" with _

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants