Skip to content

Commit

Permalink
A few minor changes to appease pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
jochie committed Jul 28, 2024
1 parent 37bd78d commit cf7fecf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
1 change: 0 additions & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ jobs:
run: |
sudo apt-get -q install pylint python3-packaging python3-pil
pip3 install imgkit
- name: Run Pylint
run: make lint
28 changes: 14 additions & 14 deletions compare_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,16 @@ def render_teletekst(fname, content):
# lives, and possibly be wrong there anyway

# Wrap it in the minimally needed HTML
content = '''
content = f'''
<html>
<head>
<style>body { background: #202020; }</style>
<style>body {{ background: #202020; }}</style>
</head>
<body>
<link href="https://cdn.nos.nl/assets/nos-symfony/ceb1651/bundles/nossite/css/teletekst.css" media="all" type="text/css" rel="stylesheet"/>
<pre class="teletekst__content__pre">%s</pre>
<pre class="teletekst__content__pre">{content}</pre>
</body>
</html>''' % (content,)
</html>'''
imgkit.from_string(
content,
fname,
Expand Down Expand Up @@ -198,7 +198,7 @@ def generate_diff_attachment(opts, http, auth, text, timestamp):
"""
img = Image.new('RGB', (385, 440 * 2), "#202020")
fnt = ImageFont.truetype('DejaVuSansMono', FNT_SIZE)
d = ImageDraw.Draw(img)
drawing = ImageDraw.Draw(img)

offset = 0
for line in text.splitlines():
Expand Down Expand Up @@ -228,13 +228,13 @@ def generate_diff_attachment(opts, http, auth, text, timestamp):
color="cyan"
if len(line) == 0:
line = " "
d.text((0, offset), line, fill=color, font=fnt)
drawing.text((0, offset), line, fill=color, font=fnt)
if Version(PIL.__version__) >= Version("10.0.0"):
# left, top, right, bottom
(_, _, _, bottom) = d.textbbox((5, offset), line, font=fnt)
(_, _, _, bottom) = drawing.textbbox((5, offset), line, font=fnt)
offset = bottom + 1
else:
# width, height = d.textsize(line, fnt)
# width, height = drawing.textsize(line, fnt)
# print(f"Width x Height = {width} x {height}")
offset += FNT_SIZE + 3
if opts.debug:
Expand All @@ -243,13 +243,13 @@ def generate_diff_attachment(opts, http, auth, text, timestamp):
img = img.crop((0, 0, 385, offset))
else:
img = img.crop((0, 0, 385, 440))
s = io.BytesIO()
img.save(s, 'png')
img_data = s.getvalue()
img_stream = io.BytesIO()
img.save(img_stream, 'png')
img_data = img_stream.getvalue()
result = http.request("POST", f"https://{opts.server}/api/v2/media",
headers=auth,
fields={
"file": ("tt/diff.png", img_data),
"file": ("diff.png", img_data),
"description": f"[{timestamp}]\n\n{text}",
"focus": "0.0,1.0"
})
Expand All @@ -272,8 +272,8 @@ def generate_attachment(opts, http, auth,
render_teletekst(file_name, raw_content)

# Prepare the attachment:
with open(file_name, "rb") as fp:
file_data = fp.read()
with open(file_name, "rb") as page_fd:
file_data = page_fd.read()
result = http.request("POST", f"https://{opts.server}/api/v2/media",
headers=auth,
fields={
Expand Down
9 changes: 6 additions & 3 deletions walk_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ def handle_data(self, data):
self.text_collected += data

def error(self, message):
print(f"Parsing error: {message}")
"""
Implement abstract error() function
"""
print(f"[{self}] Parsing error: {message}")


def parse_headlines(text):
Expand Down Expand Up @@ -100,8 +103,8 @@ def fetch_page(page, http, stamp, is_index):

try:
page_json = json.loads(result.data)
except ValueError as e:
print(f"Error parsing JSON: {e}")
except ValueError as err:
print(f"Error parsing JSON: {err}")
print(result.data)
sys.exit(1)

Expand Down

0 comments on commit cf7fecf

Please sign in to comment.