pygetcomics 1.2.5__tar.gz → 1.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,26 +1,26 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pygetcomics
3
- Version: 1.2.5
3
+ Version: 1.3.1
4
4
  Summary: Download various daily comics.
5
5
  Home-page: https://gitlab.com/berhoel/python/pyGetComics.git
6
6
  License: BSD-2-Clause
7
7
  Author: Berthold Höllmann
8
8
  Author-email: berhoel@gmail.com
9
- Requires-Python: >=3.8,<4.0
9
+ Requires-Python: >=3.9,<4.0
10
10
  Classifier: Development Status :: 4 - Beta
11
11
  Classifier: License :: OSI Approved :: BSD License
12
12
  Classifier: Operating System :: OS Independent
13
13
  Classifier: Programming Language :: Python
14
14
  Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.10
16
- Classifier: Programming Language :: Python :: 3.8
17
15
  Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
18
  Classifier: Programming Language :: Python :: Implementation :: CPython
19
19
  Requires-Dist: Pillow (>8.0.0)
20
20
  Requires-Dist: jinja2 (>3.0.0)
21
21
  Requires-Dist: lxml (>4.5.0)
22
22
  Requires-Dist: requests (>2.23.0)
23
- Requires-Dist: selenium (>4.0.0)
23
+ Requires-Dist: selenium (>=4.7.2)
24
24
  Project-URL: Repository, https://gitlab.com/berhoel/python/pyGetComics.git
25
25
  Description-Content-Type: text/x-rst
26
26
 
