-
Notifications
You must be signed in to change notification settings - Fork 704
import os #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import os #259
Conversation
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)
import requests
from typing import Dict
PINTEREST_ACCESS_TOKEN = os.getenv("PINTEREST_ACCESS_TOKEN")
PINTEREST_BOARD_ID = os.getenv("PINTEREST_BOARD_ID")
PINTEREST_PINS_URL = "https://api.pinterest.com/v5/pins"
def create_pin(image_url: str, title: str, description: str, alt_text: str) -> Dict:
"""
Create a Pinterest pin using the v5 API.
"""
if not PINTEREST_ACCESS_TOKEN:
raise RuntimeError("PINTEREST_ACCESS_TOKEN environment variable is not set")
if not PINTEREST_BOARD_ID:
raise RuntimeError("PINTEREST_BOARD_ID environment variable is not set")
headers = {
"Authorization": f"Bearer {PINTEREST_ACCESS_TOKEN}",
"Content-Type": "application/json"
}
payload = {
"board_id": PINTEREST_BOARD_ID,
"title": title[:100],
"description": description[:500],
"alt_text": alt_text[:500],
"media_source": {
"source_type": "image_url",
"url": image_url
}
}
response = requests.post(
PINTEREST_PINS_URL,
headers=headers,
json=payload,
timeout=30
)
response.raise_for_status()
return response.json()
|
At the moment we are not accepting contributions to the repository. Feedback for Copilot.vim can be given in the feedback forum. |
alajv76-hub
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import requests from typing import Dict
PINTEREST_ACCESS_TOKEN = os.getenv("PINTEREST_ACCESS_TOKEN") PINTEREST_BOARD_ID = os.getenv("PINTEREST_BOARD_ID")
PINTEREST_PINS_URL = "https://api.pinterest.com/v5/pins"
def create_pin(image_url: str, title: str, description: str, alt_text: str) -> Dict:
"""
Create a Pinterest pin using the v5 API.
"""if not PINTEREST_ACCESS_TOKEN: raise RuntimeError("PINTEREST_ACCESS_TOKEN environment variable is not set") if not PINTEREST_BOARD_ID: raise RuntimeError("PINTEREST_BOARD_ID environment variable is not set") headers = { "Authorization": f"Bearer {PINTEREST_ACCESS_TOKEN}", "Content-Type": "application/json" } payload = { "board_id": PINTEREST_BOARD_ID, "title": title[:100], "description": description[:500], "alt_text": alt_text[:500], "media_source": { "source_type": "image_url", "url": image_url } } response = requests.post( PINTEREST_PINS_URL, headers=headers, json=payload, timeout=30 ) response.raise_for_status() return response.json()At the moment we are not accepting contributions to the repository.
alajv76-hub
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import requests from typing import Dict
PINTEREST_ACCESS_TOKEN = os.getenv("PINTEREST_ACCESS_TOKEN") PINTEREST_BOARD_ID = os.getenv("PINTEREST_BOARD_ID")
PINTEREST_PINS_URL = "https://api.pinterest.com/v5/pins"
def create_pin(image_url: str, title: str, description: str, alt_text: str) -> Dict:
"""
Create a Pinterest pin using the v5 API.
"""
At the moment we are not accepting contributions to the repository.