-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.py
28 lines (25 loc) · 870 Bytes
/
post.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from PIL import Image, ImageDraw, ImageFont
import requests
import os
from dotenv import load_dotenv, dotenv_values
load_dotenv()
def write_on_img(message):
img = Image.open("static/2.jpg")
font = ImageFont.truetype('static/莫大毛筆-Regular.ttf', 85)
imgDraw = ImageDraw.Draw(img)
width = 1748
textWidth = 0
poem = ""
for line in message:
textWidth = max(textWidth, imgDraw.textlength(line, font=font))
poem += line.replace("\\n", "\n")
xText = (width-textWidth)/2
yText = 435
imgDraw.multiline_text((xText, yText), poem, font=font, fill=(50, 50, 50), spacing=32, align="center")
return img
def send_line(message):
token = os.getenv("LINE_TOKEN")
headers = { "Authorization": "Bearer " + token }
data = { 'message': '\n'+message }
requests.post("https://notify-api.line.me/api/notify",
headers = headers, data = data)