Created
July 1, 2020 17:28
-
-
Save danieltharp/c66d92f59bb08b73d414dc74794174d8 to your computer and use it in GitHub Desktop.
A quick way to clone Wikidot sites larger than 100 Pages with an API key.
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
# You will need to be a member of both sites. | |
# Both sites need to enable API Reads for members, and the new site needs to allow writes via the API. | |
# If you're an admin of the sites you can restrict the API to admins only. | |
# If you don't have a Wikidot API Key, unfortunately you can no longer get one. | |
# TODO: Handle files above the 6MB size limit the API imposes, although you also can't write files back of that size. | |
# They could be retrieved via files.get_meta, there's an attribute called download_url. | |
# E.g., | |
# import requests | |
# for idx, file in enumerate(files): | |
# info = s.files.get_meta({"site": wikidot_site, "page": slug, "files": [file]}) | |
# filedict = list(info.values())[0] | |
# thefile = requests.get(filedict['download_url']) | |
# filebytes = thefile.content # Bytes object. | |
from xmlrpc.client import ServerProxy | |
from time import sleep | |
wikidot_username = "pxdnbluesoul" | |
wikidot_api_key = "asdfjkl123456789" | |
old_site = "oldwikisite" # This is [whatever].wikidot.com | |
new_site = "shinynewwiki" | |
s = ServerProxy('https://' + wikidot_username + ':' + wikidot_api_key + '@www.wikidot.com/xml-rpc-api.php') | |
pageslist = s.pages.select({'site': old_site}) | |
for page in pageslist: | |
print("Saving " + page) | |
fullpage = s.pages.get_one({'site': old_site, 'page': page}) | |
sleep(0.25) | |
if not fullpage["parent_fullname"]: | |
fullpage["parent_fullname"] = "" | |
writepage = s.pages.save_one({ | |
'site': new_site, | |
'page': page, | |
'title': fullpage["title"], | |
'content': fullpage["content"], | |
'tags': fullpage["tags"], | |
}) | |
print("Saved, checking for files.") | |
sleep(0.25) | |
files = s.files.select({ | |
'site': old_site, | |
'page': page | |
}) | |
for file in files: | |
savedfile = s.files.get_one({ | |
'site': old_site, | |
'page': page, | |
'file': file, | |
}) | |
s.files.save_one({ | |
'site': new_site, | |
'page': page, | |
'file': file, | |
'content': savedfile["content"] | |
}) | |
print("Saved file " + file) | |
for page in pageslist: | |
print("Checking " + page) | |
fullpage = s.pages.get_one({'site': old_site, 'page': page}) | |
sleep(0.25) | |
if fullpage["parent_fullname"]: | |
print("Parenting " + page + " to " + fullpage["parent_fullname"]) | |
writepage = s.pages.save_one({ | |
'site': new_site, | |
'page': page, | |
'parent_fullname': fullpage["parent_fullname"], | |
'save_mode': 'update' | |
}) | |
print("Complete.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment