Skip to content

Commit

Permalink
PostBot: Initial integration of banner generation [skip ci]
Browse files Browse the repository at this point in the history
Change-Id: I80d9386908bb9f3724c6bf4a1f475a324777f822
Signed-off-by: PrajjuS <[email protected]>
  • Loading branch information
PrajjuS committed Sep 26, 2024
1 parent 79d7d3c commit c60ab0a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
22 changes: 22 additions & 0 deletions .github/scripts/banner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os
from PIL import Image, ImageDraw, ImageFont

TEMPLATE_PATH = "./assets/banners/template.png"
FONT_PATH = "./assets/fonts"

def generate_banner(device_vendor: str, device_name: str, device_codename: str):
template = Image.open(TEMPLATE_PATH)
draw = ImageDraw.Draw(template)

font_vendor = ImageFont.truetype(f"{FONT_PATH}/GENERALSANS-MEDIUM.OTF", size=60)
font_device = ImageFont.truetype(f"{FONT_PATH}/GENERALSANS-MEDIUM.OTF", size=140 if len(device_name) <= 12 else 100)
font_codename = ImageFont.truetype(f"{FONT_PATH}/CONFIG-MEDIUM.OTF", size=40)

draw.text((85, 590), device_vendor, font=font_vendor, fill=(255, 69, 0))
draw.text((80, 680), device_name, font=font_device, fill=(238, 238, 238))
draw.text((80, 1320), device_codename.upper(), font=font_codename, fill=(51, 51, 51))


output_filename = f"./assets/{device_codename}_banner.png"
template.save(output_filename)
return os.path.abspath(output_filename)
6 changes: 4 additions & 2 deletions .github/scripts/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from NoobStuffs.libtelegraph import TelegraphHelper
from github import Github

import banner

# Get configs from workflow secrets
def getConfig(config_name: str):
return os.getenv(config_name)
Expand Down Expand Up @@ -59,8 +61,6 @@ def getDroidXUIVersion():

DROID_VERSION_CHECK = getDroidXUIVersion()

BANNER_PATH = "./assets/banners/latest.png"

# Init bot
bot = telebot.TeleBot(BOT_TOKEN, parse_mode="HTML")
telegraph = TelegraphHelper(
Expand Down Expand Up @@ -197,9 +197,11 @@ def tg_message():
print(f"IDs Changed:\n{get_diff(get_new_id(), get_old_id())}\n\n")
for devices in get_diff(get_new_id(), get_old_id()):
info = get_info(devices)
BANNER_PATH = banner.generate_banner(info['oem'], info['device_name'], info['codename'])
with open(BANNER_PATH, "rb") as image:
send_post(CHAT_ID, image, message_content(info))
commit_description += f"- {info['device_name']} ({info['codename']})\n"
os.remove(BANNER_PATH)
sleep(5)
update(get_new_id())
open("commit_mesg.txt", "w+").write(f"DroidX: {commit_message} [BOT]\n\n{commit_description}")
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/post-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v3

- name: Install Dependencies
run: sudo pip install pyTelegramBotAPI noobstuffs PyGithub
run: sudo pip install pyTelegramBotAPI noobstuffs PyGithub pillow

- name: Set Git Configs & Secrets
run: |
Expand Down
Binary file added assets/banners/template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/fonts/CONFIG-MEDIUM.OTF
Binary file not shown.
Binary file added assets/fonts/FONT.ttf
Binary file not shown.
Binary file added assets/fonts/GENERALSANS-MEDIUM.OTF
Binary file not shown.

0 comments on commit c60ab0a

Please sign in to comment.