-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall_bookmarks_df.py
More file actions
56 lines (40 loc) · 1.31 KB
/
all_bookmarks_df.py
File metadata and controls
56 lines (40 loc) · 1.31 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
46
47
48
49
50
51
52
53
54
55
56
"""
Create a DataFrame with all Raindrop bookmarks
"""
import os
import requests
import pandas as pd
from dotenv import load_dotenv
# 1. Load environment variables from .env
load_dotenv()
# 2. Read configuration
API_TOKEN = os.getenv('RAINDROP_API_TOKEN')
# 3. Verify that everything is configured
if not API_TOKEN:
raise ValueError("RAINDROP_API_TOKEN not found in .env")
print("Configuration loaded.")
# 4. Set headers for API
headers = {'Authorization': f'Bearer {API_TOKEN}'}
# 5. Retrieve all raindrops
print("Retrieving all raindrops...")
all_raindrops = []
page = 0
per_page = 50 # Max per page
while True:
response = requests.get(f'https://api.raindrop.io/rest/v1/raindrops/0?page={page}&perpage={per_page}', headers=headers)
response.raise_for_status()
data = response.json()
raindrops = data['items']
all_raindrops.extend(raindrops)
if len(raindrops) < per_page:
break # No more pages
page += 1
print(f"Retrieved {len(all_raindrops)} raindrops.")
# 6. Create DataFrame
df = pd.DataFrame(all_raindrops)
# Select relevant columns, adjust as needed
columns = ['_id', 'title', 'link', 'tags', 'excerpt', 'created', 'lastUpdate']
df = df[columns]
# 7. Save to CSV
df.to_csv('all_bookmarks.csv', index=False, sep=';')
print("DataFrame created and saved to all_bookmarks.csv")