Skip to content

Instantly share code, notes, and snippets.

@a0726h77
Last active December 18, 2015 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a0726h77/e08885de81889548e6f2 to your computer and use it in GitHub Desktop.
Save a0726h77/e08885de81889548e6f2 to your computer and use it in GitHub Desktop.
List all pads of Hackpad
#!/usr/bin/env python
# encoding: utf-8
from hackpad_api import hackpad
from xmlrpclib import ServerProxy
from datetime import datetime
config = {'hackpad': {}, 'wikidot': {}}
config['hackpad']['subdomain'] = 'hackingthursday'
config['hackpad']['client_id'] = ''
config['hackpad']['secret'] = ''
config['hackpad']['save_pad_id'] = ''
config['wikidot']['user'] = 'h4'
config['wikidot']['api_key'] = ''
config['wikidot']['site'] = 'hackingthursday'
config['wikidot']['save_page_name'] = 'hackpad-all'
h = hackpad.Hackpad(config['hackpad']['subdomain'], config['hackpad']['client_id'], config['hackpad']['secret'])
w = ServerProxy('https://%s:%s@www.wikidot.com/xml-rpc-api.php' % (config['wikidot']['user'], config['wikidot']['api_key']))
content = ''
# list all pads
pads = h.list_all()
for pad in pads:
title = h.get_pad_content(pad).split('\n')[0].decode('utf-8')
id = pad
line = '%s\nhttps://%s.hackpad.com/%s\n' % (title, config['hackpad']['subdomain'], id)
content = content + line
print line
# 寫回 pad
# 目前 Hackpad 寫入的 API 有問題,先寫回 Wikidot
# if config['hackpad']['save_pad_id']:
# h.update_pad_content(config['hackpad']['save_pad_id'], str(datetime.now()) + '\n' + content)
if config['wikidot']['save_page_name']:
w.pages.save_one({'site': config['wikidot']['site'], 'page': config['wikidot']['save_page_name'], 'content': (str(datetime.now()) + '\n' + content).replace('\n', '\n\n')})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment