From 0a1a538268a9a63fa3014b9b2534ee01dd8eefd4 Mon Sep 17 00:00:00 2001 From: Ian Weller Date: Tue, 22 Dec 2009 01:41:07 -0600 Subject: [PATCH 1/1] Centralize pagename/filename conversions --- src/mw/api.py | 11 +++++++++++ src/mw/clicommands.py | 9 ++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/mw/api.py b/src/mw/api.py index bd12bb0..8961f5d 100644 --- a/src/mw/api.py +++ b/src/mw/api.py @@ -55,3 +55,14 @@ class API(object): return high else: return low + + +def pagename_to_filename(name): + name.replace(' ', '_') + name.replace('/', '!') + return name + +def filename_to_pagename(name): + name.replace('!', '/') + name.replace('_', ' ') + return name diff --git a/src/mw/clicommands.py b/src/mw/clicommands.py index ccfc9cb..1d5f5c8 100644 --- a/src/mw/clicommands.py +++ b/src/mw/clicommands.py @@ -91,17 +91,16 @@ class FetchCommand(CommandBase): } response = self.api.call(data)['query']['pages'] for pageid in response.keys(): + pagename = response[pageid]['title'] if 'missing' in response[pageid].keys(): print '%s: %s: page does not exist, file not created' % \ - (self.me, response[pageid]['title']) + (self.me, pagename) continue revid = [x['revid'] for x in response[pageid]['revisions']] - self.metadir.pagedict_add(response[pageid]['title'], - int(pageid)) + self.metadir.pagedict_add(pagename, int(pageid)) self.metadir.pages_add_rev(int(pageid), response[pageid]['revisions'][0]) - filename = response[pageid]['title'].replace(' ', '_') - filename = filename.replace('/', '!') + filename = mw.api.pagename_to_filename(pagename) fd = file(os.path.join(self.metadir.root, filename + '.wiki'), 'w') fd.write(response[pageid]['revisions'][0]['*'].encode('utf-8')) -- 2.39.5