Good code practices #1547
Replies: 9 comments 30 replies
-
We need good code examples to get images, authors, titles. It seems to me that such code could be implemented better. cover_img = soup.select_one('.entry-content .wp-block-image img')
if cover_img:
self.novel_cover = self.absolute_url(cover_img['data-ezsrc'])
# end if
first_p = soup.select_one("div.entry-content p")
for text in first_p.get_text(separator='\n', strip=True).split('\n'):
if text.startswith('Author'):
self.novel_author = text.replace("Author: ", "")
break
# end if
# end for |
Beta Was this translation helpful? Give feedback.
-
@idMysteries It's more @dipu-bd than me, I'm low level if lower with python, I kind of understand most code but I mostly a copy and paste coders or I like to think I can modify code to make it do what I want most of the time but I don't write from scratch, most of mine is google and then edit to make it work lol. If @dipu-bd decided this is better for future sources files I'm happy to use whatever works for each site. |
Beta Was this translation helpful? Give feedback.
-
c1dd85f |
Beta Was this translation helpful? Give feedback.
-
I started this project a long time ago. I was just beginning to learn python at that time. Many of the sources here might not be the best example of good coding practice. If I get a chance to define what is a good coding practice today, I would use decorations and typings heavily and would not use those Anyway, just follow the common python coding practices and linting suggestions from flake8 and autopep8. |
Beta Was this translation helpful? Give feedback.
-
I think I found a good solution to parse such lines. novelcontent = soup.select_one(".novelcontent")
if novelcontent:
author_strong = novelcontent.find('strong', string='Author: ')
if author_strong and author_strong.next_sibling:
self.novel_author = author_strong.next_sibling.text |
Beta Was this translation helpful? Give feedback.
-
@dipu-bd fed67ab |
Beta Was this translation helpful? Give feedback.
-
@dipu-bd can you please tell us about some changes in the code? What kind of models have appeared? For example, SearchResult. How to use it? I don't keep up with the changes, but I like them. If you have time, describe a little the changes that have occurred in recent days. |
Beta Was this translation helpful? Give feedback.
-
Some chapters have a number in the title, and some don't. Like "Chapter X: Title", but not "Chapter X: Chapter X: Title"? OR Maybe "Title (ch. X)", "Chapter X: Title (ch. X)"? |
Beta Was this translation helpful? Give feedback.
-
@dipu-bd Do we need to create a separate module for each site from the template? class MadaraTemplate(Crawler)...
...
class MangaRockteam(MadaraTemplate):
...
class Madara2(MadaraTemplate):...
class Madara4(MadaraTemplate):...
class Madara5(MadaraTemplate):...
class Madara6(MadaraTemplate):... |
Beta Was this translation helpful? Give feedback.
-
I am a new member of this project and I know python at a low level.
Let's think together about a good solution to some problems? @dipu-bd @SirGryphin
For example, a beautiful and fast code for adding volumes and chapters.
Is it possible to improve this part and take it out of the loop?
Beta Was this translation helpful? Give feedback.
All reactions