Skip to content

Commit

Permalink
Merge pull request #243 from sachavakili/fix/sections_missing
Browse files Browse the repository at this point in the history
fix: Modify sections query parameters to adapt to Wikipedia's API
  • Loading branch information
goldsmith committed Oct 9, 2020
2 parents 2065c56 + 18fab92 commit 1554943
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/request_mock_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
(('prop', 'revisions'), ('rvlimit', 1), ('rvparse', ''), ('rvprop', 'content'), ('titles', 'Celtuce')):
{'query-continue': {'revisions': {'rvcontinue': 547842204}}, 'query': {'pages': {'1868108': {'ns': 0, 'pageid': 1868108, 'revisions': [{'*': '<table class="metadata plainlinks ambox ambox-content ambox-Unreferenced" style="" role="presentation">\n<tr><td class="mbox-image"><div style="width: 52px;"><a href="/wiki/File:Question_book-new.svg" class="image"><img alt="Question book-new.svg" src="//upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/50px-Question_book-new.svg.png" width="50" height="39" srcset="//upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/75px-Question_book-new.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/100px-Question_book-new.svg.png 2x" /></a></div></td><td class="mbox-text" style=""><span class="mbox-text-span">This article <b>does not <a href="/wiki/Wikipedia:Citing_sources" title="Wikipedia:Citing sources">cite</a> any <a href="/wiki/Wikipedia:Verifiability" title="Wikipedia:Verifiability">references or sources</a></b>.<span class="hide-when-compact"> Please help <a class="external text" href="//en.wikipedia.org/w/index.php?title=Celtuce&amp;action=edit">improve this article</a> by <a href="/wiki/Help:Introduction_to_referencing/1" title="Help:Introduction to referencing/1">adding citations to reliable sources</a>. Unsourced material may be challenged and <a href="/wiki/Wikipedia:Verifiability#Burden_of_evidence" title="Wikipedia:Verifiability">removed</a>.</span>&#32;<small><i>(December 2009)</i></small><span class="hide-when-compact"> </span></span></td></tr></table><div class="thumb tright"><div class="thumbinner" style="width:302px;"><a href="/wiki/File:Celtuce.jpg" class="image"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/8/87/Celtuce.jpg/300px-Celtuce.jpg" width="300" height="135" class="thumbimage" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/8/87/Celtuce.jpg/450px-Celtuce.jpg 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/8/87/Celtuce.jpg/600px-Celtuce.jpg 2x" /></a> <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Celtuce.jpg" class="internal" title="Enlarge"><img src="//bits.wikimedia.org/static-1.22wmf12/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>Celtuce stems &amp; heads</div></div></div>\n<p><b>Celtuce</b> (<i>Lactuca sativa</i> var. <i>asparagina</i>, <i>augustana</i>, or <i>angustata</i>), also called <b>stem lettuce</b>, <b>celery lettuce</b>, <b>asparagus lettuce</b>, or <b>Chinese lettuce</b>, IPA (UK,US) <span title="Representation in the International Phonetic Alphabet (IPA)" class="IPA">/\u02c8s\u025blt.\u0259s/</span>, is a cultivar of <a href="/wiki/Lettuce" title="Lettuce">lettuce</a> grown primarily for its thick <a href="/wiki/Plant_stem" title="Plant stem">stem</a>, used as a <a href="/wiki/Vegetable" title="Vegetable">vegetable</a>. It is especially popular in China, and is called <i><b>wosun</b></i> (<a href="/wiki/Chinese_language" title="Chinese language">Chinese</a>&#58; <span lang="zh"><a href="//en.wiktionary.org/wiki/%E8%8E%B4" class="extiw" title="wiktionary:\u83b4">\u83b4</a><a href="//en.wiktionary.org/wiki/%E7%AC%8B" class="extiw" title="wiktionary:\u7b0b">\u7b0b</a></span>&#59;&#32;<a href="/wiki/Pinyin" title="Pinyin">pinyin</a>&#58; <em>w\u014ds\u016dn</em>) or <i><b>woju</b></i> (<a href="/wiki/Chinese_language" title="Chinese language">Chinese</a>&#58; <span lang="zh"><a href="//en.wiktionary.org/wiki/%E8%8E%B4" class="extiw" title="wiktionary:\u83b4">\u83b4</a><a href="//en.wiktionary.org/wiki/%E8%8B%A3" class="extiw" title="wiktionary:\u82e3">\u82e3</a></span>&#59;&#32;<a href="/wiki/Pinyin" title="Pinyin">pinyin</a>&#58; <em>w\u014dj\xf9</em>) (although the latter name may also be used to mean lettuce in general).\n</p>\n<div class="thumb tright"><div class="thumbinner" style="width:302px;"><a href="/wiki/File:The_farmer%27s_market_near_the_Potala_in_Lhasa.jpg" class="image"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/d/dc/The_farmer%27s_market_near_the_Potala_in_Lhasa.jpg/300px-The_farmer%27s_market_near_the_Potala_in_Lhasa.jpg" width="300" height="241" class="thumbimage" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/d/dc/The_farmer%27s_market_near_the_Potala_in_Lhasa.jpg/450px-The_farmer%27s_market_near_the_Potala_in_Lhasa.jpg 1.5x, //upload.wikimedia.org/wikipedia/commons/d/dc/The_farmer%27s_market_near_the_Potala_in_Lhasa.jpg 2x" /></a> <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:The_farmer%27s_market_near_the_Potala_in_Lhasa.jpg" class="internal" title="Enlarge"><img src="//bits.wikimedia.org/static-1.22wmf12/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>Celtuce (foreground) for sale in <a href="/wiki/Lhasa" title="Lhasa">Lhasa</a></div></div></div>\n<table class="infobox" style="font-size: 88%; text-align: left; width: 22em; line-height: 1.5em">\n<caption style="font-size: 125%; font-weight: bold"> Celtuce, raw\n\n</caption>\n<tr>\n<th colspan="2" style="text-align: center"> Nutritional value per 100&#160;g (3.5&#160;oz)\n</th></tr>\n<tr style="background-color: #e0e0e0">\n<th> <a href="/wiki/Food_energy" title="Food energy">Energy</a>\n</th>\n<td> 75&#160;kJ (18&#160;kcal)\n</td></tr>\n<tr>\n<th> <a href="/wiki/Carbohydrate" title="Carbohydrate">Carbohydrates</a>\n</th>\n<td> 3.65 g\n</td></tr>\n\n\n\n<tr>\n<th> - <a href="/wiki/Dietary_fiber" title="Dietary fiber">Dietary fiber</a>\n</th>\n<td> 1.7 g\n</td></tr>\n\n<tr>\n<th> <a href="/wiki/Fat" title="Fat">Fat</a>\n</th>\n<td> 0.3 g\n</td></tr>\n\n\n\n\n\n\n<tr>\n<th> <a href="/wiki/Protein_(nutrient)" title="Protein (nutrient)">Protein</a>\n</th>\n<td> 0.85 g\n</td></tr>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<tr>\n<td> <a href="/wiki/Vitamin_A" title="Vitamin A">Vitamin A</a> equiv.\n</td>\n<td> 175 \u03bcg (22%)\n</td></tr>\n\n\n\n\n<tr>\n<td> <a href="/wiki/Thiamine" title="Thiamine">Thiamine (vit. B<sub>1</sub>)</a>\n</td>\n<td> 0.055 mg (5%)\n</td></tr>\n<tr>\n<td> <a href="/wiki/Riboflavin" title="Riboflavin">Riboflavin (vit. B<sub>2</sub>)</a>\n</td>\n<td> 0.07 mg (6%)\n</td></tr>\n<tr>\n<td> <a href="/wiki/Niacin" title="Niacin">Niacin (vit. B<sub>3</sub>)</a>\n</td>\n<td> 0.55 mg (4%)\n</td></tr>\n<tr>\n<td> <a href="/wiki/Pantothenic_acid" title="Pantothenic acid">Pantothenic acid</a> (B<sub>5</sub>)\n</td>\n<td> 0.183 mg (4%)\n</td></tr>\n<tr>\n<td> <a href="/wiki/Vitamin_B6" title="Vitamin B6">Vitamin B<sub>6</sub></a>\n</td>\n<td> 0.05 mg (4%)\n</td></tr>\n<tr>\n<td> <a href="/wiki/Folate" title="Folate" class="mw-redirect">Folate</a> (vit. B<sub>9</sub>)\n</td>\n<td> 46 \u03bcg (12%)\n</td></tr>\n\n\n<tr>\n<td> <a href="/wiki/Vitamin_C" title="Vitamin C">Vitamin C</a>\n</td>\n<td> 19.5 mg (23%)\n</td></tr>\n\n\n\n\n\n<tr>\n<td> <a href="/wiki/Calcium#Nutrition" title="Calcium">Calcium</a>\n</td>\n<td> 39 mg (4%)\n</td></tr>\n<tr>\n<td> <a href="/wiki/Iron#Biological_role" title="Iron">Iron</a>\n</td>\n<td> 0.55 mg (4%)\n</td></tr>\n<tr>\n<td> <a href="/wiki/Magnesium_in_biology" title="Magnesium in biology">Magnesium</a>\n</td>\n<td> 28 mg (8%)\n</td></tr>\n<tr>\n<td> <a href="/wiki/Manganese#Biological_role" title="Manganese">Manganese</a>\n</td>\n<td> 0.688 mg (33%)\n</td></tr>\n<tr>\n<td> <a href="/wiki/Phosphorus#Biological_role" title="Phosphorus">Phosphorus</a>\n</td>\n<td> 39 mg (6%)\n</td></tr>\n<tr>\n<td> <a href="/wiki/Potassium#In_diet" title="Potassium">Potassium</a>\n</td>\n<td> 330 mg (7%)\n</td></tr>\n<tr>\n<td> <a href="/wiki/Sodium#Biological_role" title="Sodium">Sodium</a>\n</td>\n<td> 11 mg (1%)\n</td></tr>\n<tr>\n<td> <a href="/wiki/Zinc#Biological_role" title="Zinc">Zinc</a>\n</td>\n<td> 0.27 mg (3%)\n</td></tr>\n\n\n\n\n\n<tr style="background-color: #e0e0e0; font-size: 90%; text-align: center; padding: 4pt; line-height: 1.25em">\n<td colspan="2"> <a rel="nofollow" class="external text" href="http://ndb.nal.usda.gov/ndb/search/list?qlookup=11145&amp;format=Full">Link to USDA Database entry</a><br/>Percentages are roughly approximated<br>using <a href="/wiki/Dietary_Reference_Intake" title="Dietary Reference Intake">US recommendations</a> for adults.<br/><small>Source: <a rel="nofollow" class="external text" href="http://ndb.nal.usda.gov/ndb/search/list">USDA Nutrient Database</a></small>\n</td></tr></table>\n<p>The stem is usually harvested at a length of around 15\u201320&#160;cm and a diameter of around 3\u20134&#160;cm. It is crisp, moist, and mildly flavored, and typically prepared by slicing and then <a href="/wiki/Stir_frying" title="Stir frying">stir frying</a> with more strongly flavored ingredients.\n</p><p><br />\n</p>\n<table class="metadata plainlinks stub" style="background: transparent;" role="presentation"><tr>\n<td><a href="/wiki/File:VegCorn.jpg" class="image"><img alt="Stub icon" src="//upload.wikimedia.org/wikipedia/commons/thumb/7/79/VegCorn.jpg/40px-VegCorn.jpg" width="40" height="26" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/7/79/VegCorn.jpg/60px-VegCorn.jpg 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/7/79/VegCorn.jpg/80px-VegCorn.jpg 2x" /></a></td>\n<td><i>This <a href="/wiki/Vegetable" title="Vegetable">vegetable</a>-related article is a <a href="/wiki/Wikipedia:Stub" title="Wikipedia:Stub">stub</a>. You can help Wikipedia by <a class="external text" href="//en.wikipedia.org/w/index.php?title=Celtuce&amp;action=edit">expanding it</a>.</i><div class="noprint plainlinks hlist navbar mini" style="position: absolute; right: 15px; display: none;"><ul><li class="nv-view"><a href="/wiki/Template:Vegetable-stub" title="Template:Vegetable-stub"><span title="View this template" style="">v</span></a></li><li class="nv-talk"><a href="/wiki/Template_talk:Vegetable-stub" title="Template talk:Vegetable-stub"><span title="Discuss this template" style="">t</span></a></li><li class="nv-edit"><a class="external text" href="//en.wikipedia.org/w/index.php?title=Template:Vegetable-stub&amp;action=edit"><span title="Edit this template" style="">e</span></a></li></ul></div></td>\n</tr></table>\n'}], 'title': 'Celtuce'}}}},

