This commit is contained in:
parent
750b69843f
commit
97b9ea356d
2 changed files with 46 additions and 23 deletions
|
@ -16,8 +16,8 @@ CLS
|
|||
IF ERRORLEVEL 1 (
|
||||
ECHO Installation of Python not found, installation...
|
||||
|
||||
:: Install Python 3.11 from MS Store
|
||||
ECHO Y | winget install -he 9NRWMJP3717K
|
||||
:: Install Python 3.12 from MS Store
|
||||
ECHO Y | winget install -he 9NCVDN91XZQP
|
||||
|
||||
ECHO Download and installation of dependencies...
|
||||
|
||||
|
@ -34,14 +34,11 @@ IF ERRORLEVEL 1 (
|
|||
!py! -m !pipR! >NUL
|
||||
)
|
||||
|
||||
:: Download images under %TEMP%\images
|
||||
REM TODO
|
||||
|
||||
:: Write the program
|
||||
CALL :getLine "::python_beg" "::python_end" > "!tmpFile!"
|
||||
|
||||
:: Run the program
|
||||
PowerShell -Command "Start-Process cmd -Argument '/c START /B python !tmpFile!' -WindowStyle hidden"
|
||||
!py! "!tmpFile!" online
|
||||
EXIT /B
|
||||
|
||||
:getLine <beg str> <end str>
|
||||
|
|
60
main.py
60
main.py
|
@ -1,24 +1,29 @@
|
|||
from random import choice
|
||||
from os import makedirs
|
||||
from os.path import join
|
||||
from random import choice
|
||||
from sys import argv
|
||||
from urllib.request import urlretrieve
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
zodiac_signs = [
|
||||
"Belier",
|
||||
"Cancer",
|
||||
"Balance",
|
||||
"Capricorne",
|
||||
"Taureau",
|
||||
"Lion",
|
||||
"Scorpion",
|
||||
"Verseau",
|
||||
"Gemeaux",
|
||||
"Vierge",
|
||||
"Sagittaire",
|
||||
"Poissons",
|
||||
]
|
||||
|
||||
|
||||
def generate_horoscope() -> dict[str, dict[str, str]]:
|
||||
zodiac_signs = [
|
||||
"Belier",
|
||||
"Cancer",
|
||||
"Balance",
|
||||
"Capricorne",
|
||||
"Taureau",
|
||||
"Lion",
|
||||
"Scorpion",
|
||||
"Verseau",
|
||||
"Gemeaux",
|
||||
"Vierge",
|
||||
"Sagittaire",
|
||||
"Poissons",
|
||||
]
|
||||
|
||||
"""Generate horoscope predictions"""
|
||||
horoscope = {}
|
||||
for sign in zodiac_signs:
|
||||
love = choice(["+++", "++", "+", "-", "- -"])
|
||||
|
@ -27,7 +32,13 @@ def generate_horoscope() -> dict[str, dict[str, str]]:
|
|||
return horoscope
|
||||
|
||||
|
||||
def get_path(image: str):
|
||||
"""Return the path of the image"""
|
||||
return join("images", f"{image.lower()}.png")
|
||||
|
||||
|
||||
def create_horoscope_image(horoscope: dict[str, dict[str, str]]):
|
||||
"""Generate horoscope images"""
|
||||
img_width, img_height = 1200, 425
|
||||
image = Image.new("RGBA", (img_width, img_height), color=(255, 255, 255, 0))
|
||||
draw = ImageDraw.Draw(image)
|
||||
|
@ -39,7 +50,7 @@ def create_horoscope_image(horoscope: dict[str, dict[str, str]]):
|
|||
|
||||
x, y = 10, 10
|
||||
for sign, prediction in horoscope.items():
|
||||
sign_image = Image.open(join("images", f"{sign.lower()}.png")).convert("RGBA")
|
||||
sign_image = Image.open(get_path(sign)).convert("RGBA")
|
||||
sign_image.thumbnail((100, 105))
|
||||
image.paste(sign_image, (x + 20, y), sign_image)
|
||||
|
||||
|
@ -80,7 +91,22 @@ def create_horoscope_image(horoscope: dict[str, dict[str, str]]):
|
|||
return image
|
||||
|
||||
|
||||
def download_images():
|
||||
"""Download images from source"""
|
||||
url = "https://git.mylloon.fr/Anri/Horoscope/raw/branch/main/images/"
|
||||
|
||||
makedirs("images", exist_ok=True)
|
||||
for el in zodiac_signs + ["love", "work"]:
|
||||
urlretrieve(url + el.lower() + ".png", get_path(el))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(argv) > 2 or (len(argv) == 2 and argv[1] != "online"):
|
||||
exit(1)
|
||||
|
||||
if len(argv) == 2:
|
||||
download_images()
|
||||
|
||||
# Generate new horoscope
|
||||
new_horoscope = generate_horoscope()
|
||||
|
||||
|
|
Loading…
Reference in a new issue