Created
September 14, 2011 13:53
-
-
Save tomoconnor/1216613 to your computer and use it in GitHub Desktop.
WikiArchiver
This file contains hidden or 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
| import gdata.docs.data | |
| import gdata.docs.client | |
| import gdata | |
| import os | |
| import datetime | |
| import mimetypes | |
| client = gdata.docs.client.DocsClient(source='wikiDocker-v1') | |
| client.ssl = True | |
| client.http_client.debug = False | |
| EXPORT_DIR = "<wget --mirror output>" | |
| client.ClientLogin('<googleid>', '<googlepassword>', client.source) | |
| mimetypes.init() | |
| def handleFile(p,f,folder): | |
| pass | |
| def handleObject(p,f,folder): | |
| mime = mimetypes.guess_type(p)[0] | |
| if mime is None: | |
| mime = 'text/html' | |
| ms = gdata.data.MediaSource(file_path=p,content_type=mime) | |
| new_page = client.Upload(ms,f) | |
| client.move(new_page,folder) | |
| print 'Document now accessible online at:', new_page.GetAlternateLink().href | |
| now = datetime.datetime.now() | |
| datestring = "%d-%d-%d-%d%d%d" % (now.year,now.month,now.day,now.hour,now.minute,now.second) | |
| folder_id = "WikiArchive-%s" % datestring | |
| wiki_folder = client.Create(gdata.docs.data.FOLDER_LABEL, folder_id) | |
| print 'Folder "%s" created' % wiki_folder.title.text | |
| for dirname, dirnames, filenames in os.walk(EXPORT_DIR): | |
| for subdirname in dirnames: | |
| #print os.path.join(dirname, subdirname) | |
| for filename in filenames: | |
| fpath = os.path.join(dirname, filename) | |
| print fpath | |
| if not 'Category:' in fpath: | |
| if not 'Template:' in fpath: | |
| if not 'Special:' in fpath: | |
| if not 'User:' in fpath: | |
| if not 'User_talk:' in fpath: | |
| if 'Image:' in fpath: | |
| handleFile(fpath,filename,wiki_folder) | |
| elif 'File:' in fpath: | |
| handleFile(fpath,filename,wiki_folder) | |
| else: | |
| handleObject(fpath,filename,wiki_folder) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment