Commit de20bf7
committed
def main():
parser = argparse.ArgumentParser(description="Download from Pexels and post to Pinterest")
parser.add_argument("--query", required=True, help="Search query for Pexels")
parser.add_argument("--count", type=int, default=1, help="Number of items to fetch")
parser.add_argument("--use-hosting", action="store_true")
parser.add_argument("--include-attribution", action="store_true")
args = parser.parse_args()
photos = search_pexels(args.query, args.count)
if not photos:
print("No photos found.")
sys.exit(1)
for photo in photos:
image_url = photo["src"]["original"]
photographer = photo.get("photographer", "Unknown")
pexels_link = photo.get("url", "")
final_image_url = image_url
if args.use_hosting:
filename = f"temp_{int(time.time())}.jpg"
download_file(image_url, filename)
final_image_url = upload_to_imgur(filename)
os.remove(filename)
description = f"Photo about {args.query}"
if args.include_attribution:
description += f"\n📸 {photographer} via Pexels\n{pexels_link}"
response = create_pin(
image_url=final_image_url,
title=f"{args.query.title()} Inspiration",
description=description,
alt_text=f"{args.query} image"
)
print("✅ Pin created:", response.get("id"))
time.sleep(2)1 parent a12fd56 commit de20bf7
1 file changed
+19
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
0 commit comments