@@ -0,0 +1,58 @@
1
+ #! /usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """Download various daily comics.
4
+ """
5
+
6
+ from __future__ import annotations, generator_stop
7
+
8
+ # Standard library imports.
9
+ import argparse
10
+
11
+ # Local library imports.
12
+ from . import peanuts, garfield
13
+
14
+ __date__ = "2023/03/18 18:04:22 hoel"
15
+ __author__ = "Berthold Höllmann"
16
+ __copyright__ = "Copyright © 2017, 2022 by Berthold Höllmann"
17
+ __credits__ = ["Berthold Höllmann"]
18
+ __maintainer__ = "Berthold Höllmann"
19
+ __email__ = "berhoel@gmail.com"
20
+
21
+ try:
22
+ # Local library imports.
23
+ from ._version import __version__
24
+ except ImportError:
25
+ __version__ = "0.0.0.invalid0"
26
+
27
+
28
+ def get_parser() -> argparse.ArgumentParser:
29
+ parser = argparse.ArgumentParser(
30
+ prog="get_comics", description="Download various periodic comics."
31
+ )
32
+ parser.add_argument(
33
+ "--version",
34
+ "-V",
35
+ action="version",
36
+ version="%(prog)s {version}".format(version=__version__),
37
+ )
38
+ return parser
39
+
40
+
41
+ def main(args=None):
42
+ """Get all supported comics."""
43
+ args = get_parser().parse_args()
44
+
45
+ print("Get Peanuts.")
46
+ peanuts.main(args)
47
+ print("Get Garfield.")
48
+ garfield.main(args)
49
+
50
+
51
+ if __name__ == "__main__":
52
+ main()
53
+
54
+ # Local Variables:
55
+ # mode: python
56
+ # compile-command: "cd ../../ && python setup.py test"
57
+ # time-stamp-pattern: "30/__date__ = \"%:y/%02m/%02d %02H:%02M:%02S %u\""
58
+ # End:
@@ -5,13 +5,14 @@
5
5
 
6
6
  from __future__ import annotations, generator_stop
7
7
 
8
- # Standard libraries.
9
- import os
8
+ # Standard library imports.
9
+ import argparse
10
10
  from pathlib import Path
11
11
 
12
+ # Local library imports.
12
13
  from ..gocomics import GoComics
13
14
 
14
- __date__ = "2022/07/04 23:16:51 hoel"
15
+ __date__ = "2023/03/19 19:35:26 hoel"
15
16
  __author__ = "Berthold Höllmann"
16
17
  __copyright__ = "Copyright © 2017, 2022 by Berthold Höllmann"
17
18
  __credits__ = ["Berthold Höllmann"]
@@ -20,7 +21,6 @@ __email__ = "berhoel@gmail.com"
20
21
 
21
22
 
22
23
  class Garfield(GoComics):
23
-
24
24
  "Download daily Garfield comcs fromGoComics."
25
25
 
26
26
  # June 19, 1978
@@ -37,8 +37,27 @@ class Garfield(GoComics):
37
37
  statefile_name = garfield_path / "garfield.statfile"
38
38
 
39
39
 
40
- def main():
40
+ def get_parser() -> argparse.ArgumentParser:
41
+ # First party library imports.
42
+ from berhoel.get_comics import __version__
43
+
44
+ parser = argparse.ArgumentParser(
45
+ prog="get_garfield", description="Download daily Garfield comics."
46
+ )
47
+ parser.add_argument(
48
+ "--version",
49
+ "-V",
50
+ action="version",
51
+ version="%(prog)s {version}".format(version=__version__),
52
+ )
53
+ return parser
54
+
55
+
56
+ def main(args=None):
41
57
  "Main Program."
58
+ if args is None:
59
+ args = get_parser().parse_args()
60
+
42
61
  Garfield()()
43
62
 
44
63
 
@@ -5,14 +5,14 @@
5
5
 
6
6
  from __future__ import annotations, generator_stop
7
7
 
8
- # Standard libraries.
8
+ # Standard library imports.
9
9
  import datetime
10
10
  from pathlib import Path
11
11
 
12
- # Third party libraries.
12
+ # Third party library imports.
13
13
  import jinja2
14
14
 
15
- __date__ = "2022/05/28 16:46:00 hoel"
15
+ __date__ = "2023/03/19 19:37:25 hoel"
16
16
  __author__ = "Berthold Höllmann"
17
17
  __copyright__ = "Copyright © 2017, 2022 by Berthold Höllmann"
18
18
  __credits__ = ["Berthold Höllmann"]
@@ -30,7 +30,6 @@ class Keep(object):
30
30
 
31
31
 
32
32
  class GenPDF(object):
33
-
34
33
  latex_jinja_env = jinja2.Environment(
35
34
  block_start_string=r"\BLOCK{",
36
35
  block_end_string="}",
@@ -64,7 +63,6 @@ class GenPDF(object):
64
63
  now += one_day
65
64
 
66
65
  def __call__(self, start_date=None, end_date=None):
67
-
68
66
  template = self.latex_jinja_env.get_template("book.tex")
69
67
  gen_dates = self.gen_dates(start_date, end_date)
70
68
  return template.render(
@@ -5,7 +5,7 @@
5
5
 
6
6
  from __future__ import annotations, generator_stop
7
7
 
8
- # Standard libraries.
8
+ # Standard library imports.
9
9
  import os
10
10
  import sys
11
11
  import stat
@@ -20,14 +20,14 @@ import configparser
20
20
  from urllib import request
21
21
  from pathlib import Path
22
22
 
23
- # Third party libraries.
23
+ # Third party library imports.
24
24
  from selenium import webdriver
25
25
  from lxml.html import fromstring
26
26
  from selenium.webdriver.common import action_chains
27
27
  from selenium.webdriver.common.keys import Keys
28
28
  from selenium.webdriver.chrome.options import Options
29
29
 
30
- __date__ = "2022/07/18 17:24:59 hoel"
30
+ __date__ = "2023/03/19 19:37:43 hoel"
31
31
  __author__ = "Berthold Höllmann"
32
32
  __copyright__ = "Copyright © 2011-2017 by Berthold Höllmann"
33
33
  __credits__ = ["Berthold Höllmann"]
@@ -39,13 +39,11 @@ TOUCH_FMT = "%Y%m%d0300"
39
39
 
40
40
 
41
41
  class SeleniumSingleton(object):
42
-
43
42
  __instance = None
44
43
 
45
44
  def __init__(self):
46
45
  """Virtually private constructor."""
47
46
  if SeleniumSingleton.__instance is None:
48
-
49
47
  driverpath = None
50
48
  for path in [
51
49
  Path(i)
@@ -102,12 +100,11 @@ class SeleniumSingleton(object):
102
100
  SeleniumSingleton()
103
101
  return SeleniumSingleton.__instance
104
102
 
105
- def __delete__(self):
103
+ def __del__(self):
106
104
  self.driver.close()
107
105
 
108
106
 
109
107
  class SaveState(object):
110
-
111
108
  "Save state information on already downloaded files and dates tried"
112
109
 
113
110
  def __init__(self):
@@ -155,7 +152,6 @@ class GoComics(object):
155
152
  statefile_name = Path("")
156
153
 
157
154
  def __init__(self):
158
-
159
155
  self.start_date = datetime.date(
160
156
  self.start_year, self.start_month, self.start_day
161
157
  )
@@ -202,7 +198,6 @@ class GoComics(object):
202
198
  png_path = Path(f"{cur_date:{self.png_path_fmt}}")
203
199
  pic_id = None
204
200
  if not png_path.is_file():
205
-
206
201
  state.tried[f"{cur_date}"] = (
207
202
  state.tried.get(f"{cur_date}", -1) + 1
208
203
  ) % devidor
@@ -5,13 +5,15 @@
5
5
 
6
6
  from __future__ import annotations, generator_stop
7
7
 
8
- # Standard libraries.
8
+ # Standard library imports.
9
+ import argparse
9
10
  import datetime
10
11
  from pathlib import Path
11
12
 
13
+ # Local library imports.
12
14
  from ..gocomics import GoComics
13
15
 
14
- __date__ = "2022/07/04 23:35:37 hoel"
16
+ __date__ = "2022/08/09 17:38:06 hoel"
15
17
  __author__ = "Berthold Höllmann"
16
18
  __copyright__ = "Copyright © 2017, 2022 by Berthold Höllmann"
17
19
  __credits__ = ["Berthold Höllmann"]
@@ -108,8 +110,27 @@ class Peanuts(GoComics):
108
110
  statefile_name = peanuts_path / "peanuts.statfile"
109
111
 
110
112
 
111
- def main():
113
+ def get_parser() -> argparse.ArgumentParser:
114
+ # First party library imports.
115
+ from berhoel.get_comics import __version__
116
+
117
+ parser = argparse.ArgumentParser(
118
+ prog="get_peanuts", description="Download daily Peanuts comics."
119
+ )
120
+ parser.add_argument(
121
+ "--version",
122
+ "-V",
123
+ action="version",
124
+ version="%(prog)s {version}".format(version=__version__),
125
+ )
126
+ return parser
127
+
128
+
129
+ def main(args=None):
112
130
  "Main Program."
131
+ if args is None:
132
+ args = get_parser().parse_args()
133
+
113
134
  Peanuts()()
114
135
 
115
136
 
@@ -6,13 +6,13 @@ Prepare to delete Wrong Peanut downloads based on MD5.
6
6
 
7
7
  from __future__ import annotations, generator_stop
8
8
 
9
- # Standard libraries.
9
+ # Standard library imports.
10
10
  import sys
11
11
  import hashlib
12
12
  import collections
13
13
  from pathlib import Path
14
14
 
15
- __date__ = "2022/07/18 17:46:10 hoel"
15
+ __date__ = "2022/08/09 17:01:30 hoel"
16
16
  __author__ = "Berthold Höllmann"
17
17
  __copyright__ = "Copyright © 2017, 2022 by Berthold Höllmann"
18
18
  __credits__ = ["Berthold Höllmann"]
@@ -5,11 +5,11 @@
5
5
 
6
6
  from __future__ import annotations, generator_stop
7
7
 
8
- # Standard libraries.
8
+ # Standard library imports.
9
9
  import datetime
10
10
  from pathlib import Path
11
11
 
12
- __date__ = "2022/07/18 17:42:56 hoel"
12
+ __date__ = "2023/03/19 19:38:06 hoel"
13
13
  __author__ = "Berthold Höllmann"
14
14
  __copyright__ = "Copyright © 2017, 2022 by Berthold Höllmann"
15
15
  __credits__ = ["Berthold Höllmann"]
@@ -54,7 +54,7 @@ class PeanutsBook(object):
54
54
  if self.side_weekd == 2 and self.with_sund:
55
55
  out.write("\\clearpage\n")
56
56
  self.side_weekd = 1
57
- for (func, path, date) in self.days:
57
+ for func, path, date in self.days:
58
58
  self.graphicspath(out, path)
59
59
  func(out, path.name, date)
60
60
  if self.with_sund or side_weekd == 2:
@@ -0,0 +1,51 @@
1
+ #! /usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """Tests for get_comics.
4
+ """
5
+
6
+ # Standard library imports.
7
+ from pathlib import Path
8
+
9
+ # Third party library imports.
10
+ import tomli
11
+ import pytest
12
+
13
+ # First party library imports.
14
+ from berhoel.get_comics import __version__
15
+
16
+ __date__ = "2022/08/09 17:51:27 Berthold Höllmann"
17
+ __author__ = "Berthold Höllmann"
18
+ __copyright__ = "Copyright © 2022 by Berthold Höllmann"
19
+ __credits__ = ["Berthold Höllmann"]
20
+ __maintainer__ = "Berthold Höllmann"
21
+ __email__ = "berhoel@gmail.com"
22
+
23
+
24
+ @pytest.fixture
25
+ def base_path():
26
+ base_path = Path(__file__).parent
27
+ while not (base_path / "pyproject.toml").is_file():
28
+ base_path = base_path.parent
29
+ return base_path
30
+
31
+
32
+ @pytest.fixture
33
+ def config(base_path: Path):
34
+ return base_path / "pyproject.toml"
35
+
36
+
37
+ @pytest.fixture
38
+ def toml(config: Path):
39
+ return tomli.load(config.open("rb"))
40
+
41
+
42
+ def test_version(toml):
43
+ """Testing for consistent version number."""
44
+ assert __version__ == toml["tool"]["poetry"]["version"]
45
+
46
+
47
+ # Local Variables:
48
+ # mode: python
49
+ # compile-command: "poetry run tox"
50
+ # time-stamp-pattern: "30/__date__ = \"%Y/%02m/%02d %02H:%02M:%02S %L\""
51
+ # End:
@@ -0,0 +1,102 @@
1
+ [tool.poetry]
2
+ name = "pyGetComics"
3
+ version = "1.3.1"
4
+
5
+ description = "Download various daily comics."
6
+
7
+ packages = [
8
+ { include = "berhoel" },
9
+ ]
10
+
11
+ authors = ["Berthold Höllmann <berhoel@gmail.com>"]
12
+ license = "BSD-2-Clause"
13
+
14
+ repository = "https://gitlab.com/berhoel/python/pyGetComics.git"
15
+
16
+ readme = "README.rst"
17
+
18
+ classifiers =[
19
+ "Development Status :: 4 - Beta",
20
+ "License :: OSI Approved :: BSD License",
21
+ "Programming Language :: Python",
22
+ "Programming Language :: Python :: Implementation :: CPython",
23
+ "Operating System :: OS Independent"
24
+ ]
25
+
26
+ [tool.poetry.dependencies]
27
+ python = "^3.9"
28
+ Pillow = ">8.0.0"
29
+ lxml = ">4.5.0"
30
+ requests = ">2.23.0"
31
+ jinja2 = ">3.0.0"
32
+ selenium = ">=4.7.2"
33
+
34
+ [tool.poetry.dev-dependencies]
35
+ black = "*"
36
+ flake8 = "^4.0.0"
37
+ pdbpp = "*"
38
+ tox = "*"
39
+ pytest = "*"
40
+ pytest-benchmark = "*"
41
+ pytest-black = "*"
42
+ pytest-cache = "*"
43
+ pytest-cov = "*"
44
+ pytest-env = "*"
45
+ pytest-flake8 = "*"
46
+ pytest-isort = "*"
47
+ pytest-mock = "*"
48
+ pytest-runner = "*"
49
+ pytest-sugar = "*"
50
+ isort = "*"
51
+ rope = "*"
52
+ pylint = "*"
53
+ pylint-common = "*"
54
+ pylint-plugin-utils = "*"
55
+ bhoelhelper = ">=1.3.0"
56
+ berhoel-sphinx-settings = {git = "https://gitlab.com/berhoel/python/berhoel-sphinx-settings.git", rev = "main"}
57
+ tomli = "*"
58
+ sphinx-argparse-cli = "*"
59
+
60
+ [tool.berhoel.helper.set_version]
61
+ version_files = ["berhoel/get_comics/_version.py"]
62
+
63
+ [tool.poetry.scripts]
64
+ get_comics = 'berhoel.get_comics:main'
65
+ get_peanuts = 'berhoel.get_comics.peanuts:main'
66
+ get_garfield = 'berhoel.get_comics.garfield:main'
67
+
68
+ [tool.isort]
69
+ multi_line_output = 3
70
+ dedup_headings = true
71
+ include_trailing_comma = true
72
+ indent = ' '
73
+ float_to_top = true
74
+ namespace_packages = ['berhoel']
75
+ force_grid_wrap = 0
76
+ balanced_wrapping = true
77
+ use_parentheses = true
78
+ length_sort = true
79
+ line_length = 88
80
+ combine_as_imports = true
81
+ sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
82
+ import_heading_stdlib = 'Standard library imports.'
83
+ import_heading_thirdparty = 'Third party library imports.'
84
+ import_heading_firstparty = 'First party library imports.'
85
+ import_heading_localfolder = 'Local library imports.'
86
+ default_section = "THIRDPARTY"
87
+ known_first_party = ["berhoel"]
88
+ known_third_party = [
89
+ "pytest",
90
+ ]
91
+
92
+ [tool.pytest.ini_options]
93
+ minversion = "7.0"
94
+ addopts = "--doctest-modules --ff --pdb -s --cov=berhoel --cov-report=term --cov-report=html --cov-branch --isort --black --flake8"
95
+ testpaths = ["berhoel"]
96
+
97
+ [flake8]
98
+ max-line-length = 88
99
+
100
+ [build-system]
101
+ requires = ["poetry>=0.12"]
102
+ build-backend = "poetry.masonry.api"
@@ -1,35 +0,0 @@
1
- #! /usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
- """Download various daily comics.
4
- """
5
-
6
- from __future__ import annotations, generator_stop
7
-
8
- from . import dilbert, peanuts, garfield
9
-
10
- __date__ = "2022/05/28 16:44:35 hoel"
11
- __author__ = "Berthold Höllmann"
12
- __copyright__ = "Copyright © 2017, 2022 by Berthold Höllmann"
13
- __credits__ = ["Berthold Höllmann"]
14
- __maintainer__ = "Berthold Höllmann"
15
- __email__ = "berhoel@gmail.com"
16
-
17
-
18
- def main():
19
- """Get all supported comics.
20
- """
21
- print("Get Dilbert.")
22
- dilbert.main()
23
- print("Get Peanuts.")
24
- peanuts.main()
25
- print("Get Garfield.")
26
- garfield.main()
27
-
28
- if __name__ == '__main__':
29
- main()
30
-
31
- # Local Variables:
32
- # mode: python
33
- # compile-command: "cd ../../ && python setup.py test"
34
- # time-stamp-pattern: "30/__date__ = \"%:y/%02m/%02d %02H:%02M:%02S %u\""
35
- # End:
@@ -1,116 +0,0 @@
1
- #! /usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
- """Download Dilberts since Apr 16, 1989.
4
- """
5
-
6
- from __future__ import annotations, generator_stop
7
-
8
- # Standard libraries.
9
- import os
10
- import sys
11
- import stat
12
- import os.path
13
- import datetime
14
- import subprocess
15
- from pathlib import Path
16
-
17
- # Third party libraries.
18
- import requests
19
- from PIL import ImageFile
20
- from lxml.html import fromstring
21
-
22
- from . import day_get
23
-
24
- __date__ = "2022/07/18 17:44:12 hoel"
25
- __author__ = "Berthold Höllmann"
26
- __copyright__ = "Copyright © 2011, 2022 by Berthold Höllmann"
27
- __credits__ = ["Berthold Höllmann"]
28
- __maintainer__ = "Berthold Höllmann"
29
- __email__ = "berhoel@gmail.com"
30
-
31
- START_YEAR = 1989
32
- START_MONTH = 4
33
- START_DAY = 16
34
-
35
- START_DATE = datetime.date(START_YEAR, START_MONTH, START_DAY)
36
-
37
- DELTA = datetime.timedelta(days=1)
38
-
39
- PNG_PATH_FMT = str(Path.home() / "Bilder" / "Dilbert" / "%Y" / "%m" / "%d.png")
40
- TOUCH_FMT = "%Y%m%d0300"
41
- URL_FMT = "http://dilbert.com/strip/%Y-%m-%d"
42
-
43
-
44
- def retr_gif(url):
45
- doc = fromstring(requests.get(url).content)
46
- url = doc.xpath(".//img[@class='img-responsive img-comic']")[0].get("src")
47
- if url.startswith("//"):
48
- url = f"https:{url}"
49
- return requests.get(url).content
50
-
51
-
52
- def mk_dir_tree(path):
53
- """Generate directory including missing upper directories."""
54
- if not path.is_dir():
55
- mode = (
56
- stat.S_ISGID
57
- | stat.S_IRWXU
58
- | stat.S_IRGRP
59
- | stat.S_IXGRP
60
- | stat.S_IROTH
61
- | stat.S_IXOTH
62
- )
63
- path.mkdir(mode=mode, parents=True)
64
- path.chmod(mode)
65
-
66
-
67
- def main():
68
- """Main routine."""
69
- cur_date = datetime.date.today()
70
-
71
- mode = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH
72
-
73
- cnt = 100
74
-
75
- while cur_date >= START_DATE:
76
- png_path = Path(f"{cur_date:{PNG_PATH_FMT}}")
77
- try:
78
- if not png_path.is_file():
79
-
80
- cnt -= 1
81
-
82
- mk_dir_tree(png_path.parent)
83
- p = ImageFile.Parser()
84
- p.feed(retr_gif(f"{cur_date:{URL_FMT}}"))
85
- im = p.close()
86
-
87
- im.save(png_path)
88
-
89
- os.chmod(png_path, mode)
90
-
91
- print(png_path, end=" ")
92
-
93
- process = subprocess.Popen(
94
- f"touch -t {cur_date:{TOUCH_FMT}} {png_path}", shell=True
95
- )
96
- os.waitpid(process.pid, 0)
97
- print(day_get.DilbertPdf(cur_date.year, cur_date.month, cur_date.day)())
98
- except IOError:
99
- print(
100
- f"*** Failed to download {cur_date:{URL_FMT}}.",
101
- file=sys.stderr,
102
- )
103
-
104
- cur_date -= DELTA
105
- if cnt < 0:
106
- break
107
-
108
-
109
- if __name__ == "__main__":
110
- main()
111
-
112
- # Local Variables:
113
- # mode: python
114
- # compile-command: "cd ../../../ && python setup.py test"
115
- # time-stamp-pattern: "30/__date__ = \"%:y/%02m/%02d %02H:%02M:%02S %u\""
116
- # End:
@@ -1,87 +0,0 @@
1
- #! /usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
- """Generate pdf from Dilbert png.
4
- """
5
-
6
- from __future__ import annotations, generator_stop
7
-
8
- # Standard libraries.
9
- import sys
10
- import subprocess
11
- from string import Template
12
- from pathlib import Path
13
-
14
- __date__ = "2022/05/28 17:17:10 hoel"
15
- __author__ = "Berthold Höllmann"
16
- __copyright__ = "Copyright © 2012, 2022 by Berthold Höllmann"
17
- __credits__ = ["Berthold Höllmann"]
18
- __maintainer__ = "Berthold Höllmann"
19
- __email__ = "berhoel@gmail.com"
20
-
21
-
22
- PATH = Path.home() / "Bilder" / "Dilbert"
23
-
24
-
25
- def latex(f_name):
26
- """lualatex --jobname='today' '\nonstopmode\input{today.tex}'"""
27
- for _ in range(3):
28
- pipe = subprocess.Popen(
29
- [
30
- "lualatex",
31
- f"--jobname={f_name}",
32
- rf"\nonstopmode\input{{{f_name}.tex}}",
33
- ],
34
- stdout=subprocess.PIPE,
35
- cwd=PATH,
36
- ).stdout
37
- pipe.read()
38
- (Path(PATH) / (f"{f_name}.log")).unlink()
39
- (Path(PATH) / (f"{f_name}.aux")).unlink()
40
- (Path(PATH) / (f"{f_name}.tex")).unlink()
41
-
42
-
43
- class DilbertPdf(object):
44
-
45
- """
46
- >>> tmp = DilbertPdf(2012, 3, 1)
47
- >>> tmp.year
48
- 2012
49
- >>> tmp.month
50
- 03
51
- >>> tmp.day
52
- 01"""
53
-
54
- def __init__(self, year, month, day):
55
- self.data = dict(year=f"{year:d}", month=f"{month:02d}", day=f"{day:02d}")
56
- self.template = Template(self.loadTemplate())
57
-
58
- @staticmethod
59
- def loadTemplate():
60
- """Load template from file."""
61
- template_path = Path(__file__).with_name("template.tex")
62
- return template_path.open("r").read()
63
-
64
- def __call__(self):
65
- f_name = Template("Daily_Dilbert_$year-$month-$day").substitute(self.data)
66
-
67
- with (PATH / (f"{f_name}.tex")).open("w") as out_f:
68
- out_f.write(self.template.substitute(self.data))
69
-
70
- latex(f_name)
71
-
72
- return (PATH / f_name).with_suffix(".pdf")
73
-
74
-
75
- if __name__ == "__main__":
76
- if len(sys.argv) == 4:
77
- YEAR, MONTH, DAY = [int(i) for i in sys.argv[1:]]
78
- else:
79
- YEAR, MONTH, DAY = (2012, 3, 14)
80
- print(DilbertPdf(YEAR, MONTH, DAY)())
81
-
82
-
83
- # Local Variables:
84
- # mode: python
85
- # compile-command: "cd ../../../ && python setup.py test"
86
- # time-stamp-pattern: "30/__date__ = \"%:y/%02m/%02d %02H:%02M:%02S %u\""
87
- # End:
@@ -1,162 +0,0 @@
1
- #! /usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
- """Generate Book of all Dilbert comics from images.
4
- """
5
-
6
- from __future__ import annotations, generator_stop
7
-
8
- # Standard libraries.
9
- import datetime
10
- from pathlib import Path
11
-
12
- __date__ = "2022/07/18 17:40:37 hoel"
13
- __author__ = "Berthold Höllmann"
14
- __copyright__ = "Copyright © 2011, 2022 by Berthold Höllmann"
15
- __credits__ = ["Berthold Höllmann"]
16
- __maintainer__ = "Berthold Höllmann"
17
- __email__ = "berhoel@gmail.com"
18
-
19
- START_YEAR = 1989
20
- START_MONTH = 4
21
- START_DAY = 16
22
-
23
- START_DATE = datetime.date(START_YEAR, START_MONTH, START_DAY)
24
- TODAY = datetime.date.today()
25
-
26
- DELTA = datetime.timedelta(days=1)
27
-
28
- PATH_FMT = Path("%Y") / "%m" / "%d"
29
-
30
-
31
- class DilbertBook(object):
32
- """Generate LaTeX file for Dilbert comic book."""
33
-
34
- def __init__(self, fname):
35
- self.cur_date = START_DATE
36
- self.out = file(fname, "w")
37
- self.grpath = None
38
- self.outp_done = False
39
-
40
- def run(self):
41
- """Do the actual processing."""
42
- self.write_prologue()
43
-
44
- while self.cur_date <= TODAY:
45
- self.wr_image(self.cur_date)
46
- if self.cur_date.isoweekday() == 7 and self.outp_done:
47
- self.outp_done = False
48
- self.out.write("\\clearpage\n")
49
-
50
- self.cur_date += DELTA
51
-
52
- self.write_epilog()
53
-
54
- def write_prologue(self):
55
- """Write LaTeX prologue."""
56
- self.out.write(
57
- r"""
58
- \documentclass[a4paper,landscape]{book}
59
- \usepackage{graphicx}
60
- \usepackage{textpos}
61
- \usepackage[textwidth=277.0mm,textheight=189.9mm,headsep=1mm]{geometry}
62
- \makeatletter
63
- %\g@addto@macro\Gin@extensions{,.gif}
64
- %\makeatother
65
- %\DeclareGraphicsRule{.gif}{png}{.png}{%
66
- % `convert '#1' `dirname '#1'`/`basename '#1' .gif`-gif-converted-to.png%
67
- %}
68
- \TPGrid[12mm,12mm]{2}{4}
69
- \setlength{\parindent}{0pt}
70
- \usepackage{fontspec}
71
- \setmainfont{Linux Libertine O}
72
- \begin{document}
73
- """
74
- )
75
-
76
- def wr_image(self, date):
77
- """Write information for including image."""
78
- path = Path(f"{date:{PATH_FMT}}")
79
- if path.with_suffix(".png").is_file():
80
- self.graphicspath(path)
81
- weekday = date.isoweekday()
82
- {
83
- 1: self.do_mo,
84
- 2: self.do_di,
85
- 3: self.do_mi,
86
- 4: self.do_do,
87
- 5: self.do_fr,
88
- 6: self.do_sa,
89
- 7: self.do_so,
90
- }[weekday](path.name)
91
- self.outp_done = True
92
-
93
- def graphicspath(self, path):
94
- """Write appropriate Graphicspath information."""
95
- grpath = path.parent()
96
- if grpath != self.grpath:
97
- self.out.write(f"\\graphicspath{{{{{grpath}/}}}} \n")
98
- self.grpath = grpath
99
-
100
- def do_mo(self, fname):
101
- "Place Monday figure."
102
- self.place_img(1, 1, fname, "Mo")
103
-
104
- def do_di(self, fname):
105
- "Place Tuesday figure."
106
- self.place_img(1, 2, fname, "Di")
107
-
108
- def do_mi(self, fname):
109
- "Place Wednesday figure."
110
- self.place_img(1, 3, fname, "Mi")
111
-
112
- def do_do(self, fname):
113
- "Place Thursday figure."
114
- self.place_img(1, 4, fname, "Do")
115
-
116
- def do_fr(self, fname):
117
- "Place Friday figure."
118
- self.place_img(2, 1, fname, "Fr")
119
-
120
- def do_sa(self, fname):
121
- "Place Saturday figure."
122
- self.place_img(2, 2, fname, "Sa")
123
-
124
- def do_so(self, fname):
125
- "Place Sunday figure."
126
- self.place_img(2, 3, fname, "So")
127
-
128
- def place_img(self, x, y, fname, dummy):
129
- "Place image in grid."
130
- self.out.write(
131
- f"""\
132
- \\begin{{textblock}}{{1}}({x-1},{y-1})
133
- {self.cur_date:%a %d. %B %Y}\\par
134
- \\centering%%
135
- \\includegraphics[width=.95\\linewidth]{{{fname}}}
136
- \\end{{textblock}}
137
- """
138
- )
139
-
140
- def write_epilog(self):
141
- "Write LaTeX epilogue."
142
- self.out.write(
143
- r"""
144
- \end{document}
145
- """
146
- )
147
-
148
-
149
- def main():
150
- "Main processing"
151
- book = DilbertBook(fname="Dilbert_book.tex")
152
- book.run()
153
-
154
-
155
- if __name__ == "__main__":
156
- main()
157
-
158
- # Local Variables:
159
- # mode: python
160
- # compile-command: "cd ../../../ && python setup.py test"
161
- # time-stamp-pattern: "30/__date__ = \"%:y/%02m/%02d %02H:%02M:%02S %u\""
162
- # End:
@@ -1,41 +0,0 @@
1
-
2
- \documentclass[a4paper]{scrartcl}
3
-
4
- \usepackage[left=5mm,right=5mm,%
5
- top=15mm,bottom=15mm,%
6
- landscape,%
7
- %verbose=true,showframe,%
8
- nohead,nofoot]{geometry}
9
-
10
- \usepackage{graphicx}
11
- \usepackage{tabularx,array}
12
-
13
- \pagestyle{empty}
14
-
15
- \begin{document}
16
-
17
- \section*{Daily Dilbert $year-$month-$day}
18
-
19
- \includegraphics[width=\linewidth]{$year/$month/$day}
20
-
21
- \subsection*{Umlauf}
22
- \label{sec:umlauf}
23
-
24
- \begin{center}
25
- \begin{tabularx}{\linewidth}{*3{|>{\bfseries}l|X|}}
26
- \firsthline
27
- Hoel&&SMt&&MLie&\\[.6cm]
28
- \hline
29
- Ca&& GPo&& WiG&\\[.6cm]
30
- \lasthline
31
- \end{tabularx}
32
- \end{center}
33
-
34
- \end{document}
35
-
36
- %%% Local Variables:
37
- %%% mode: latex
38
- %%% TeX-engine: luatex
39
- %%% TeX-PDF-mode: true
40
- %%% TeX-master: t
41
- %%% End:
@@ -1,57 +0,0 @@
1
- [tool.poetry]
2
- name = "pyGetComics"
3
- version = "1.2.5"
4
-
5
- description = "Download various daily comics."
6
-
7
- packages=[
8
- { include = "berhoel" },
9
- ]
10
-
11
- authors = ["Berthold Höllmann <berhoel@gmail.com>"]
12
- license = "BSD-2-Clause"
13
-
14
- repository = "https://gitlab.com/berhoel/python/pyGetComics.git"
15
-
16
- readme = "README.rst"
17
-
18
- classifiers =[
19
- "Development Status :: 4 - Beta",
20
- "License :: OSI Approved :: BSD License",
21
- "Programming Language :: Python",
22
- "Programming Language :: Python :: Implementation :: CPython",
23
- "Operating System :: OS Independent"
24
- ]
25
-
26
- [tool.poetry.dependencies]
27
- python = "^3.8"
28
- Pillow = ">8.0.0"
29
- lxml = ">4.5.0"
30
- requests = ">2.23.0"
31
- jinja2 = ">3.0.0"
32
- selenium = ">4.0.0"
33
-
34
- [tool.poetry.dev-dependencies]
35
- tox = ">3.14.5"
36
- pytest = ">5.4.1"
37
-
38
- [tool.poetry.scripts]
39
- get_comics = 'berhoel.get_comics:main'
40
- get_dilbert = 'berhoel.get_comics.dilbert:main'
41
- get_peanuts = 'berhoel.get_comics.peanuts:main'
42
- get_garfield = 'berhoel.get_comics.garfield:main'
43
-
44
- [tool.isort]
45
- multi_line_output = 5
46
- include_trailing_comma = true
47
- indent = ' '
48
- length_sort = true
49
- line_length = 88
50
- balanced_wrapping = true
51
- import_heading_stdlib = 'Standard libraries.'
52
- import_heading_thirdparty = 'Third party libraries.'
53
- known_first_party = ['berhoel']
54
-
55
- [build-system]
56
- requires = ["poetry>=0.12"]
57
- build-backend = "poetry.masonry.api"
@@ -1,47 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- from setuptools import setup
3
-
4
- packages = \
5
- ['berhoel',
6
- 'berhoel.get_comics',
7
- 'berhoel.get_comics.dilbert',
8
- 'berhoel.get_comics.garfield',
9
- 'berhoel.get_comics.gen_pdf',
10
- 'berhoel.get_comics.gocomics',
11
- 'berhoel.get_comics.peanuts']
12
-
13
- package_data = \
14
- {'': ['*'], 'berhoel.get_comics.gen_pdf': ['template/*']}
15
-
16
- install_requires = \
17
- ['Pillow>8.0.0',
18
- 'jinja2>3.0.0',
19
- 'lxml>4.5.0',
20
- 'requests>2.23.0',
21
- 'selenium>4.0.0']
22
-
23
- entry_points = \
24
- {'console_scripts': ['get_comics = berhoel.get_comics:main',
25
- 'get_dilbert = berhoel.get_comics.dilbert:main',
26
- 'get_garfield = berhoel.get_comics.garfield:main',
27
- 'get_peanuts = berhoel.get_comics.peanuts:main']}
28
-
29
- setup_kwargs = {
30
- 'name': 'pygetcomics',
31
- 'version': '1.2.5',
32
- 'description': 'Download various daily comics.',
33
- 'long_description': '=============\n pyGetComics\n=============\n\nDownload various daily comics.\n',
34
- 'author': 'Berthold Höllmann',
35
- 'author_email': 'berhoel@gmail.com',
36
- 'maintainer': None,
37
- 'maintainer_email': None,
38
- 'url': 'https://gitlab.com/berhoel/python/pyGetComics.git',
39
- 'packages': packages,
40
- 'package_data': package_data,
41
- 'install_requires': install_requires,
42
- 'entry_points': entry_points,
43
- 'python_requires': '>=3.8,<4.0',
44
- }
45
-
46
-
47
- setup(**setup_kwargs)
File without changes
File without changes