from random import choice from os.path import join from PIL import Image, ImageDraw, ImageFont zodiac_signs = [ "Belier", "Cancer", "Balance", "Capricorne", "Taureau", "Lion", "Scorpion", "Verseau", "Gemeaux", "Vierge", "Sagittaire", "Poissons", ] def generate_horoscope(): horoscope = {} for sign in zodiac_signs: heart = choice(["+++", "++", "+", "-", "- -"]) work = choice(["+++", "++", "+", "-", "- -"]) horoscope[sign] = {"heart": heart, "work": work} return horoscope def create_horoscope_image(horoscope): img_width, img_height = 1050, 450 image = Image.new("RGBA", (img_width, img_height), color=(255, 255, 255, 0)) draw = ImageDraw.Draw(image) font = ImageFont.load_default(24) x, y = 10, 10 for sign, prediction in horoscope.items(): 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 y += 150 return image if __name__ == "__main__": # Generate new horoscope new_horoscope = generate_horoscope() # Create and save the image 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'")