import.py
· 1011 B · Python
Orginalformat
import csv
import requests
CSV_PATH = 'PATH_TO/pocket/part_000000.csv' # getpocket export file
API_URL = 'http://shiori.para.net/api/bookmarks'
HEADERS = {
'Content-Type': 'application/json',
'Authorization': 'Bearer TOKEN'
}
def parse_tags(tag_string):
if not tag_string:
return []
return [{"name": tag.strip()} for tag in tag_string.split("|")]
def import_bookmarks(csv_path):
with open(csv_path, newline='', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
payload = {
"url": row["url"],
"createArchive": False,
"public": 0,
"tags": parse_tags(row["tags"]),
"excerpt": ""
}
print(payload)
response = requests.post(API_URL, headers=HEADERS, json=payload)
print(f"Sent: {row['url']} - Status: {response.status_code}")
if __name__ == "__main__":
import_bookmarks(CSV_PATH)
| 1 | import csv |
| 2 | import requests |
| 3 | |
| 4 | CSV_PATH = 'PATH_TO/pocket/part_000000.csv' # getpocket export file |
| 5 | API_URL = 'http://shiori.para.net/api/bookmarks' |
| 6 | HEADERS = { |
| 7 | 'Content-Type': 'application/json', |
| 8 | 'Authorization': 'Bearer TOKEN' |
| 9 | } |
| 10 | |
| 11 | def parse_tags(tag_string): |
| 12 | if not tag_string: |
| 13 | return [] |
| 14 | return [{"name": tag.strip()} for tag in tag_string.split("|")] |
| 15 | |
| 16 | def import_bookmarks(csv_path): |
| 17 | with open(csv_path, newline='', encoding='utf-8') as csvfile: |
| 18 | reader = csv.DictReader(csvfile) |
| 19 | for row in reader: |
| 20 | payload = { |
| 21 | "url": row["url"], |
| 22 | "createArchive": False, |
| 23 | "public": 0, |
| 24 | "tags": parse_tags(row["tags"]), |
| 25 | "excerpt": "" |
| 26 | } |
| 27 | print(payload) |
| 28 | response = requests.post(API_URL, headers=HEADERS, json=payload) |
| 29 | print(f"Sent: {row['url']} - Status: {response.status_code}") |
| 30 | |
| 31 | |
| 32 | if __name__ == "__main__": |
| 33 | import_bookmarks(CSV_PATH) |