Skip to content

Commit

Permalink
Fix day out of range problems
Browse files Browse the repository at this point in the history
  • Loading branch information
ssfdust committed Dec 31, 2023
1 parent 783a0b3 commit 1e4c8b4
Showing 1 changed file with 95 additions and 91 deletions.
186 changes: 95 additions & 91 deletions src/weathercn/paint.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,101 +136,105 @@ def paint(self):
draw.line((118, 216, 118, 366), fill=(122, 109, 109, 250))
draw.line((216, 216, 216, 366), fill=(122, 109, 109, 250))
# ============ day one ======================
draw.text(
(33, 226),
centertxt(self.parser.forecast[0]["date"]),
font=self.dayfont,
)
draw.text(
(33, 244),
centertxt(self.parser.forecast[0]["weekday"]),
font=self.dayfont,
)
self.img.paste(
self.picfinder.capture(self.parser.forecast[0]["dcode"]),
(50, 265),
mask=self.picfinder.capture(self.parser.forecast[0]["dcode"]),
)
draw.text(
(33, 300),
centertxt(format(self.parser.forecast[0]["weather"])),
font=self.dayfont,
)
draw.text(
(33, 320),
centertxt(
"{} ~ {}".format(
self.parser.forecast[0]["high"],
self.parser.forecast[0]["low"],
)
),
font=self.dayfont,
)

if len(self.parser.forecast) >= 1:
draw.text(
(33, 226),
centertxt(self.parser.forecast[0]["date"]),
font=self.dayfont,
)
draw.text(
(33, 244),
centertxt(self.parser.forecast[0]["weekday"]),
font=self.dayfont,
)
self.img.paste(
self.picfinder.capture(self.parser.forecast[0]["dcode"]),
(50, 265),
mask=self.picfinder.capture(self.parser.forecast[0]["dcode"]),
)
draw.text(
(33, 300),
centertxt(format(self.parser.forecast[0]["weather"])),
font=self.dayfont,
)
draw.text(
(33, 320),
centertxt(
"{} ~ {}".format(
self.parser.forecast[0]["high"],
self.parser.forecast[0]["low"],
)
),
font=self.dayfont,
)

# ================= day two ===================================
draw.text(
(33 + 100, 226),
centertxt(self.parser.forecast[1]["date"]),
font=self.dayfont,
)
draw.text(
(33 + 100, 244),
centertxt(self.parser.forecast[1]["weekday"]),
font=self.dayfont,
)
self.img.paste(
self.picfinder.capture(self.parser.forecast[1]["dcode"]),
(50 + 100, 265),
mask=self.picfinder.capture(self.parser.forecast[1]["dcode"]),
)
draw.text(
(33 + 100, 300),
centertxt(format(self.parser.forecast[1]["weather"])),
font=self.dayfont,
)
draw.text(
(33 + 100, 320),
centertxt(
"{} ~ {}".format(
self.parser.forecast[1]["high"],
self.parser.forecast[1]["low"],
)
),
font=self.dayfont,
)
if len(self.parser.forecast) >= 2:
draw.text(
(33 + 100, 226),
centertxt(self.parser.forecast[1]["date"]),
font=self.dayfont,
)
draw.text(
(33 + 100, 244),
centertxt(self.parser.forecast[1]["weekday"]),
font=self.dayfont,
)
self.img.paste(
self.picfinder.capture(self.parser.forecast[1]["dcode"]),
(50 + 100, 265),
mask=self.picfinder.capture(self.parser.forecast[1]["dcode"]),
)
draw.text(
(33 + 100, 300),
centertxt(format(self.parser.forecast[1]["weather"])),
font=self.dayfont,
)
draw.text(
(33 + 100, 320),
centertxt(
"{} ~ {}".format(
self.parser.forecast[1]["high"],
self.parser.forecast[1]["low"],
)
),
font=self.dayfont,
)

# ================== day three ==========================
last_index = len(self.parser.forecast) - 1
draw.text(
(33 + 200, 226),
centertxt(self.parser.forecast[last_index]["date"]),
font=self.dayfont,
)
draw.text(
(33 + 200, 244),
centertxt(self.parser.forecast[last_index]["weekday"]),
font=self.dayfont,
)
self.img.paste(
self.picfinder.capture(self.parser.forecast[last_index]["dcode"]),
(50 + 200, 265),
mask=self.picfinder.capture(self.parser.forecast[last_index]["dcode"]),
)
draw.text(
(33 + 200, 300),
centertxt(format(self.parser.forecast[last_index]["weather"])),
font=self.dayfont,
)
draw.text(
(33 + 200, 320),
centertxt(
"{} ~ {}".format(
self.parser.forecast[last_index]["high"],
self.parser.forecast[last_index]["low"],
)
),
font=self.dayfont,
)
if len(self.parser.forecast) >= 3:
last_index = 2
draw.text(
(33 + 200, 226),
centertxt(self.parser.forecast[last_index]["date"]),
font=self.dayfont,
)
draw.text(
(33 + 200, 244),
centertxt(self.parser.forecast[last_index]["weekday"]),
font=self.dayfont,
)
self.img.paste(
self.picfinder.capture(self.parser.forecast[last_index]["dcode"]),
(50 + 200, 265),
mask=self.picfinder.capture(self.parser.forecast[last_index]["dcode"]),
)
draw.text(
(33 + 200, 300),
centertxt(format(self.parser.forecast[last_index]["weather"])),
font=self.dayfont,
)
draw.text(
(33 + 200, 320),
centertxt(
"{} ~ {}".format(
self.parser.forecast[last_index]["high"],
self.parser.forecast[last_index]["low"],
)
),
font=self.dayfont,
)

def load_icons(self):
"""加载图标"""
Expand Down

0 comments on commit 1e4c8b4

Please sign in to comment.