Compare commits
6 commits
Author | SHA1 | Date | |
---|---|---|---|
89af320a66 | |||
a61cc02c42 | |||
0a790e8a75 | |||
a19353f869 | |||
c00060af2d | |||
4f0232fe42 |
3 changed files with 58 additions and 19 deletions
|
@ -2,8 +2,7 @@ name: Upload release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
branches: [main]
|
||||||
- "*"
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
@ -18,4 +17,6 @@ jobs:
|
||||||
uses: akkuman/gitea-release-action@v1
|
uses: akkuman/gitea-release-action@v1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.TOKEN }}
|
token: ${{ secrets.TOKEN }}
|
||||||
|
name: Latest version
|
||||||
|
tag_name: latest
|
||||||
files: horoscope.bat
|
files: horoscope.bat
|
||||||
|
|
|
@ -16,6 +16,9 @@ CLS
|
||||||
IF ERRORLEVEL 1 (
|
IF ERRORLEVEL 1 (
|
||||||
ECHO Installation of Python not found, installation...
|
ECHO Installation of Python not found, installation...
|
||||||
|
|
||||||
|
:: Accept Winget ToT
|
||||||
|
ECHO Y | winget list >NUL
|
||||||
|
|
||||||
:: Install Python 3.12 from MS Store
|
:: Install Python 3.12 from MS Store
|
||||||
ECHO Y | winget install -he 9NCVDN91XZQP
|
ECHO Y | winget install -he 9NCVDN91XZQP
|
||||||
|
|
||||||
|
|
69
main.py
69
main.py
|
@ -1,10 +1,11 @@
|
||||||
from os import makedirs
|
from os import makedirs
|
||||||
from os.path import join
|
from os.path import isfile, join
|
||||||
|
from pathlib import Path
|
||||||
from random import choice
|
from random import choice
|
||||||
from sys import argv
|
from sys import argv
|
||||||
from urllib.request import urlretrieve
|
from urllib.request import urlretrieve
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageEnhance, ImageFilter, ImageFont
|
||||||
|
|
||||||
zodiac_signs = [
|
zodiac_signs = [
|
||||||
"Belier",
|
"Belier",
|
||||||
|
@ -22,6 +23,9 @@ zodiac_signs = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
image_dir = join(Path(argv[0]).parent.resolve(), "images")
|
||||||
|
|
||||||
|
|
||||||
def generate_horoscope() -> dict[str, dict[str, str]]:
|
def generate_horoscope() -> dict[str, dict[str, str]]:
|
||||||
"""Generate horoscope predictions"""
|
"""Generate horoscope predictions"""
|
||||||
horoscope = {}
|
horoscope = {}
|
||||||
|
@ -33,8 +37,36 @@ def generate_horoscope() -> dict[str, dict[str, str]]:
|
||||||
|
|
||||||
|
|
||||||
def get_path(image: str):
|
def get_path(image: str):
|
||||||
"""Return the path of the image"""
|
"""Return the path of an image"""
|
||||||
return join("images", f"{image.lower()}.png")
|
return join(image_dir, f"{image.lower()}.png")
|
||||||
|
|
||||||
|
|
||||||
|
def get_sign_image(image: str):
|
||||||
|
"""Get sign image"""
|
||||||
|
sign_image = Image.open(get_path(image)).convert("RGBA")
|
||||||
|
|
||||||
|
# Add thickness
|
||||||
|
alpha = sign_image.split()[3]
|
||||||
|
bold_mask = alpha.filter(ImageFilter.MaxFilter())
|
||||||
|
sign_image.putalpha(bold_mask)
|
||||||
|
|
||||||
|
# Add contrast
|
||||||
|
enhancer = ImageEnhance.Contrast(sign_image)
|
||||||
|
enhanced_image = enhancer.enhance(2.0)
|
||||||
|
|
||||||
|
enhanced_image.thumbnail((100, 105))
|
||||||
|
return enhanced_image
|
||||||
|
|
||||||
|
|
||||||
|
def vertical_text(text: str, font: ImageFont.ImageFont | ImageFont.FreeTypeFont):
|
||||||
|
"""Image with vertical text"""
|
||||||
|
text_img = Image.new("RGBA", (135, 29), (255, 255, 255, 0))
|
||||||
|
|
||||||
|
text_draw = ImageDraw.Draw(text_img)
|
||||||
|
text_draw.text((0, 0), f"{text:^15}", font=font, fill="black")
|
||||||
|
text_draw = text_img.rotate(90, expand=True)
|
||||||
|
|
||||||
|
return text_draw
|
||||||
|
|
||||||
|
|
||||||
def create_horoscope_image(horoscope: dict[str, dict[str, str]]):
|
def create_horoscope_image(horoscope: dict[str, dict[str, str]]):
|
||||||
|
@ -50,19 +82,15 @@ def create_horoscope_image(horoscope: dict[str, dict[str, str]]):
|
||||||
|
|
||||||
x, y = 10, 10
|
x, y = 10, 10
|
||||||
for sign, prediction in horoscope.items():
|
for sign, prediction in horoscope.items():
|
||||||
sign_image = Image.open(get_path(sign)).convert("RGBA")
|
sign_image = get_sign_image(sign)
|
||||||
sign_image.thumbnail((100, 105))
|
|
||||||
image.paste(sign_image, (x + 20, y), sign_image)
|
image.paste(sign_image, (x + 20, y), sign_image)
|
||||||
|
|
||||||
# Sign text
|
# Sign text
|
||||||
text_img = Image.new("RGBA", (135, 24), (255, 255, 255, 0))
|
text_draw = vertical_text(sign, font_sign)
|
||||||
text_draw = ImageDraw.Draw(text_img)
|
image.paste(text_draw, (x - 12, y - 10), text_draw)
|
||||||
text_draw.text((0, 0), f"{sign:^15}", font=font_sign, fill="black")
|
|
||||||
text_draw = text_img.rotate(90, expand=True)
|
|
||||||
image.paste(text_draw, (x - 10, y - 10), text_draw)
|
|
||||||
|
|
||||||
# Love prediction
|
# Love prediction
|
||||||
love = Image.open(join("images", "love.png")).convert("RGBA")
|
love = Image.open(join(image_dir, "love.png")).convert("RGBA")
|
||||||
love.thumbnail(size_emoji)
|
love.thumbnail(size_emoji)
|
||||||
image.paste(love, (x + 125, y + 20), love)
|
image.paste(love, (x + 125, y + 20), love)
|
||||||
draw.text(
|
draw.text(
|
||||||
|
@ -73,7 +101,7 @@ def create_horoscope_image(horoscope: dict[str, dict[str, str]]):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Work prediction
|
# Work prediction
|
||||||
work = Image.open(join("images", "work.png")).convert("RGBA")
|
work = Image.open(join(image_dir, "work.png")).convert("RGBA")
|
||||||
work.thumbnail(size_emoji)
|
work.thumbnail(size_emoji)
|
||||||
image.paste(work, (x + 125, y + 60), work)
|
image.paste(work, (x + 125, y + 60), work)
|
||||||
draw.text(
|
draw.text(
|
||||||
|
@ -95,9 +123,13 @@ def download_images():
|
||||||
"""Download images from source"""
|
"""Download images from source"""
|
||||||
url = "https://git.mylloon.fr/Anri/Horoscope/raw/branch/main/images/"
|
url = "https://git.mylloon.fr/Anri/Horoscope/raw/branch/main/images/"
|
||||||
|
|
||||||
makedirs("images", exist_ok=True)
|
makedirs(image_dir, exist_ok=True)
|
||||||
for el in zodiac_signs + ["love", "work"]:
|
for el in zodiac_signs + ["love", "work"]:
|
||||||
urlretrieve(url + el.lower() + ".png", get_path(el))
|
path = get_path(el)
|
||||||
|
if not isfile(path):
|
||||||
|
image = el.lower() + ".png"
|
||||||
|
print(f"Download {image}...")
|
||||||
|
urlretrieve(url + image, path)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -105,6 +137,7 @@ if __name__ == "__main__":
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if len(argv) == 2:
|
if len(argv) == 2:
|
||||||
|
print("Fetch missing images...")
|
||||||
download_images()
|
download_images()
|
||||||
|
|
||||||
# Generate new horoscope
|
# Generate new horoscope
|
||||||
|
@ -112,6 +145,8 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
# Create and save the image
|
# Create and save the image
|
||||||
horoscope_image = create_horoscope_image(new_horoscope)
|
horoscope_image = create_horoscope_image(new_horoscope)
|
||||||
horoscope_image.save("nouvel_horoscope.png")
|
|
||||||
|
|
||||||
print("Nouvel horoscope généré et sauvegardé sous 'nouvel_horoscope.png'")
|
png = "nouvel_horoscope.png"
|
||||||
|
horoscope_image.save(png)
|
||||||
|
|
||||||
|
print(f"Nouvel horoscope généré et sauvegardé sous '{png}'")
|
||||||
|
|
Loading…
Reference in a new issue