List all pads of Hackpad
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 | |
# 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