-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_collection.py
More file actions
45 lines (34 loc) · 1.2 KB
/
create_collection.py
File metadata and controls
45 lines (34 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Create a new Raindrop collection
"""
import os
import requests
from dotenv import load_dotenv
# 1. Load environment variables from .env
load_dotenv()
# 2. Read configuration
API_TOKEN = os.getenv('RAINDROP_API_TOKEN')
NEW_COLLECTION_NAME = os.getenv('NEW_COLLECTION_NAME')
GROUP_ID = os.getenv('GROUP_ID')
# 3. Verify that everything is configured
if not API_TOKEN:
raise ValueError("RAINDROP_API_TOKEN not found in .env")
if not NEW_COLLECTION_NAME:
raise ValueError("NEW_COLLECTION_NAME not found in .env")
print("Configuration loaded:")
print(f" New collection name: {NEW_COLLECTION_NAME}")
if GROUP_ID:
print(f" Group ID: {GROUP_ID}")
# 4. Set headers for API
headers = {'Authorization': f'Bearer {API_TOKEN}', 'Content-Type': 'application/json'}
# 5. Create the collection
print(f"Creating collection '{NEW_COLLECTION_NAME}'...")
data = {'title': NEW_COLLECTION_NAME}
if GROUP_ID:
data['parentId'] = GROUP_ID
response = requests.post('https://api.raindrop.io/rest/v1/collection', headers=headers, json=data)
response.raise_for_status()
collection = response.json()['item']
print(f"Collection created successfully:")
print(f" ID: {collection['_id']}")
print(f" Title: {collection['title']}")