

def main():
    parser = argparse.ArgumentParser(description='Post Quip threads to WordPress')
    parser.add_argument('--quip_access_token', required=True, help='Access token for your Quip account')
    parser.add_argument('--wordpress_xmlrpc_url', required=True, help='XML-RPC endpoint for your WordPress blog')
    parser.add_argument('--wordpress_username', required=True, help='Username for your WordPress blog')
    parser.add_argument('--wordpress_password', required=True, help='Password for your WordPress blog')
    parser.add_argument('--publish', type=bool, default=True, help='Publish the post immediately')
    parser.add_argument('thread_ids', metavar='thread_id', nargs='+', help='The thread IDs of the documents you want to publish')
    args = parser.parse_args()
    client = quip.QuipClient(access_token=args.quip_access_token)
    server = xmlrpclib.ServerProxy(args.wordpress_xmlrpc_url)
    threads = client.get_threads(args.thread_ids)
    for thread in threads.values():
        tree = client.parse_document_html(thread['html'])
        for img in tree.iter('img'):
            src = img.get('src')
            if (not src.startswith('/blob')):
                continue
            (_, _, thread_id, blob_id) = src.split('/')
            blob_response = client.get_blob(thread_id, blob_id)
            mimetype = blob_response.info().get('Content-Type')
            ext = ('.' + mimetype.split('/')[(- 1)])
            filename = blob_response.info().get('Content-Disposition').split('"')[(- 2)]
            if (not filename.endswith(ext)):
                filename += ext
            result = server.wp.uploadFile(0, args.wordpress_username, args.wordpress_password, {
                'name': filename,
                'type': mimetype,
                'bits': xmlrpclib.Binary(blob_response.read()),
                'overwrite': True,
            })
            img.set('src', result['url'])
        for child in tree:
            if (child.text == thread['thread']['title']):
                tree.remove(child)
                break
        html = unicode(xml.etree.cElementTree.tostring(tree))
        html = html[6:(- 7)]
        post_id = server.wp.newPost(0, args.wordpress_username, args.wordpress_password, {
            'post_title': thread['thread']['title'],
            'post_content': html,
        })
        if args.publish:
            server.mt.publishPost(post_id, args.wordpress_username, args.wordpress_password)

dataset/ETHPy150Open quip/quip-api/samples/wordpress/quiptowordpress.py main/original