with open('/content/main.py', 'w') as f: f.write("""import requests import…
- User
with open('/content/main.py', 'w') as f: f.write("""import requests import xml.etree.ElementTree as ET import pandas as pd from PIL import Image, ImageDraw, ImageFont, UnidentifiedImageError from io import BytesIO import textwrap import zipfile import os import re
Genel ayarlar
FONT_PATH = 'C:/Windows/Fonts/Arial.ttf' # Bilgisayarınızdaki bir font dosyasını belirleyin. TITLE_FONT_SIZE = 35 DESCRIPTION_FONT_SIZE = 19 LOGO_PATH = 'logo.png' # Masaüstüne koyduğunuz bir logo dosyasının adı.
POST_SIZE = (1080, 1080) # Görsel boyutları LOGO_SIZE = (120, 120)
Çıkış klasörlerini ayarla
OUTPUT_CSV_DIR = os.path.expanduser("
/Desktop/") # Masaüstüne kaydetmek için OUTPUT_POST_DIR = os.path.expanduser("/Downloads/") # İndirilenlere kaydetmek içinFontları yükle
title_font = ImageFont.truetype(FONT_PATH, TITLE_FONT_SIZE) description_font = ImageFont.truetype(FONT_PATH, DESCRIPTION_FONT_SIZE)
Logo dosyasını yükle
logo = Image.open(LOGO_PATH).resize(LOGO_SIZE)
def wrap_text(text, width): lines = textwrap.wrap(text, width=width) return "\n".join(lines) # Tırnaklar burada düzgün kapanmalı
Görsel gönderisi oluşturma
def create_post(title, description, img_url, output_folder): default_image_url = "https://via.placeholder.com/1080" # Varsayılan görsel URL'si headers = {'User-Agent': 'Mozilla/5.0'}
codetry: response = requests.get(img_url, headers=headers, timeout=10) response.raise_for_status() except: response = requests.get(default_image_url) try: img = Image.open(BytesIO(response.content)).resize(POST_SIZE) except: return None draw = ImageDraw.Draw(img) title = wrap_text(title, 50).upper() description = wrap_text(description, 100).upper() title_bbox = draw.textbbox((0, 0), title, font=title_font) description_bbox = draw.textbbox((0, 0), description, font=description_font) title_x, title_y = 30, 400 description_x, description_y = 30, title_y + (title_bbox[3] - title_bbox[1]) + 30 draw.rectangle([title_x - 20, title_y - 20, title_bbox[2] + 20, title_y + title_bbox[3] - title_bbox[1] + 20], fill="red") draw.text((title_x, title_y), title, font=title_font, fill="white") draw.rectangle([description_x - 10, description_y - 10, description_bbox[2] + 10, description_y + description_bbox[3] - description_bbox[1] + 10], fill="white") draw.text((description_x, description_y), description, font=description_font, fill="black") img.paste(logo, (POST_SIZE[0] - LOGO_SIZE[0] - 30, 30), logo) safe_title = re.sub(r'[^\w\-_\. ]', '_', title[:10]) post_filename = os.path.join(output_folder, f"post_{safe_title}.jpg") img.save(post_filename) return post_filename - Assistant
- User
bu kod ıcın colabta !pyinstaller --onefile /content/main.py bunu calıstırdıgımda aldıgım hata
Syntax error in /content/main.py File "/content/main.py", line 33 return " ^ SyntaxError: unterminated string literal (detected at line 33)
- Assistant