Skip to content

Commit e23b223

Browse files
committed
Added page.extend_data for continuations #129
1 parent a77ae85 commit e23b223

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

wptools/page.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ def __pull_image_info(self, title, imageinfo, normalized):
123123

124124
self.__insert_image_info(title, _from, info)
125125

126+
def _extend_data(self, datapoint, new_data):
127+
"""
128+
assigns or extends datapoint with new data
129+
"""
130+
if new_data:
131+
try:
132+
self.data[datapoint].extend(new_data)
133+
except KeyError:
134+
self.data[datapoint] = new_data
135+
126136
def _missing_imageinfo(self):
127137
"""
128138
returns list of image filenames that are missing info
@@ -290,12 +300,7 @@ def _set_query_data(self, action='query'):
290300
if action == 'query':
291301
self.data['random'] = data['query']['random'][0]["title"]
292302

293-
backlinks = data['query'].get('backlinks')
294-
if backlinks:
295-
if 'backlinks' in self.data:
296-
self.data['backlinks'].extend(backlinks)
297-
else:
298-
self.data['backlinks'] = backlinks
303+
self._extend_data('backlinks', data['query'].get('backlinks'))
299304

300305
self.data['redirected'] = data['query'].get('redirects')
301306

@@ -329,7 +334,7 @@ def _set_query_data_fast_1(self, page):
329334
if length:
330335
self.data['length'] = length
331336

332-
self.data['links'] = utils.get_links(page.get('links'))
337+
self._extend_data('links', utils.get_links(page.get('links')))
333338

334339
modified = page.get('touched')
335340
if modified:

0 commit comments

Comments
 (0)