2024-09-28 20:35:08 +02:00
|
|
|
from random import choice
|
|
|
|
from os.path import join
|
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
|
|
|
|
zodiac_signs = [
|
|
|
|
"Belier",
|
|
|
|
"Cancer",
|
|
|
|
"Balance",
|
|
|
|
"Capricorne",
|
2024-09-28 20:49:20 +02:00
|
|
|
"Taureau",
|
|
|
|
"Lion",
|
|
|
|
"Scorpion",
|
2024-09-28 20:35:08 +02:00
|
|
|
"Verseau",
|
2024-09-28 20:49:20 +02:00
|
|
|
"Gemeaux",
|
|
|
|
"Vierge",
|
|
|
|
"Sagittaire",
|
2024-09-28 20:35:08 +02:00
|
|
|
"Poissons",
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def generate_horoscope():
|
|
|
|
horoscope = {}
|
|
|
|
for sign in zodiac_signs:
|
2024-09-28 20:49:20 +02:00
|
|
|
heart = choice(["+++", "++", "+", "-", "- -"])
|
|
|
|
work = choice(["+++", "++", "+", "-", "- -"])
|
2024-09-28 20:35:08 +02:00
|
|
|
horoscope[sign] = {"heart": heart, "work": work}
|
|
|
|
return horoscope
|
|
|
|
|
|
|
|
|
|
|
|
def create_horoscope_image(horoscope):
|
2024-09-28 20:49:20 +02:00
|
|
|
img_width, img_height = 1050, 450
|
|
|
|
image = Image.new("RGBA", (img_width, img_height), color=(255, 255, 255, 0))
|
|
|
|
draw = ImageDraw.Draw(image)
|
2024-09-28 20:35:08 +02:00
|
|
|
|
2024-09-28 20:49:20 +02:00
|
|
|
font = ImageFont.load_default(24)
|
2024-09-28 20:35:08 +02:00
|
|
|
|
2024-09-28 20:49:20 +02:00
|
|
|
x, y = 10, 10
|
2024-09-28 20:35:08 +02:00
|
|
|
for sign, prediction in horoscope.items():
|
2024-09-28 20:49:20 +02:00
|
|
|
sign_image = Image.open(join("images", f"{sign.lower()}.png")).convert("RGBA")
|
|
|
|
sign_image.thumbnail((100, 100))
|
|
|
|
image.paste(sign_image, (x, y), sign_image)
|
|
|
|
|
|
|
|
draw.text((x + 110, y), sign, fill=(0, 0, 0, 255), font=font)
|
|
|
|
draw.text(
|
|
|
|
(x + 110, y + 40),
|
|
|
|
f"♥: {prediction['heart']}",
|
|
|
|
fill=(255, 0, 0, 255),
|
|
|
|
font=font,
|
|
|
|
)
|
|
|
|
draw.text(
|
|
|
|
(x + 110, y + 80),
|
|
|
|
f"💼: {prediction['work']}",
|
|
|
|
fill=(0, 0, 255, 255),
|
|
|
|
font=font,
|
|
|
|
)
|
|
|
|
|
|
|
|
x += 250
|
|
|
|
if x > 900:
|
|
|
|
x = 10
|
2024-09-28 20:35:08 +02:00
|
|
|
y += 150
|
|
|
|
|
|
|
|
return image
|
|
|
|
|
|
|
|
|
2024-09-28 20:49:20 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
# Generate new horoscope
|
|
|
|
new_horoscope = generate_horoscope()
|
2024-09-28 20:35:08 +02:00
|
|
|
|
2024-09-28 20:49:20 +02:00
|
|
|
# Create and save the image
|
|
|
|
horoscope_image = create_horoscope_image(new_horoscope)
|
|
|
|
horoscope_image.save("nouvel_horoscope.png")
|
2024-09-28 20:35:08 +02:00
|
|
|
|
2024-09-28 20:49:20 +02:00
|
|
|
print("Nouvel horoscope généré et sauvegardé sous 'nouvel_horoscope.png'")
|