paramah a révisé ce gist . Aller à la révision
1 file changed, 33 insertions
import.py(fichier créé)
| @@ -0,0 +1,33 @@ | |||
| 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) | |
Plus récent
Plus ancien