(('action', 'parse'), ('prop', 'sections'), ('titles', 'Tropical Depression Ten (2005)')):
(('action', 'parse'), ('page', 'Tropical Depression Ten (2005)'), ('prop', 'sections')):
{'parse': {'sections': [{'index': '1', 'level': '2', 'fromtitle': 'Tropical_Depression_Ten_(2005)', 'toclevel': 1, 'number': '1', 'byteoffset': 1369, 'line': 'Meteorological history', 'anchor': 'Meteorological_history'}, {'index': '2', 'level': '2', 'fromtitle': 'Tropical_Depression_Ten_(2005)', 'toclevel': 1, 'number': '2', 'byteoffset': 6248, 'line': 'Impact', 'anchor': 'Impact'}, {'index': '3', 'level': '2', 'fromtitle': 'Tropical_Depression_Ten_(2005)', 'toclevel': 1, 'number': '3', 'byteoffset': 7678, 'line': 'See also', 'anchor': 'See_also'}, {'index': '4', 'level': '2', 'fromtitle': 'Tropical_Depression_Ten_(2005)', 'toclevel': 1, 'number': '4', 'byteoffset': 7885, 'line': 'References', 'anchor': 'References'}, {'index': '5', 'level': '2', 'fromtitle': 'Tropical_Depression_Ten_(2005)', 'toclevel': 1, 'number': '5', 'byteoffset': 7917, 'line': 'External links', 'anchor': 'External_links'}], 'title': 'Tropical Depression Ten (2005)'}},

(('limit', 10), ('list', 'search'), ('srlimit', 10), ('srprop', ''), ('srsearch', 'Barack Obama')):
Expand Down
3 changes: 2 additions & 1 deletion wikipedia/wikipedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ def sections(self):
'action': 'parse',
'prop': 'sections',
}
query_params.update(self.__title_query_param)
if not getattr(self, 'title', None) is None:
query_params["page"] = self.title

request = _wiki_request(query_params)
self._sections = [section['line'] for section in request['parse']['sections']]
Expand Down

0 comments on commit 1554943

Please sign in to comment.