JaeSwift commited on
Commit
0b8c5fb
·
verified ·
1 Parent(s): 86bc9d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -26,7 +26,7 @@ def get_horoscope(sign, period="today"):
26
  horoscope_text = data.get("general", ["No horoscope available"])[0]
27
 
28
  # Prepare the Twitter share link
29
- share_text = f"Here's my horoscope by Enemy AI for {sign.capitalize()} on {period.capitalize()}:\n{horoscope_text}"
30
  encoded_text = urllib.parse.quote(share_text) # URL-encode the text
31
  twitter_share_url = f"https://twitter.com/intent/tweet?text={encoded_text}"
32
 
@@ -60,20 +60,20 @@ def generate_horoscope_image(text):
60
  words = text.split()
61
  while words:
62
  line = ''
63
- while words and (draw.textsize(line + words[0], font=font)[0] <= width - padding * 2):
64
  line += (words.pop(0) + ' ')
65
  lines.append(line)
66
 
67
  # Calculate text position for centered alignment
68
- total_text_height = sum([draw.textsize(line, font=font)[1] for line in lines])
69
  y_text = (height - total_text_height) // 2
70
 
71
  # Draw each line of text
72
  for line in lines:
73
- text_width, text_height = draw.textsize(line, font=font)
74
  x_text = (width - text_width) // 2 # Center align
75
  draw.text((x_text, y_text), line, font=font, fill=text_color)
76
- y_text += text_height
77
 
78
  # Save image to file
79
  image_path = "/tmp/horoscope_image.png"
 
26
  horoscope_text = data.get("general", ["No horoscope available"])[0]
27
 
28
  # Prepare the Twitter share link
29
+ share_text = f"Here's my horoscope for {sign.capitalize()} on {period.capitalize()}:\n{horoscope_text}"
30
  encoded_text = urllib.parse.quote(share_text) # URL-encode the text
31
  twitter_share_url = f"https://twitter.com/intent/tweet?text={encoded_text}"
32
 
 
60
  words = text.split()
61
  while words:
62
  line = ''
63
+ while words and (draw.textlength(line + words[0], font=font) <= width - padding * 2):
64
  line += (words.pop(0) + ' ')
65
  lines.append(line)
66
 
67
  # Calculate text position for centered alignment
68
+ total_text_height = sum([draw.textbbox((0, 0), line, font=font)[3] - draw.textbbox((0, 0), line, font=font)[1] for line in lines])
69
  y_text = (height - total_text_height) // 2
70
 
71
  # Draw each line of text
72
  for line in lines:
73
+ text_width = draw.textlength(line, font=font)
74
  x_text = (width - text_width) // 2 # Center align
75
  draw.text((x_text, y_text), line, font=font, fill=text_color)
76
+ y_text += draw.textbbox((0, 0), line, font=font)[3] - draw.textbbox((0, 0), line, font=font)[1]
77
 
78
  # Save image to file
79
  image_path = "/tmp/horoscope_image.png"