Created
December 30, 2011 16:14
-
-
Save franek/1540460 to your computer and use it in GitHub Desktop.
Delicious Backup Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# The Delicious API only returns 1000 bookmarks at a time. | |
# The web export returns them all in the output file. | |
# | |
# To use: | |
# 1. Install requests: http://python-requests.org | |
# under ubuntu | |
# - install pip : | |
# sudo apt-get install python-pip | |
# - upgrade python-request | |
# sudo pip install requests --upgrade | |
# 2. Run python | |
# python delicious.py -u <username> -p <password> -o output.html | |
# 3. Enjoy | |
# | |
# | |
# You can add this script in crontab | |
# Example : | |
# 0 19 * * * /usr/bin/python /directory/to/delicious.py -u <username> -p <password> -o /directory/to/backup/delicious-`date +%Y%m%d`.html | |
import requests | |
import sys | |
import argparse | |
# use argparse to get command line argument | |
# --username (or -u) and --password (or -p) are required | |
parser = argparse.ArgumentParser(description='Process parameters.') | |
parser.add_argument('-u', '--username', required=True) | |
parser.add_argument('-p', '--password', required=True) | |
parser.add_argument('-o', '--output', type=argparse.FileType('w'), required=True) | |
args = parser.parse_args() | |
# connect to delicious and retrieve cookies | |
data = {"action": "login", "username": args.username, "password": args.password} | |
response = requests.post("https://delicious.com/login", data=data) | |
cookies = response.cookies | |
# export bookmarks | |
data = {"include_notes": "yes", "include_tags": "yes", "tags": ""} | |
response = requests.post("http://export.delicious.com/settings/bookmarks/export", data=data, cookies=cookies) | |
# write bookmarks in the output file | |
args.output.write(unicode(response.content).encode("utf-8")) | |
# this is the end ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice improvements! Thanks for forking. :)