!/usr/bin/env python3
— coding: utf-8 —
import os, time, random, requests, re, unicodedata, xmlrpc.client
from io import BytesIO
from PIL import Image, ImageEnhance, ImageDraw, ImageFont
from bs4 import BeautifulSoup
—————– Ayarlar —————–
PINTEREST_ACCESS_TOKEN = “pina_AMATEXQXABUPOAIAGDAMSC6REDRGBGIBQBIQDITMPLSKW2A2HYXECEBP7F5MDBCHVKQ5DZ4NCJ42BO7WNSFPESSG5L2OJYQA”
YESIL_FILE = r”C:\Users\Kullanıcı\Desktop\kuzen\tumblr\yesil.txt”
PING_URLS = [
“http://pingoat.com/goat/RPC2”,
“http://ping.blo.gs/”,
“http://blog.with2.net/ping.php”,
“http://rpc.pingomatic.com”
]
—————– Yardımcı Fonksiyon —————–
def normalize_text(text):
mapping = str.maketrans(“çğıöşüÇĞİÖŞÜ”, “cgiosuCGIOSU”)
return unicodedata.normalize(“NFKD”, text.translate(mapping)).encode(“ascii”, “ignore”).decode(“ascii”)
def get_first_post(site):
“””RSS veya anasayfa üzerinden ilk yazıyı al”””
feed_url = f”https://{site}/feed/”
try:
r = requests.get(feed_url, timeout=10, headers={“User-Agent”:”Mozilla/5.0″})
if r.status_code == 200:
soup = BeautifulSoup(r.text, “xml”)
item = soup.find(“item”)
if item:
title = item.find(“title”).text.strip()
link = item.find(“link”).text.strip()
desc = item.find(“description”).text.strip() if item.find(“description”) else “”
return title, link, desc
except: pass
try:
r = requests.get(f”https://{site}/”, timeout=10, headers={“User-Agent”:”Mozilla/5.0″})
soup = BeautifulSoup(r.text, “html.parser”)
first_link = soup.find(“a”, href=True)
if first_link and first_link.text.strip():
title = re.sub(r”<.?>“, “”, first_link.text).strip()
link = first_link[“href”]
if not link.startswith(“http”):
link = f”https://{site}/{link.lstrip(‘/’)}”
return title, link, “”
except: pass
return None, None, None
—————– Resim Fonksiyonları —————–
def add_text_to_image(img, sitename, title, font_size=26):
draw = ImageDraw.Draw(img)
try:
font = ImageFont.truetype(“arial.ttf”, font_size)
except:
font = ImageFont.load_default()
text = f”{sitename} – {title[:40]}”
bbox = draw.textbbox((0,0), text, font=font)
position = (10, img.height – (bbox[3]-bbox[1]) – 10)
draw.text(position, text, font=font, fill=”red”)
return img
def enhance_image(img):
return ImageEnhance.Sharpness(ImageEnhance.Brightness(img).enhance(1.1)).enhance(1.1)
def download_image(urls, sitename, title):
headers = {“User-Agent”: “Mozilla/5.0”}
for url in urls:
try:
r = requests.get(url, headers=headers, timeout=10)
if r.status_code == 200 and “image” in r.headers.get(“Content-Type”,””).lower():
img = Image.open(BytesIO(r.content)).convert(“RGB”)
img = enhance_image(add_text_to_image(img, sitename, title))
path = f”temp_{random.randint(1000,9999)}.jpg”
img.save(path, “JPEG”)
return path
except: continue
return None
def generate_image(query, sitename, title):
# Unsplash fallback
urls = [f”https://source.unsplash.com/600×400/?{query}”]
path = download_image(urls, sitename, title)
if path: return path
# Basit renkli resim fallback
img = Image.new(“RGB”,(600,400),(random.randint(0,255),random.randint(0,255),random.randint(0,255)))
img = add_text_to_image(img, sitename, title)
path = f”temp_{random.randint(1000,9999)}.jpg”
img.save(path)
return path
—————– Pinterest Fonksiyonları —————–
def get_boards():
url = “https://api.pinterest.com/v5/boards”
headers = {“Authorization”: f”Bearer {PINTEREST_ACCESS_TOKEN}”}
r = requests.get(url, headers=headers)
if r.status_code == 200:
boards = [(b[“id”], b[“name”]) for b in r.json().get(“items”,[])]
print(f”[INFO] {len(boards)} pano bulundu.”)
return boards
print(f”[HATA] Panolar çekilemedi: {r.status_code}”)
return []
def create_pin(board_id, image_path, title, desc, link):
url = “https://api.pinterest.com/v5/pins”
headers = {“Authorization”: f”Bearer {PINTEREST_ACCESS_TOKEN}”}
desc_full = f”{title}\n{desc[:100]}\n{link}”
with open(image_path,”rb”) as f:
files={“image”:f}
data={“board_id”:board_id,”title”:title,”description”:desc_full,”link”:link}
r = requests.post(url, headers=headers, data=data, files=files)
if r.status_code in [200,201]:
pin_id = r.json().get(“id”)
print(f”[OK] Pin oluşturuldu: https://www.pinterest.com/pin/{pin_id}/”)
return f”https://www.pinterest.com/pin/{pin_id}/”
return None
—————– Ping —————–
def ping_sites(url):
for s in PING_URLS:
try:
if s.endswith(“.php”) or “RPC2” in s:
proxy = xmlrpc.client.ServerProxy(s)
proxy.weblogUpdates.ping(“Pinterest Bot”, url)
else:
requests.get(s, params={“ping”: url}, timeout=5)
except: pass
time.sleep(1)
—————– Ana Program —————–
def main():
boards = get_boards()
if not boards: return
sites = [s.strip() for s in open(YESIL_FILE,”r”,encoding=”utf-8″) if s.strip()]
board_index=0
while True:
for site in sites:
title, link, desc = get_first_post(site)
if not title or not link: continue
clean_title = title.strip()
query = normalize_text(clean_title)
sitename = site.split(“.”)[0]
img_path = generate_image(query, sitename, clean_title)
if not img_path: continue
board_id, _ = boards[board_index % len(boards)]
board_index +=1
pin_url = create_pin(board_id, img_path, clean_title, desc, link)
os.remove(img_path)
if pin_url:
ping_sites(pin_url)
time.sleep(3) # Daha hızlı
if __name__ == “__main__”:
main()
PS C:\Users\Kullanıcı\Desktop\kuzen\pinterst> python pin.py
[INFO] 21 pano bulundu.
devamı yok burda donuyor