73 lines
1.7 KiB
Python
73 lines
1.7 KiB
Python
|
from random import choice
|
||
|
from os.path import join
|
||
|
from PIL import Image, ImageDraw, ImageFont
|
||
|
|
||
|
zodiac_signs = [
|
||
|
"Belier",
|
||
|
"Taureau",
|
||
|
"Gemeaux",
|
||
|
"Cancer",
|
||
|
"Lion",
|
||
|
"Vierge",
|
||
|
"Balance",
|
||
|
"Scorpion",
|
||
|
"Sagittaire",
|
||
|
"Capricorne",
|
||
|
"Verseau",
|
||
|
"Poissons",
|
||
|
]
|
||
|
|
||
|
|
||
|
def generate_horoscope():
|
||
|
horoscope = {}
|
||
|
for sign in zodiac_signs:
|
||
|
heart = choice(["+", "++", "+++", "-", "--"])
|
||
|
work = choice(["+", "++", "+++", "-", "--"])
|
||
|
|
||
|
if heart.count("+") > 3:
|
||
|
heart = "+++"
|
||
|
elif heart.count("-") > 2:
|
||
|
heart = "--"
|
||
|
|
||
|
if work.count("+") > 3:
|
||
|
work = "+++"
|
||
|
elif work.count("-") > 2:
|
||
|
work = "--"
|
||
|
|
||
|
horoscope[sign] = {"heart": heart, "work": work}
|
||
|
|
||
|
return horoscope
|
||
|
|
||
|
|
||
|
def create_horoscope_image(horoscope):
|
||
|
img_width, img_height = 800, 600
|
||
|
image = Image.new("RGBA", (img_width, img_height), color="white")
|
||
|
draw = ImageDraw.Draw(image, "RGBA")
|
||
|
|
||
|
font = ImageFont.load_default()
|
||
|
|
||
|
x, y = 20, 20
|
||
|
for sign, prediction in horoscope.items():
|
||
|
sign_image = Image.open(join("images", f"{sign.lower()}.png"))
|
||
|
image.paste(sign_image, (x, y))
|
||
|
|
||
|
draw.text((x, y), sign, fill="black", font=font)
|
||
|
draw.text((x, y + 30), f"♥: {prediction['heart']}", fill="red", font=font)
|
||
|
draw.text((x, y + 60), f"💼: {prediction['work']}", fill="blue", font=font)
|
||
|
|
||
|
x += 200
|
||
|
if x > 600:
|
||
|
x = 20
|
||
|
y += 150
|
||
|
|
||
|
return image
|
||
|
|
||
|
|
||
|
new_horoscope = generate_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'")
|