Skip to content

Commit b3f6fb3

Browse files
Refactor
1 parent ba6e018 commit b3f6fb3

File tree

18 files changed

+61
-57
lines changed

18 files changed

+61
-57
lines changed

.github/workflows/pylint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ jobs:
2121
pip install -r requirements.txt
2222
- name: Analysing the code with pylint
2323
run: |
24-
pylint --fail-under=8 --ignore-long-lines $(git ls-files '*.py')
24+
pylint --fail-under=9 $(git ls-files '*.py')

.pylintrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[MASTER]
2+
disable=
3+
C0114, # missing-module-docstring
4+
C0115, # missing-class-docstring
5+
C0116, # missing-function-docstring
6+
C0301, # line-too-long

blog2epub/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from blog2epub.blog2epub_main import VERSION, Blog2Epub
2+
3+
__all__ = [
4+
"VERSION",
5+
"Blog2Epub",
6+
]
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import sys
22
from urllib import parse
33

4-
from blog2epub.Blog2Epub import BadUrlException, Blog2Epub, NotEnoughCommandsException
4+
from blog2epub import Blog2Epub
5+
from blog2epub.common.exceptions import BadUrlException, NotEnoughCommandsException
56
from blog2epub.common.interfaces import EmptyInterface
67

78

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
from typing import Dict, Optional
1111
from urllib import parse
1212

13-
from blog2epub.common.crawler import prepare_url
14-
1513
if sys.__stdout__ is None or sys.__stderr__ is None:
1614
os.environ["KIVY_NO_CONSOLELOG"] = "1"
1715

@@ -28,10 +26,13 @@
2826
from kivy.uix.popup import Popup
2927
from kivy.uix.textinput import TextInput
3028

31-
from blog2epub.Blog2Epub import BadUrlException, Blog2Epub
32-
from common.assets import asset_path
29+
from blog2epub import Blog2Epub
30+
from blog2epub.common.assets import asset_path
31+
from blog2epub.common.crawler import prepare_url
32+
from blog2epub.common.exceptions import BadUrlException
3333
from blog2epub.common.interfaces import EmptyInterface
3434

35+
3536
SIZE = 3 / Metrics.density / Metrics.density
3637
F_SIZE = 3 / Metrics.density
3738

@@ -230,7 +231,7 @@ def about_url_click(inst):
230231

231232
class AboutPopupLabel(Label):
232233
def __init__(self, **kwargs):
233-
super(AboutPopupLabel, self).__init__(**kwargs)
234+
Label.__init__(self, **kwargs)
234235
self.font_size = dp(8 * F_SIZE)
235236
self.font_name = "RobotoMono-Regular"
236237
self.size_hint = (1, 0.1)
@@ -320,7 +321,7 @@ def get(self, key):
320321

321322
class Blog2EpubKivy(App):
322323
def __init__(self, **kwargs):
323-
super(Blog2EpubKivy, self).__init__(**kwargs)
324+
App.__init__(self, **kwargs)
324325
self.title = f"blog2epub - v. {Blog2Epub.version}"
325326
if platform.system() == "Darwin":
326327
self.icon = asset_path("blog2epub.icns")
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
from typing import Dict
22

3-
from blog2epub.crawlers.CrawlerBlogspot import Crawler, CrawlerBlogspot
4-
from blog2epub.crawlers.CrawlerWordpress import CrawlerWordpress
3+
from blog2epub.common.exceptions import NoCrawlerDetectedError
4+
from blog2epub.crawlers.blogspot import CrawlerBlogspot
5+
from blog2epub.crawlers.wordpress import CrawlerWordpress
56

67
VERSION = "1.2.4"
78

89

9-
class NoCrawlerDetectedError(Exception):
10-
pass
11-
12-
13-
class BadUrlException(Exception):
14-
pass
15-
16-
17-
class NotEnoughCommandsException(Exception):
18-
pass
19-
20-
2110
class Blog2Epub:
2211
"""Main Blog2Epub class."""
2312

@@ -29,7 +18,7 @@ def __init__(self, params: Dict):
2918
raise NoCrawlerDetectedError("No crawler detected")
3019

3120
@staticmethod
32-
def select_crawler(params: Dict) -> Crawler:
21+
def select_crawler(params: Dict):
3322
if params["url"].find(".blogspot.") > -1:
3423
return CrawlerBlogspot(**params)
3524
return CrawlerWordpress(**params)

blog2epub/common/assets.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ def asset_path(filename: str) -> str:
99
base_path = os.path.abspath("./assets/")
1010
if os.path.isfile(os.path.join(base_path, filename)):
1111
return os.path.join(base_path, filename)
12-
else:
13-
# if there is no given file i'm guessing that blog2epub is run from sources
14-
return os.path.join(os.path.abspath("../assets/"), filename)
12+
# if there is no given file i'm guessing that blog2epub is run from sources
13+
return os.path.join(os.path.abspath("../assets/"), filename)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from ebooklib import epub
77

8-
from blog2epub.Cover import Cover
8+
from blog2epub.common.cover import Cover
99

1010

1111
class Book:
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
from pathlib import Path
33
from random import shuffle
44

5+
from blog2epub.common.assets import asset_path
56
from PIL import Image, ImageDraw, ImageFont
67

7-
from common.assets import asset_path
8-
98

109
class Cover:
1110
"""

blog2epub/common/crawler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ def prepare_file_name(file_name: str, url: str) -> str:
1212

1313

1414
def prepare_url_to_crawl(url: str) -> str:
15-
r = request.urlopen("https://" + url)
16-
return r.geturl()
15+
with request.urlopen("https://" + url) as r:
16+
response = r.geturl()
17+
return response
1718

1819

1920
def prepare_port(url):

0 commit comments

Comments
 (0)