From 961f590e96bbd7cc73fa202b5a5c79d60f6fa100 Mon Sep 17 00:00:00 2001 From: Sacha Vakili Date: Sat, 5 Sep 2020 11:44:41 +0200 Subject: [PATCH 1/3] use page instead of titles in the sections property --- wikipedia/wikipedia.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wikipedia/wikipedia.py b/wikipedia/wikipedia.py index 7ad50e1..7119ea1 100644 --- a/wikipedia/wikipedia.py +++ b/wikipedia/wikipedia.py @@ -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']] @@ -734,9 +735,13 @@ def _wiki_request(params): wait_time = (RATE_LIMIT_LAST_CALL + RATE_LIMIT_MIN_WAIT) - datetime.now() time.sleep(int(wait_time.total_seconds())) + print(f"GET request: {params}") + r = requests.get(API_URL, params=params, headers=headers) if RATE_LIMIT: RATE_LIMIT_LAST_CALL = datetime.now() + print(f"GET response: {r.json()}") + return r.json() From e28a912262b050eecc6286c6cd4e4d1d88c27aa5 Mon Sep 17 00:00:00 2001 From: Sacha Vakili Date: Sat, 5 Sep 2020 11:45:30 +0200 Subject: [PATCH 2/3] adapt the mocked answer in the tests --- tests/request_mock_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/request_mock_data.py b/tests/request_mock_data.py index cea34eb..0f82ec8 100644 --- a/tests/request_mock_data.py +++ b/tests/request_mock_data.py @@ -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': [{'*': '\n
Celtuce stems & heads
\n

Celtuce (Lactuca sativa var. asparagina, augustana, or angustata), also called stem lettuce, celery lettuce, asparagus lettuce, or Chinese lettuce, IPA (UK,US) /\u02c8s\u025blt.\u0259s/, is a cultivar of lettuce grown primarily for its thick stem, used as a vegetable. It is especially popular in China, and is called wosun (Chinese: \u83b4\u7b0b; pinyin: w\u014ds\u016dn) or woju (Chinese: \u83b4\u82e3; pinyin: w\u014dj\xf9) (although the latter name may also be used to mean lettuce in general).\n

\n
Celtuce (foreground) for sale in Lhasa
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Celtuce, raw\n\n
Nutritional value per 100 g (3.5 oz)\n
Energy\n 75 kJ (18 kcal)\n
Carbohydrates\n 3.65 g\n
- Dietary fiber\n 1.7 g\n
Fat\n 0.3 g\n
Protein\n 0.85 g\n
Vitamin A equiv.\n 175 \u03bcg (22%)\n
Thiamine (vit. B1)\n 0.055 mg (5%)\n
Riboflavin (vit. B2)\n 0.07 mg (6%)\n
Niacin (vit. B3)\n 0.55 mg (4%)\n
Pantothenic acid (B5)\n 0.183 mg (4%)\n
Vitamin B6\n 0.05 mg (4%)\n
Folate (vit. B9)\n 46 \u03bcg (12%)\n
Vitamin C\n 19.5 mg (23%)\n
Calcium\n 39 mg (4%)\n
Iron\n 0.55 mg (4%)\n
Magnesium\n 28 mg (8%)\n
Manganese\n 0.688 mg (33%)\n
Phosphorus\n 39 mg (6%)\n
Potassium\n 330 mg (7%)\n
Sodium\n 11 mg (1%)\n
Zinc\n 0.27 mg (3%)\n
Link to USDA Database entry
Percentages are roughly approximated
using US recommendations for adults.
Source: USDA Nutrient Database\n
\n

The stem is usually harvested at a length of around 15\u201320 cm and a diameter of around 3\u20134 cm. It is crisp, moist, and mildly flavored, and typically prepared by slicing and then stir frying with more strongly flavored ingredients.\n


\n

\n\n\n\n\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')): From 18fab92a35474decb80882f33ab03368da6bc26f Mon Sep 17 00:00:00 2001 From: Sacha Vakili Date: Sat, 5 Sep 2020 12:19:11 +0200 Subject: [PATCH 3/3] remove temporary logs --- wikipedia/wikipedia.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/wikipedia/wikipedia.py b/wikipedia/wikipedia.py index 7119ea1..040901a 100644 --- a/wikipedia/wikipedia.py +++ b/wikipedia/wikipedia.py @@ -735,13 +735,9 @@ def _wiki_request(params): wait_time = (RATE_LIMIT_LAST_CALL + RATE_LIMIT_MIN_WAIT) - datetime.now() time.sleep(int(wait_time.total_seconds())) - print(f"GET request: {params}") - r = requests.get(API_URL, params=params, headers=headers) if RATE_LIMIT: RATE_LIMIT_LAST_CALL = datetime.now() - print(f"GET response: {r.json()}") - return r.json()