repository_name
stringlengths
7
55
func_path_in_repository
stringlengths
4
223
func_name
stringlengths
1
134
whole_func_string
stringlengths
75
104k
language
stringclasses
1 value
func_code_string
stringlengths
75
104k
func_code_tokens
listlengths
19
28.4k
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
listlengths
1
1.97k
split_name
stringclasses
1 value
func_code_url
stringlengths
87
315
siznax/wptools
wptools/category.py
WPToolsCategory.get_random
def get_random(self, show=True, proxy=None, timeout=0): """ GET MediaWiki:API (action=query) for random category https://www.mediawiki.org/wiki/API:Random Required {params}: None Optional arguments: - [show]: <bool> echo page data if true - [proxy]: <str> use th...
python
def get_random(self, show=True, proxy=None, timeout=0): """ GET MediaWiki:API (action=query) for random category https://www.mediawiki.org/wiki/API:Random Required {params}: None Optional arguments: - [show]: <bool> echo page data if true - [proxy]: <str> use th...
[ "def", "get_random", "(", "self", ",", "show", "=", "True", ",", "proxy", "=", "None", ",", "timeout", "=", "0", ")", ":", "self", ".", "_get", "(", "'random'", ",", "show", ",", "proxy", ",", "timeout", ")", "# flush cache to allow repeated random request...
GET MediaWiki:API (action=query) for random category https://www.mediawiki.org/wiki/API:Random Required {params}: None Optional arguments: - [show]: <bool> echo page data if true - [proxy]: <str> use this HTTP proxy - [timeout]: <int> timeout in seconds (0=wait forever)...
[ "GET", "MediaWiki", ":", "API", "(", "action", "=", "query", ")", "for", "random", "category", "https", ":", "//", "www", ".", "mediawiki", ".", "org", "/", "wiki", "/", "API", ":", "Random" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/category.py#L154-L175
siznax/wptools
wptools/site.py
WPToolsSite._set_data
def _set_data(self, action): """ capture Wikidata API response data """ if action == 'siteinfo': self._set_siteinfo() elif action == 'sitematrix': self._set_sitematrix() elif action == 'sitevisitors': self._set_sitevisitors()
python
def _set_data(self, action): """ capture Wikidata API response data """ if action == 'siteinfo': self._set_siteinfo() elif action == 'sitematrix': self._set_sitematrix() elif action == 'sitevisitors': self._set_sitevisitors()
[ "def", "_set_data", "(", "self", ",", "action", ")", ":", "if", "action", "==", "'siteinfo'", ":", "self", ".", "_set_siteinfo", "(", ")", "elif", "action", "==", "'sitematrix'", ":", "self", ".", "_set_sitematrix", "(", ")", "elif", "action", "==", "'si...
capture Wikidata API response data
[ "capture", "Wikidata", "API", "response", "data" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/site.py#L50-L59
siznax/wptools
wptools/site.py
WPToolsSite._set_siteinfo
def _set_siteinfo(self): """ capture API sitematrix data in data attribute """ data = self._load_response('siteinfo').get('query') mostviewed = data.get('mostviewed') self.data['mostviewed'] = [] for item in mostviewed[1:]: if item['ns'] == 0: ...
python
def _set_siteinfo(self): """ capture API sitematrix data in data attribute """ data = self._load_response('siteinfo').get('query') mostviewed = data.get('mostviewed') self.data['mostviewed'] = [] for item in mostviewed[1:]: if item['ns'] == 0: ...
[ "def", "_set_siteinfo", "(", "self", ")", ":", "data", "=", "self", ".", "_load_response", "(", "'siteinfo'", ")", ".", "get", "(", "'query'", ")", "mostviewed", "=", "data", ".", "get", "(", "'mostviewed'", ")", "self", ".", "data", "[", "'mostviewed'",...
capture API sitematrix data in data attribute
[ "capture", "API", "sitematrix", "data", "in", "data", "attribute" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/site.py#L61-L96
siznax/wptools
wptools/site.py
WPToolsSite._set_sitematrix
def _set_sitematrix(self): """ capture API sitematrix data in data attribute """ data = self._load_response('sitematrix') self.params.update({'title': self.COMMONS}) matrix = data.get('sitematrix') if matrix: self.data['sites'] = self._sitelist(matri...
python
def _set_sitematrix(self): """ capture API sitematrix data in data attribute """ data = self._load_response('sitematrix') self.params.update({'title': self.COMMONS}) matrix = data.get('sitematrix') if matrix: self.data['sites'] = self._sitelist(matri...
[ "def", "_set_sitematrix", "(", "self", ")", ":", "data", "=", "self", ".", "_load_response", "(", "'sitematrix'", ")", "self", ".", "params", ".", "update", "(", "{", "'title'", ":", "self", ".", "COMMONS", "}", ")", "matrix", "=", "data", ".", "get", ...
capture API sitematrix data in data attribute
[ "capture", "API", "sitematrix", "data", "in", "data", "attribute" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/site.py#L98-L109
siznax/wptools
wptools/site.py
WPToolsSite._set_sitevisitors
def _set_sitevisitors(self): """ capture API pageview/visitor data in data attribute """ data = self._load_response('sitevisitors').get('query') siteviews = data.get('siteviews') if siteviews: values = [x for x in siteviews.values() if x] if value...
python
def _set_sitevisitors(self): """ capture API pageview/visitor data in data attribute """ data = self._load_response('sitevisitors').get('query') siteviews = data.get('siteviews') if siteviews: values = [x for x in siteviews.values() if x] if value...
[ "def", "_set_sitevisitors", "(", "self", ")", ":", "data", "=", "self", ".", "_load_response", "(", "'sitevisitors'", ")", ".", "get", "(", "'query'", ")", "siteviews", "=", "data", ".", "get", "(", "'siteviews'", ")", "if", "siteviews", ":", "values", "...
capture API pageview/visitor data in data attribute
[ "capture", "API", "pageview", "/", "visitor", "data", "in", "data", "attribute" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/site.py#L111-L123
siznax/wptools
wptools/site.py
WPToolsSite._sitelist
def _sitelist(self, matrix): """ Returns a list of sites from a SiteMatrix, optionally filtered by 'domain' param """ _list = [] for item in matrix: sites = [] if isinstance(matrix[item], list): sites = matrix[item] eli...
python
def _sitelist(self, matrix): """ Returns a list of sites from a SiteMatrix, optionally filtered by 'domain' param """ _list = [] for item in matrix: sites = [] if isinstance(matrix[item], list): sites = matrix[item] eli...
[ "def", "_sitelist", "(", "self", ",", "matrix", ")", ":", "_list", "=", "[", "]", "for", "item", "in", "matrix", ":", "sites", "=", "[", "]", "if", "isinstance", "(", "matrix", "[", "item", "]", ",", "list", ")", ":", "sites", "=", "matrix", "[",...
Returns a list of sites from a SiteMatrix, optionally filtered by 'domain' param
[ "Returns", "a", "list", "of", "sites", "from", "a", "SiteMatrix", "optionally", "filtered", "by", "domain", "param" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/site.py#L125-L149
siznax/wptools
wptools/site.py
WPToolsSite.get_info
def get_info(self, wiki=None, show=True, proxy=None, timeout=0): """ GET site info (general, statistics, siteviews, mostviewed) via https://www.mediawiki.org/wiki/API:Siteinfo, and https://www.mediawiki.org/wiki/Extension:PageViewInfo Optional arguments: - [wiki]: <str> ...
python
def get_info(self, wiki=None, show=True, proxy=None, timeout=0): """ GET site info (general, statistics, siteviews, mostviewed) via https://www.mediawiki.org/wiki/API:Siteinfo, and https://www.mediawiki.org/wiki/Extension:PageViewInfo Optional arguments: - [wiki]: <str> ...
[ "def", "get_info", "(", "self", ",", "wiki", "=", "None", ",", "show", "=", "True", ",", "proxy", "=", "None", ",", "timeout", "=", "0", ")", ":", "if", "wiki", ":", "self", ".", "params", ".", "update", "(", "{", "'wiki'", ":", "wiki", "}", ")...
GET site info (general, statistics, siteviews, mostviewed) via https://www.mediawiki.org/wiki/API:Siteinfo, and https://www.mediawiki.org/wiki/Extension:PageViewInfo Optional arguments: - [wiki]: <str> alternate wiki site (default=en.wikipedia.org) - [show]: <bool> echo page dat...
[ "GET", "site", "info", "(", "general", "statistics", "siteviews", "mostviewed", ")", "via", "https", ":", "//", "www", ".", "mediawiki", ".", "org", "/", "wiki", "/", "API", ":", "Siteinfo", "and", "https", ":", "//", "www", ".", "mediawiki", ".", "org...
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/site.py#L151-L178
siznax/wptools
wptools/site.py
WPToolsSite.get_sites
def get_sites(self, domain=None, show=True, proxy=None, timeout=0): """ GET Wikimedia sites via Extension:SiteMatrix https://www.mediawiki.org/wiki/Extension:SiteMatrix Optional params: - [domain]: filter sites on this domain, e.g. 'wiktionary.org' Optional arguments: ...
python
def get_sites(self, domain=None, show=True, proxy=None, timeout=0): """ GET Wikimedia sites via Extension:SiteMatrix https://www.mediawiki.org/wiki/Extension:SiteMatrix Optional params: - [domain]: filter sites on this domain, e.g. 'wiktionary.org' Optional arguments: ...
[ "def", "get_sites", "(", "self", ",", "domain", "=", "None", ",", "show", "=", "True", ",", "proxy", "=", "None", ",", "timeout", "=", "0", ")", ":", "if", "domain", ":", "self", ".", "params", ".", "update", "(", "{", "'domain'", ":", "domain", ...
GET Wikimedia sites via Extension:SiteMatrix https://www.mediawiki.org/wiki/Extension:SiteMatrix Optional params: - [domain]: filter sites on this domain, e.g. 'wiktionary.org' Optional arguments: - [show]: <bool> echo page data if true - [proxy]: <str> use this HTTP pr...
[ "GET", "Wikimedia", "sites", "via", "Extension", ":", "SiteMatrix", "https", ":", "//", "www", ".", "mediawiki", ".", "org", "/", "wiki", "/", "Extension", ":", "SiteMatrix" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/site.py#L180-L206
siznax/wptools
wptools/site.py
WPToolsSite.top
def top(self, wiki=None, limit=25): """ Print list of top viewed articles (ns=0) over the last WEEK https://www.mediawiki.org/wiki/Extension:PageViewInfo Optional params: - [wiki]: <str> alternate wiki site (default=en.wikipedia.org) - [limit]: <int> show up to limit art...
python
def top(self, wiki=None, limit=25): """ Print list of top viewed articles (ns=0) over the last WEEK https://www.mediawiki.org/wiki/Extension:PageViewInfo Optional params: - [wiki]: <str> alternate wiki site (default=en.wikipedia.org) - [limit]: <int> show up to limit art...
[ "def", "top", "(", "self", ",", "wiki", "=", "None", ",", "limit", "=", "25", ")", ":", "if", "wiki", ":", "self", ".", "params", ".", "update", "(", "{", "'wiki'", ":", "wiki", "}", ")", "if", "'siteinfo'", "not", "in", "self", ".", "cache", "...
Print list of top viewed articles (ns=0) over the last WEEK https://www.mediawiki.org/wiki/Extension:PageViewInfo Optional params: - [wiki]: <str> alternate wiki site (default=en.wikipedia.org) - [limit]: <int> show up to limit articles (max=500) See also: https://en.wi...
[ "Print", "list", "of", "top", "viewed", "articles", "(", "ns", "=", "0", ")", "over", "the", "last", "WEEK", "https", ":", "//", "www", ".", "mediawiki", ".", "org", "/", "wiki", "/", "Extension", ":", "PageViewInfo" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/site.py#L208-L235
siznax/wptools
wptools/core.py
handle_wikidata_errors
def handle_wikidata_errors(data, query): """ Raises LookupError if wikidata error found """ entities = data.get('entities') if not entities: raise LookupError(query) elif '-1' in entities: raise LookupError(query) else: item = list(entities.values())[0] if 'm...
python
def handle_wikidata_errors(data, query): """ Raises LookupError if wikidata error found """ entities = data.get('entities') if not entities: raise LookupError(query) elif '-1' in entities: raise LookupError(query) else: item = list(entities.values())[0] if 'm...
[ "def", "handle_wikidata_errors", "(", "data", ",", "query", ")", ":", "entities", "=", "data", ".", "get", "(", "'entities'", ")", "if", "not", "entities", ":", "raise", "LookupError", "(", "query", ")", "elif", "'-1'", "in", "entities", ":", "raise", "L...
Raises LookupError if wikidata error found
[ "Raises", "LookupError", "if", "wikidata", "error", "found" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/core.py#L294-L308
siznax/wptools
wptools/core.py
prettyprint
def prettyprint(datastr): """ Print page data strings to stderr """ maxwidth = WPToolsQuery.MAXWIDTH rpad = WPToolsQuery.RPAD extent = maxwidth - (rpad + 2) for line in datastr: if len(line) >= maxwidth: line = line[:extent] + '...' utils.stderr(line)
python
def prettyprint(datastr): """ Print page data strings to stderr """ maxwidth = WPToolsQuery.MAXWIDTH rpad = WPToolsQuery.RPAD extent = maxwidth - (rpad + 2) for line in datastr: if len(line) >= maxwidth: line = line[:extent] + '...' utils.stderr(line)
[ "def", "prettyprint", "(", "datastr", ")", ":", "maxwidth", "=", "WPToolsQuery", ".", "MAXWIDTH", "rpad", "=", "WPToolsQuery", ".", "RPAD", "extent", "=", "maxwidth", "-", "(", "rpad", "+", "2", ")", "for", "line", "in", "datastr", ":", "if", "len", "(...
Print page data strings to stderr
[ "Print", "page", "data", "strings", "to", "stderr" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/core.py#L311-L322
siznax/wptools
wptools/core.py
WPTools._build_showstr
def _build_showstr(self, seed): """ Returns show() display string for data attribute """ output = ["%s (%s) data" % (seed, self.params['lang'])] output.append('{') maxwidth = WPToolsQuery.MAXWIDTH for item in sorted(self.data): if self.data[item] i...
python
def _build_showstr(self, seed): """ Returns show() display string for data attribute """ output = ["%s (%s) data" % (seed, self.params['lang'])] output.append('{') maxwidth = WPToolsQuery.MAXWIDTH for item in sorted(self.data): if self.data[item] i...
[ "def", "_build_showstr", "(", "self", ",", "seed", ")", ":", "output", "=", "[", "\"%s (%s) data\"", "%", "(", "seed", ",", "self", ".", "params", "[", "'lang'", "]", ")", "]", "output", ".", "append", "(", "'{'", ")", "maxwidth", "=", "WPToolsQuery", ...
Returns show() display string for data attribute
[ "Returns", "show", "()", "display", "string", "for", "data", "attribute" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/core.py#L63-L105
siznax/wptools
wptools/core.py
WPTools._continue_params
def _continue_params(self): """ Returns query string fragment continue parameters """ if not self.data.get('continue'): return params = [] for item in self.data['continue']: params.append("&%s=%s" % (item, self.data['continue'][item])) re...
python
def _continue_params(self): """ Returns query string fragment continue parameters """ if not self.data.get('continue'): return params = [] for item in self.data['continue']: params.append("&%s=%s" % (item, self.data['continue'][item])) re...
[ "def", "_continue_params", "(", "self", ")", ":", "if", "not", "self", ".", "data", ".", "get", "(", "'continue'", ")", ":", "return", "params", "=", "[", "]", "for", "item", "in", "self", ".", "data", "[", "'continue'", "]", ":", "params", ".", "a...
Returns query string fragment continue parameters
[ "Returns", "query", "string", "fragment", "continue", "parameters" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/core.py#L107-L118
siznax/wptools
wptools/core.py
WPTools._handle_continuations
def _handle_continuations(self, response, cache_key): """ Select continue params and clear cache or last continue params """ rcontinue = response.get('continue') listen = ['blcontinue', 'cmcontinue', 'plcontinue'] cparams = {} if rcontinue: for flag i...
python
def _handle_continuations(self, response, cache_key): """ Select continue params and clear cache or last continue params """ rcontinue = response.get('continue') listen = ['blcontinue', 'cmcontinue', 'plcontinue'] cparams = {} if rcontinue: for flag i...
[ "def", "_handle_continuations", "(", "self", ",", "response", ",", "cache_key", ")", ":", "rcontinue", "=", "response", ".", "get", "(", "'continue'", ")", "listen", "=", "[", "'blcontinue'", ",", "'cmcontinue'", ",", "'plcontinue'", "]", "cparams", "=", "{"...
Select continue params and clear cache or last continue params
[ "Select", "continue", "params", "and", "clear", "cache", "or", "last", "continue", "params" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/core.py#L120-L138
siznax/wptools
wptools/core.py
WPTools._get
def _get(self, action, show, proxy, timeout): """ make HTTP request and cache response """ silent = self.flags['silent'] if action in self.cache: if action != 'imageinfo' and action != 'labels': utils.stderr("+ %s results in cache" % action, silent) ...
python
def _get(self, action, show, proxy, timeout): """ make HTTP request and cache response """ silent = self.flags['silent'] if action in self.cache: if action != 'imageinfo' and action != 'labels': utils.stderr("+ %s results in cache" % action, silent) ...
[ "def", "_get", "(", "self", ",", "action", ",", "show", ",", "proxy", ",", "timeout", ")", ":", "silent", "=", "self", ".", "flags", "[", "'silent'", "]", "if", "action", "in", "self", ".", "cache", ":", "if", "action", "!=", "'imageinfo'", "and", ...
make HTTP request and cache response
[ "make", "HTTP", "request", "and", "cache", "response" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/core.py#L140-L186
siznax/wptools
wptools/core.py
WPTools._load_response
def _load_response(self, action): """ returns API reponse from cache or raises ValueError """ _query = self.cache[action]['query'].replace('&format=json', '') response = self.cache[action]['response'] if not response: raise ValueError("Empty response: %s" % s...
python
def _load_response(self, action): """ returns API reponse from cache or raises ValueError """ _query = self.cache[action]['query'].replace('&format=json', '') response = self.cache[action]['response'] if not response: raise ValueError("Empty response: %s" % s...
[ "def", "_load_response", "(", "self", ",", "action", ")", ":", "_query", "=", "self", ".", "cache", "[", "action", "]", "[", "'query'", "]", ".", "replace", "(", "'&format=json'", ",", "''", ")", "response", "=", "self", ".", "cache", "[", "action", ...
returns API reponse from cache or raises ValueError
[ "returns", "API", "reponse", "from", "cache", "or", "raises", "ValueError" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/core.py#L188-L224
siznax/wptools
wptools/core.py
WPTools._request
def _request(self, proxy, timeout): """ Returns WPToolsRequest object """ return request.WPToolsRequest(self.flags['silent'], self.flags['verbose'], proxy, timeout)
python
def _request(self, proxy, timeout): """ Returns WPToolsRequest object """ return request.WPToolsRequest(self.flags['silent'], self.flags['verbose'], proxy, timeout)
[ "def", "_request", "(", "self", ",", "proxy", ",", "timeout", ")", ":", "return", "request", ".", "WPToolsRequest", "(", "self", ".", "flags", "[", "'silent'", "]", ",", "self", ".", "flags", "[", "'verbose'", "]", ",", "proxy", ",", "timeout", ")" ]
Returns WPToolsRequest object
[ "Returns", "WPToolsRequest", "object" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/core.py#L232-L238
siznax/wptools
wptools/core.py
WPTools.info
def info(self, action=None): """ returns cached request info for given action, or list of cached actions """ if action in self.cache: return self.cache[action]['info'] return self.cache.keys() or None
python
def info(self, action=None): """ returns cached request info for given action, or list of cached actions """ if action in self.cache: return self.cache[action]['info'] return self.cache.keys() or None
[ "def", "info", "(", "self", ",", "action", "=", "None", ")", ":", "if", "action", "in", "self", ".", "cache", ":", "return", "self", ".", "cache", "[", "action", "]", "[", "'info'", "]", "return", "self", ".", "cache", ".", "keys", "(", ")", "or"...
returns cached request info for given action, or list of cached actions
[ "returns", "cached", "request", "info", "for", "given", "action", "or", "list", "of", "cached", "actions" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/core.py#L246-L253
siznax/wptools
wptools/core.py
WPTools.query
def query(self, action=None): """ returns cached query string (without &format=json) for given action, or list of cached actions """ if action in self.cache: return self.cache[action]['query'].replace('&format=json', '') return self.cache.keys() or None
python
def query(self, action=None): """ returns cached query string (without &format=json) for given action, or list of cached actions """ if action in self.cache: return self.cache[action]['query'].replace('&format=json', '') return self.cache.keys() or None
[ "def", "query", "(", "self", ",", "action", "=", "None", ")", ":", "if", "action", "in", "self", ".", "cache", ":", "return", "self", ".", "cache", "[", "action", "]", "[", "'query'", "]", ".", "replace", "(", "'&format=json'", ",", "''", ")", "ret...
returns cached query string (without &format=json) for given action, or list of cached actions
[ "returns", "cached", "query", "string", "(", "without", "&format", "=", "json", ")", "for", "given", "action", "or", "list", "of", "cached", "actions" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/core.py#L255-L262
siznax/wptools
wptools/core.py
WPTools.response
def response(self, action=None): """ returns cached response (as dict) for given action, or list of cached actions """ if action in self.cache: return utils.json_loads(self.cache[action]['response']) return self.cache.keys() or None
python
def response(self, action=None): """ returns cached response (as dict) for given action, or list of cached actions """ if action in self.cache: return utils.json_loads(self.cache[action]['response']) return self.cache.keys() or None
[ "def", "response", "(", "self", ",", "action", "=", "None", ")", ":", "if", "action", "in", "self", ".", "cache", ":", "return", "utils", ".", "json_loads", "(", "self", ".", "cache", "[", "action", "]", "[", "'response'", "]", ")", "return", "self",...
returns cached response (as dict) for given action, or list of cached actions
[ "returns", "cached", "response", "(", "as", "dict", ")", "for", "given", "action", "or", "list", "of", "cached", "actions" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/core.py#L264-L271
siznax/wptools
wptools/core.py
WPTools.show
def show(self): """ Pretty-print instance data """ if not self.data: return if self.data.get('continue'): return ptitle = self.params.get('title') dtitle = self.data.get('title') pageid = self.params.get('pageid') seed = ...
python
def show(self): """ Pretty-print instance data """ if not self.data: return if self.data.get('continue'): return ptitle = self.params.get('title') dtitle = self.data.get('title') pageid = self.params.get('pageid') seed = ...
[ "def", "show", "(", "self", ")", ":", "if", "not", "self", ".", "data", ":", "return", "if", "self", ".", "data", ".", "get", "(", "'continue'", ")", ":", "return", "ptitle", "=", "self", ".", "params", ".", "get", "(", "'title'", ")", "dtitle", ...
Pretty-print instance data
[ "Pretty", "-", "print", "instance", "data" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/core.py#L273-L291
siznax/wptools
wptools/wikidata.py
reduce_claims
def reduce_claims(query_claims): """ returns claims as reduced dict {P: [Q's or values]} P = property Q = item """ claims = collections.defaultdict(list) for claim, entities in query_claims.items(): for ent in entities: try: snak = ent.get('main...
python
def reduce_claims(query_claims): """ returns claims as reduced dict {P: [Q's or values]} P = property Q = item """ claims = collections.defaultdict(list) for claim, entities in query_claims.items(): for ent in entities: try: snak = ent.get('main...
[ "def", "reduce_claims", "(", "query_claims", ")", ":", "claims", "=", "collections", ".", "defaultdict", "(", "list", ")", "for", "claim", ",", "entities", "in", "query_claims", ".", "items", "(", ")", ":", "for", "ent", "in", "entities", ":", "try", ":"...
returns claims as reduced dict {P: [Q's or values]} P = property Q = item
[ "returns", "claims", "as", "reduced", "dict", "{", "P", ":", "[", "Q", "s", "or", "values", "]", "}", "P", "=", "property", "Q", "=", "item" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/wikidata.py#L350-L388
siznax/wptools
wptools/wikidata.py
WPToolsWikidata._get_entity_prop
def _get_entity_prop(self, entity, prop): """ returns Wikidata entity property value """ variant = self.params.get('variant') lang = self.params.get('lang') if entity.get(prop): ent = entity[prop] try: return ent[variant or lang].g...
python
def _get_entity_prop(self, entity, prop): """ returns Wikidata entity property value """ variant = self.params.get('variant') lang = self.params.get('lang') if entity.get(prop): ent = entity[prop] try: return ent[variant or lang].g...
[ "def", "_get_entity_prop", "(", "self", ",", "entity", ",", "prop", ")", ":", "variant", "=", "self", ".", "params", ".", "get", "(", "'variant'", ")", "lang", "=", "self", ".", "params", ".", "get", "(", "'lang'", ")", "if", "entity", ".", "get", ...
returns Wikidata entity property value
[ "returns", "Wikidata", "entity", "property", "value" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/wikidata.py#L49-L61
siznax/wptools
wptools/wikidata.py
WPToolsWikidata._marshal_claims
def _marshal_claims(self, query_claims): """ set Wikidata entities from query claims """ claims = reduce_claims(query_claims) # self.data['claimq'] = query_claims self.data['claims'] = claims entities = set() for eid in claims: if self.user_la...
python
def _marshal_claims(self, query_claims): """ set Wikidata entities from query claims """ claims = reduce_claims(query_claims) # self.data['claimq'] = query_claims self.data['claims'] = claims entities = set() for eid in claims: if self.user_la...
[ "def", "_marshal_claims", "(", "self", ",", "query_claims", ")", ":", "claims", "=", "reduce_claims", "(", "query_claims", ")", "# self.data['claimq'] = query_claims", "self", ".", "data", "[", "'claims'", "]", "=", "claims", "entities", "=", "set", "(", ")", ...
set Wikidata entities from query claims
[ "set", "Wikidata", "entities", "from", "query", "claims" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/wikidata.py#L63-L85
siznax/wptools
wptools/wikidata.py
WPToolsWikidata._pop_entities
def _pop_entities(self, limit=50): """ returns up to limit entities and pops them off the list """ pop = self.data['entities'][:limit] del self.data['entities'][:limit] return pop
python
def _pop_entities(self, limit=50): """ returns up to limit entities and pops them off the list """ pop = self.data['entities'][:limit] del self.data['entities'][:limit] return pop
[ "def", "_pop_entities", "(", "self", ",", "limit", "=", "50", ")", ":", "pop", "=", "self", ".", "data", "[", "'entities'", "]", "[", ":", "limit", "]", "del", "self", ".", "data", "[", "'entities'", "]", "[", ":", "limit", "]", "return", "pop" ]
returns up to limit entities and pops them off the list
[ "returns", "up", "to", "limit", "entities", "and", "pops", "them", "off", "the", "list" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/wikidata.py#L87-L93
siznax/wptools
wptools/wikidata.py
WPToolsWikidata._query
def _query(self, action, qobj): """ returns wikidata query string """ if action == 'labels': return qobj.labels(self._pop_entities()) elif action == 'wikidata': return qobj.wikidata(self.params.get('title'), self.params.get...
python
def _query(self, action, qobj): """ returns wikidata query string """ if action == 'labels': return qobj.labels(self._pop_entities()) elif action == 'wikidata': return qobj.wikidata(self.params.get('title'), self.params.get...
[ "def", "_query", "(", "self", ",", "action", ",", "qobj", ")", ":", "if", "action", "==", "'labels'", ":", "return", "qobj", ".", "labels", "(", "self", ".", "_pop_entities", "(", ")", ")", "elif", "action", "==", "'wikidata'", ":", "return", "qobj", ...
returns wikidata query string
[ "returns", "wikidata", "query", "string" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/wikidata.py#L103-L111
siznax/wptools
wptools/wikidata.py
WPToolsWikidata._set_data
def _set_data(self, action): """ capture Wikidata API response data """ if action == 'labels': self._set_labels() if action == 'wikidata': self._set_wikidata() self.get_labels(show=False)
python
def _set_data(self, action): """ capture Wikidata API response data """ if action == 'labels': self._set_labels() if action == 'wikidata': self._set_wikidata() self.get_labels(show=False)
[ "def", "_set_data", "(", "self", ",", "action", ")", ":", "if", "action", "==", "'labels'", ":", "self", ".", "_set_labels", "(", ")", "if", "action", "==", "'wikidata'", ":", "self", ".", "_set_wikidata", "(", ")", "self", ".", "get_labels", "(", "sho...
capture Wikidata API response data
[ "capture", "Wikidata", "API", "response", "data" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/wikidata.py#L113-L122
siznax/wptools
wptools/wikidata.py
WPToolsWikidata._set_labels
def _set_labels(self): """ set entity labels from get_labels() """ data = self._load_response('labels') entities = data.get('entities') or [] for ent in entities: label = self._get_entity_prop(entities[ent], 'labels') self.data['labels'][ent] = la...
python
def _set_labels(self): """ set entity labels from get_labels() """ data = self._load_response('labels') entities = data.get('entities') or [] for ent in entities: label = self._get_entity_prop(entities[ent], 'labels') self.data['labels'][ent] = la...
[ "def", "_set_labels", "(", "self", ")", ":", "data", "=", "self", ".", "_load_response", "(", "'labels'", ")", "entities", "=", "data", ".", "get", "(", "'entities'", ")", "or", "[", "]", "for", "ent", "in", "entities", ":", "label", "=", "self", "."...
set entity labels from get_labels()
[ "set", "entity", "labels", "from", "get_labels", "()" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/wikidata.py#L124-L133
siznax/wptools
wptools/wikidata.py
WPToolsWikidata._set_title
def _set_title(self, item): """ attempt to set title from wikidata """ title = None lang = self.params['lang'] label = self.data['label'] if item.get('sitelinks'): for link in item['sitelinks']: if link == "%swiki" % lang: ...
python
def _set_title(self, item): """ attempt to set title from wikidata """ title = None lang = self.params['lang'] label = self.data['label'] if item.get('sitelinks'): for link in item['sitelinks']: if link == "%swiki" % lang: ...
[ "def", "_set_title", "(", "self", ",", "item", ")", ":", "title", "=", "None", "lang", "=", "self", ".", "params", "[", "'lang'", "]", "label", "=", "self", ".", "data", "[", "'label'", "]", "if", "item", ".", "get", "(", "'sitelinks'", ")", ":", ...
attempt to set title from wikidata
[ "attempt", "to", "set", "title", "from", "wikidata" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/wikidata.py#L135-L153
siznax/wptools
wptools/wikidata.py
WPToolsWikidata._set_wikidata
def _set_wikidata(self): """ set attributes derived from Wikidata (action=wbentities) """ self.data['labels'] = {} self.data['wikidata'] = {} data = self._load_response('wikidata') entities = data.get('entities') item = entities.get(next(iter(entities))) ...
python
def _set_wikidata(self): """ set attributes derived from Wikidata (action=wbentities) """ self.data['labels'] = {} self.data['wikidata'] = {} data = self._load_response('wikidata') entities = data.get('entities') item = entities.get(next(iter(entities))) ...
[ "def", "_set_wikidata", "(", "self", ")", ":", "self", ".", "data", "[", "'labels'", "]", "=", "{", "}", "self", ".", "data", "[", "'wikidata'", "]", "=", "{", "}", "data", "=", "self", ".", "_load_response", "(", "'wikidata'", ")", "entities", "=", ...
set attributes derived from Wikidata (action=wbentities)
[ "set", "attributes", "derived", "from", "Wikidata", "(", "action", "=", "wbentities", ")" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/wikidata.py#L155-L188
siznax/wptools
wptools/wikidata.py
WPToolsWikidata._update_images
def _update_images(self): """ add images from Wikidata """ wd_images = self.data['claims'].get('P18') # image if wd_images: if not isinstance(wd_images, list): wd_images = [wd_images] if 'image' not in self.data: self.dat...
python
def _update_images(self): """ add images from Wikidata """ wd_images = self.data['claims'].get('P18') # image if wd_images: if not isinstance(wd_images, list): wd_images = [wd_images] if 'image' not in self.data: self.dat...
[ "def", "_update_images", "(", "self", ")", ":", "wd_images", "=", "self", ".", "data", "[", "'claims'", "]", ".", "get", "(", "'P18'", ")", "# image", "if", "wd_images", ":", "if", "not", "isinstance", "(", "wd_images", ",", "list", ")", ":", "wd_image...
add images from Wikidata
[ "add", "images", "from", "Wikidata" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/wikidata.py#L190-L205
siznax/wptools
wptools/wikidata.py
WPToolsWikidata._update_what
def _update_what(self): """ set what this thing is! "instance of (P31)" """ if 'P31' not in self.data['claims']: # missing Wikidata msg = ("Note: Wikidata item %s" % self.data['wikibase'], "missing 'instance of' (P31)") utils.stderr(" ".join(ms...
python
def _update_what(self): """ set what this thing is! "instance of (P31)" """ if 'P31' not in self.data['claims']: # missing Wikidata msg = ("Note: Wikidata item %s" % self.data['wikibase'], "missing 'instance of' (P31)") utils.stderr(" ".join(ms...
[ "def", "_update_what", "(", "self", ")", ":", "if", "'P31'", "not", "in", "self", ".", "data", "[", "'claims'", "]", ":", "# missing Wikidata", "msg", "=", "(", "\"Note: Wikidata item %s\"", "%", "self", ".", "data", "[", "'wikibase'", "]", ",", "\"missing...
set what this thing is! "instance of (P31)"
[ "set", "what", "this", "thing", "is!", "instance", "of", "(", "P31", ")" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/wikidata.py#L207-L221
siznax/wptools
wptools/wikidata.py
WPToolsWikidata._update_wikidata
def _update_wikidata(self): """ set wikidata from claims and labels """ claims = self.data['claims'] for ent in claims: plabel = self.data['labels'].get(ent) # P (property) label if plabel: plabel = "%s (%s)" % (plabel, ent) ...
python
def _update_wikidata(self): """ set wikidata from claims and labels """ claims = self.data['claims'] for ent in claims: plabel = self.data['labels'].get(ent) # P (property) label if plabel: plabel = "%s (%s)" % (plabel, ent) ...
[ "def", "_update_wikidata", "(", "self", ")", ":", "claims", "=", "self", ".", "data", "[", "'claims'", "]", "for", "ent", "in", "claims", ":", "plabel", "=", "self", ".", "data", "[", "'labels'", "]", ".", "get", "(", "ent", ")", "# P (property) label"...
set wikidata from claims and labels
[ "set", "wikidata", "from", "claims", "and", "labels" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/wikidata.py#L223-L249
siznax/wptools
wptools/wikidata.py
WPToolsWikidata.get_labels
def get_labels(self, show=False, proxy=None, timeout=0): """ GET Wikidata:API (action=wbgetentities) for claims labels https://www.wikidata.org/w/api.php?action=help&modules=wbgetentities Required {data}: entities, claims data['claims']: {'P17': ['Q17'], 'P910': ['Q8854938']...
python
def get_labels(self, show=False, proxy=None, timeout=0): """ GET Wikidata:API (action=wbgetentities) for claims labels https://www.wikidata.org/w/api.php?action=help&modules=wbgetentities Required {data}: entities, claims data['claims']: {'P17': ['Q17'], 'P910': ['Q8854938']...
[ "def", "get_labels", "(", "self", ",", "show", "=", "False", ",", "proxy", "=", "None", ",", "timeout", "=", "0", ")", ":", "if", "'entities'", "not", "in", "self", ".", "data", ":", "utils", ".", "stderr", "(", "\"No entities found.\"", ")", "return",...
GET Wikidata:API (action=wbgetentities) for claims labels https://www.wikidata.org/w/api.php?action=help&modules=wbgetentities Required {data}: entities, claims data['claims']: {'P17': ['Q17'], 'P910': ['Q8854938'], ...} data['entities']: ['P17', 'Q17', 'P910', 'Q8854938', ...] ...
[ "GET", "Wikidata", ":", "API", "(", "action", "=", "wbgetentities", ")", "for", "claims", "labels", "https", ":", "//", "www", ".", "wikidata", ".", "org", "/", "w", "/", "api", ".", "php?action", "=", "help&modules", "=", "wbgetentities" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/wikidata.py#L251-L284
siznax/wptools
wptools/wikidata.py
WPToolsWikidata.get_wikidata
def get_wikidata(self, show=True, proxy=None, timeout=0): """ GET Wikidata:API (action=wbgetentities) wikidata https://www.wikidata.org/w/api.php?action=help&modules=wbgetentities Required {params}: title OR wikibase - title: <str> Mediawiki page title, file, category, etc. ...
python
def get_wikidata(self, show=True, proxy=None, timeout=0): """ GET Wikidata:API (action=wbgetentities) wikidata https://www.wikidata.org/w/api.php?action=help&modules=wbgetentities Required {params}: title OR wikibase - title: <str> Mediawiki page title, file, category, etc. ...
[ "def", "get_wikidata", "(", "self", ",", "show", "=", "True", ",", "proxy", "=", "None", ",", "timeout", "=", "0", ")", ":", "title", "=", "self", ".", "params", ".", "get", "(", "'title'", ")", "wikibase", "=", "self", ".", "params", ".", "get", ...
GET Wikidata:API (action=wbgetentities) wikidata https://www.wikidata.org/w/api.php?action=help&modules=wbgetentities Required {params}: title OR wikibase - title: <str> Mediawiki page title, file, category, etc. - wikibase: <str> Wikidata item ID Optional {params}: - [...
[ "GET", "Wikidata", ":", "API", "(", "action", "=", "wbgetentities", ")", "wikidata", "https", ":", "//", "www", ".", "wikidata", ".", "org", "/", "w", "/", "api", ".", "php?action", "=", "help&modules", "=", "wbgetentities" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/wikidata.py#L286-L329
siznax/wptools
wptools/wikidata.py
WPToolsWikidata.wanted_labels
def wanted_labels(self, labels): """ Specify only WANTED labels to minimize get_labels() requests Args: - labels: <list> of wanted labels. Example: page.wanted_labels(['P18', 'P31']) """ if not isinstance(labels, list): raise ValueError("In...
python
def wanted_labels(self, labels): """ Specify only WANTED labels to minimize get_labels() requests Args: - labels: <list> of wanted labels. Example: page.wanted_labels(['P18', 'P31']) """ if not isinstance(labels, list): raise ValueError("In...
[ "def", "wanted_labels", "(", "self", ",", "labels", ")", ":", "if", "not", "isinstance", "(", "labels", ",", "list", ")", ":", "raise", "ValueError", "(", "\"Input labels must be a list.\"", ")", "self", ".", "user_labels", "=", "labels" ]
Specify only WANTED labels to minimize get_labels() requests Args: - labels: <list> of wanted labels. Example: page.wanted_labels(['P18', 'P31'])
[ "Specify", "only", "WANTED", "labels", "to", "minimize", "get_labels", "()", "requests" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/wikidata.py#L331-L344
siznax/wptools
scripts/wptool.py
_html_image
def _html_image(page): """ returns HTML img tag """ source = _image(page) if not source: return alt = page.data.get('label') or page.data.get('title') img = "<img src=\"%s\"" % source img += " alt=\"%s\" title=\"%s\" " % (alt, alt) img += "align=\"right\" width=\"240\">" ...
python
def _html_image(page): """ returns HTML img tag """ source = _image(page) if not source: return alt = page.data.get('label') or page.data.get('title') img = "<img src=\"%s\"" % source img += " alt=\"%s\" title=\"%s\" " % (alt, alt) img += "align=\"right\" width=\"240\">" ...
[ "def", "_html_image", "(", "page", ")", ":", "source", "=", "_image", "(", "page", ")", "if", "not", "source", ":", "return", "alt", "=", "page", ".", "data", ".", "get", "(", "'label'", ")", "or", "page", ".", "data", ".", "get", "(", "'title'", ...
returns HTML img tag
[ "returns", "HTML", "img", "tag" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/scripts/wptool.py#L19-L30
siznax/wptools
scripts/wptool.py
_html_title
def _html_title(page): """ returns Wiki-linked HTML title """ link = "<a href=\"%s\">%s</a>" % (page.data.get('url'), page.data.get('title')) desc = page.data.get('description') if desc: link += "&mdash;<i>%s</i>" % desc else: link += "&m...
python
def _html_title(page): """ returns Wiki-linked HTML title """ link = "<a href=\"%s\">%s</a>" % (page.data.get('url'), page.data.get('title')) desc = page.data.get('description') if desc: link += "&mdash;<i>%s</i>" % desc else: link += "&m...
[ "def", "_html_title", "(", "page", ")", ":", "link", "=", "\"<a href=\\\"%s\\\">%s</a>\"", "%", "(", "page", ".", "data", ".", "get", "(", "'url'", ")", ",", "page", ".", "data", ".", "get", "(", "'title'", ")", ")", "desc", "=", "page", ".", "data",...
returns Wiki-linked HTML title
[ "returns", "Wiki", "-", "linked", "HTML", "title" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/scripts/wptool.py#L33-L45
siznax/wptools
scripts/wptool.py
_page_html
def _page_html(page): """ returns assembled HTML output """ out = [] out.append(_html_title(page)) out.append(_html_image(page)) out.append(page.data.get('extract')) return "\n".join([x for x in out if x])
python
def _page_html(page): """ returns assembled HTML output """ out = [] out.append(_html_title(page)) out.append(_html_image(page)) out.append(page.data.get('extract')) return "\n".join([x for x in out if x])
[ "def", "_page_html", "(", "page", ")", ":", "out", "=", "[", "]", "out", ".", "append", "(", "_html_title", "(", "page", ")", ")", "out", ".", "append", "(", "_html_image", "(", "page", ")", ")", "out", ".", "append", "(", "page", ".", "data", "....
returns assembled HTML output
[ "returns", "assembled", "HTML", "output" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/scripts/wptool.py#L57-L65
siznax/wptools
scripts/wptool.py
_page_text
def _page_text(page, nowrap=False): """ returns assembled text output """ title = page.data['title'] title = "%s\n%s" % (title, "=" * len(title)) desc = page.data.get('description') if desc: desc = "_%s_" % desc img = _text_image(page) pars = page.data.get('extext') i...
python
def _page_text(page, nowrap=False): """ returns assembled text output """ title = page.data['title'] title = "%s\n%s" % (title, "=" * len(title)) desc = page.data.get('description') if desc: desc = "_%s_" % desc img = _text_image(page) pars = page.data.get('extext') i...
[ "def", "_page_text", "(", "page", ",", "nowrap", "=", "False", ")", ":", "title", "=", "page", ".", "data", "[", "'title'", "]", "title", "=", "\"%s\\n%s\"", "%", "(", "title", ",", "\"=\"", "*", "len", "(", "title", ")", ")", "desc", "=", "page", ...
returns assembled text output
[ "returns", "assembled", "text", "output" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/scripts/wptool.py#L68-L107
siznax/wptools
scripts/wptool.py
_safe_exit
def _safe_exit(start, output): """ exit without breaking pipes """ try: sys.stdout.write(output) sys.stdout.flush() except TypeError: # python3 sys.stdout.write(str(output, 'utf-8')) sys.stdout.flush() except IOError: pass seconds = time.time() - sta...
python
def _safe_exit(start, output): """ exit without breaking pipes """ try: sys.stdout.write(output) sys.stdout.flush() except TypeError: # python3 sys.stdout.write(str(output, 'utf-8')) sys.stdout.flush() except IOError: pass seconds = time.time() - sta...
[ "def", "_safe_exit", "(", "start", ",", "output", ")", ":", "try", ":", "sys", ".", "stdout", ".", "write", "(", "output", ")", "sys", ".", "stdout", ".", "flush", "(", ")", "except", "TypeError", ":", "# python3", "sys", ".", "stdout", ".", "write",...
exit without breaking pipes
[ "exit", "without", "breaking", "pipes" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/scripts/wptool.py#L110-L124
siznax/wptools
scripts/wptool.py
_text_image
def _text_image(page): """ returns text image URL """ img = None alt = page.data.get('label') or page.data.get('title') source = _image(page) if source: img = "![%s](%s)" % (alt, source) return img
python
def _text_image(page): """ returns text image URL """ img = None alt = page.data.get('label') or page.data.get('title') source = _image(page) if source: img = "![%s](%s)" % (alt, source) return img
[ "def", "_text_image", "(", "page", ")", ":", "img", "=", "None", "alt", "=", "page", ".", "data", ".", "get", "(", "'label'", ")", "or", "page", ".", "data", ".", "get", "(", "'title'", ")", "source", "=", "_image", "(", "page", ")", "if", "sourc...
returns text image URL
[ "returns", "text", "image", "URL" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/scripts/wptool.py#L127-L136
siznax/wptools
scripts/wptool.py
get
def get(args): """ invoke wptools and assemble selected output """ html = args.H lang = args.l nowrap = args.n query = args.q silent = args.s title = args.t verbose = args.v wiki = args.w if query: qobj = WPToolsQuery(lang=lang, wiki=wiki) if title: ...
python
def get(args): """ invoke wptools and assemble selected output """ html = args.H lang = args.l nowrap = args.n query = args.q silent = args.s title = args.t verbose = args.v wiki = args.w if query: qobj = WPToolsQuery(lang=lang, wiki=wiki) if title: ...
[ "def", "get", "(", "args", ")", ":", "html", "=", "args", ".", "H", "lang", "=", "args", ".", "l", "nowrap", "=", "args", ".", "n", "query", "=", "args", ".", "q", "silent", "=", "args", ".", "s", "title", "=", "args", ".", "t", "verbose", "=...
invoke wptools and assemble selected output
[ "invoke", "wptools", "and", "assemble", "selected", "output" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/scripts/wptool.py#L139-L177
siznax/wptools
scripts/wptool.py
parse_args
def parse_args(): """ parse main() args """ description = ( "Get Wikipedia article info and Wikidata via MediaWiki APIs.\n\n" "Gets a random English Wikipedia article by default, or in the\n" "language -lang, or from the wikisite -wiki, or by specific\n" "title -title. Th...
python
def parse_args(): """ parse main() args """ description = ( "Get Wikipedia article info and Wikidata via MediaWiki APIs.\n\n" "Gets a random English Wikipedia article by default, or in the\n" "language -lang, or from the wikisite -wiki, or by specific\n" "title -title. Th...
[ "def", "parse_args", "(", ")", ":", "description", "=", "(", "\"Get Wikipedia article info and Wikidata via MediaWiki APIs.\\n\\n\"", "\"Gets a random English Wikipedia article by default, or in the\\n\"", "\"language -lang, or from the wikisite -wiki, or by specific\\n\"", "\"title -title. Th...
parse main() args
[ "parse", "main", "()", "args" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/scripts/wptool.py#L180-L210
siznax/wptools
scripts/wptool.py
main
def main(args): """ invoke wptools and exit safely """ start = time.time() output = get(args) _safe_exit(start, output)
python
def main(args): """ invoke wptools and exit safely """ start = time.time() output = get(args) _safe_exit(start, output)
[ "def", "main", "(", "args", ")", ":", "start", "=", "time", ".", "time", "(", ")", "output", "=", "get", "(", "args", ")", "_safe_exit", "(", "start", ",", "output", ")" ]
invoke wptools and exit safely
[ "invoke", "wptools", "and", "exit", "safely" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/scripts/wptool.py#L213-L219
siznax/wptools
wptools/page.py
WPToolsPage.__insert_image_info
def __insert_image_info(self, title, _from, info): """ Insert API image INFO into matching image dict We make one imageinfo request containing only unique image filenames. We reduce duplication by asking for image data per file, instead of per "kind" or source (Wikipedia, Wikida...
python
def __insert_image_info(self, title, _from, info): """ Insert API image INFO into matching image dict We make one imageinfo request containing only unique image filenames. We reduce duplication by asking for image data per file, instead of per "kind" or source (Wikipedia, Wikida...
[ "def", "__insert_image_info", "(", "self", ",", "title", ",", "_from", ",", "info", ")", ":", "for", "img", "in", "self", ".", "data", "[", "'image'", "]", ":", "if", "'url'", "not", "in", "img", ":", "if", "title", "==", "img", "[", "'file'", "]",...
Insert API image INFO into matching image dict We make one imageinfo request containing only unique image filenames. We reduce duplication by asking for image data per file, instead of per "kind" or source (Wikipedia, Wikidata, etc.), because some sources reference the same image file. ...
[ "Insert", "API", "image", "INFO", "into", "matching", "image", "dict" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L84-L102
siznax/wptools
wptools/page.py
WPToolsPage.__pull_image_info
def __pull_image_info(self, title, imageinfo, normalized): """ Pull image INFO from API response and insert """ for info in imageinfo: info.update({'title': title}) # get API normalized "from" filename for matching _from = None for norm in...
python
def __pull_image_info(self, title, imageinfo, normalized): """ Pull image INFO from API response and insert """ for info in imageinfo: info.update({'title': title}) # get API normalized "from" filename for matching _from = None for norm in...
[ "def", "__pull_image_info", "(", "self", ",", "title", ",", "imageinfo", ",", "normalized", ")", ":", "for", "info", "in", "imageinfo", ":", "info", ".", "update", "(", "{", "'title'", ":", "title", "}", ")", "# get API normalized \"from\" filename for matching"...
Pull image INFO from API response and insert
[ "Pull", "image", "INFO", "from", "API", "response", "and", "insert" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L104-L124
siznax/wptools
wptools/page.py
WPToolsPage._extend_data
def _extend_data(self, datapoint, new_data): """ extend or assign new data to datapoint """ if new_data: try: self.data[datapoint].extend(new_data) except KeyError: self.data[datapoint] = new_data
python
def _extend_data(self, datapoint, new_data): """ extend or assign new data to datapoint """ if new_data: try: self.data[datapoint].extend(new_data) except KeyError: self.data[datapoint] = new_data
[ "def", "_extend_data", "(", "self", ",", "datapoint", ",", "new_data", ")", ":", "if", "new_data", ":", "try", ":", "self", ".", "data", "[", "datapoint", "]", ".", "extend", "(", "new_data", ")", "except", "KeyError", ":", "self", ".", "data", "[", ...
extend or assign new data to datapoint
[ "extend", "or", "assign", "new", "data", "to", "datapoint" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L126-L134
siznax/wptools
wptools/page.py
WPToolsPage._missing_imageinfo
def _missing_imageinfo(self): """ returns list of image filenames that are missing info """ if 'image' not in self.data: return missing = [] for img in self.data['image']: if 'url' not in img: missing.append(img['file']) ret...
python
def _missing_imageinfo(self): """ returns list of image filenames that are missing info """ if 'image' not in self.data: return missing = [] for img in self.data['image']: if 'url' not in img: missing.append(img['file']) ret...
[ "def", "_missing_imageinfo", "(", "self", ")", ":", "if", "'image'", "not", "in", "self", ".", "data", ":", "return", "missing", "=", "[", "]", "for", "img", "in", "self", ".", "data", "[", "'image'", "]", ":", "if", "'url'", "not", "in", "img", ":...
returns list of image filenames that are missing info
[ "returns", "list", "of", "image", "filenames", "that", "are", "missing", "info" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L136-L146
siznax/wptools
wptools/page.py
WPToolsPage._normalize_images
def _normalize_images(self): """ normalizes image filenames by prepending 'File:' if needed """ if 'image' not in self.data: return for img in self.data['image']: fname = img['file'].replace('_', ' ') fstart = fname.startswith('File:') ...
python
def _normalize_images(self): """ normalizes image filenames by prepending 'File:' if needed """ if 'image' not in self.data: return for img in self.data['image']: fname = img['file'].replace('_', ' ') fstart = fname.startswith('File:') ...
[ "def", "_normalize_images", "(", "self", ")", ":", "if", "'image'", "not", "in", "self", ".", "data", ":", "return", "for", "img", "in", "self", ".", "data", "[", "'image'", "]", ":", "fname", "=", "img", "[", "'file'", "]", ".", "replace", "(", "'...
normalizes image filenames by prepending 'File:' if needed
[ "normalizes", "image", "filenames", "by", "prepending", "File", ":", "if", "needed" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L148-L161
siznax/wptools
wptools/page.py
WPToolsPage._query
def _query(self, action, qobj): """ returns WPToolsQuery string """ title = self.params.get('title') pageid = self.params.get('pageid') wikibase = self.params.get('wikibase') qstr = None if action == 'random': qstr = qobj.random() eli...
python
def _query(self, action, qobj): """ returns WPToolsQuery string """ title = self.params.get('title') pageid = self.params.get('pageid') wikibase = self.params.get('wikibase') qstr = None if action == 'random': qstr = qobj.random() eli...
[ "def", "_query", "(", "self", ",", "action", ",", "qobj", ")", ":", "title", "=", "self", ".", "params", ".", "get", "(", "'title'", ")", "pageid", "=", "self", ".", "params", ".", "get", "(", "'pageid'", ")", "wikibase", "=", "self", ".", "params"...
returns WPToolsQuery string
[ "returns", "WPToolsQuery", "string" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L163-L193
siznax/wptools
wptools/page.py
WPToolsPage._set_data
def _set_data(self, action): """ marshals response data into page data """ if 'query' in action: self._set_query_data(action) elif action == 'imageinfo': self._set_imageinfo_data() elif action == 'parse': self._set_parse_data() ...
python
def _set_data(self, action): """ marshals response data into page data """ if 'query' in action: self._set_query_data(action) elif action == 'imageinfo': self._set_imageinfo_data() elif action == 'parse': self._set_parse_data() ...
[ "def", "_set_data", "(", "self", ",", "action", ")", ":", "if", "'query'", "in", "action", ":", "self", ".", "_set_query_data", "(", "action", ")", "elif", "action", "==", "'imageinfo'", ":", "self", ".", "_set_imageinfo_data", "(", ")", "elif", "action", ...
marshals response data into page data
[ "marshals", "response", "data", "into", "page", "data" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L195-L216
siznax/wptools
wptools/page.py
WPToolsPage._set_imageinfo_data
def _set_imageinfo_data(self): """ set image attributes from MediaWiki API:Imageinfo response """ data = self._load_response('imageinfo') pages = data['query'].get('pages') normalized = [] if 'normalized' in data['query']: normalized = data['query']['...
python
def _set_imageinfo_data(self): """ set image attributes from MediaWiki API:Imageinfo response """ data = self._load_response('imageinfo') pages = data['query'].get('pages') normalized = [] if 'normalized' in data['query']: normalized = data['query']['...
[ "def", "_set_imageinfo_data", "(", "self", ")", ":", "data", "=", "self", ".", "_load_response", "(", "'imageinfo'", ")", "pages", "=", "data", "[", "'query'", "]", ".", "get", "(", "'pages'", ")", "normalized", "=", "[", "]", "if", "'normalized'", "in",...
set image attributes from MediaWiki API:Imageinfo response
[ "set", "image", "attributes", "from", "MediaWiki", "API", ":", "Imageinfo", "response" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L218-L238
siznax/wptools
wptools/page.py
WPToolsPage._set_parse_data
def _set_parse_data(self): """ set attributes derived from MediaWiki (action=parse) """ pdata = self._load_response('parse')['parse'] self.data['iwlinks'] = utils.get_links(pdata.get('iwlinks')) self.data['pageid'] = pdata.get('pageid') self.data['wikitext'] = pd...
python
def _set_parse_data(self): """ set attributes derived from MediaWiki (action=parse) """ pdata = self._load_response('parse')['parse'] self.data['iwlinks'] = utils.get_links(pdata.get('iwlinks')) self.data['pageid'] = pdata.get('pageid') self.data['wikitext'] = pd...
[ "def", "_set_parse_data", "(", "self", ")", ":", "pdata", "=", "self", ".", "_load_response", "(", "'parse'", ")", "[", "'parse'", "]", "self", ".", "data", "[", "'iwlinks'", "]", "=", "utils", ".", "get_links", "(", "pdata", ".", "get", "(", "'iwlinks...
set attributes derived from MediaWiki (action=parse)
[ "set", "attributes", "derived", "from", "MediaWiki", "(", "action", "=", "parse", ")" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L240-L272
siznax/wptools
wptools/page.py
WPToolsPage._set_parse_image
def _set_parse_image(self, infobox): """ set image data from action=parse response """ image = infobox.get('image') cover = infobox.get('Cover') or infobox.get('cover') if image or cover: if 'image' not in self.data: self.data['image'] = [] ...
python
def _set_parse_image(self, infobox): """ set image data from action=parse response """ image = infobox.get('image') cover = infobox.get('Cover') or infobox.get('cover') if image or cover: if 'image' not in self.data: self.data['image'] = [] ...
[ "def", "_set_parse_image", "(", "self", ",", "infobox", ")", ":", "image", "=", "infobox", ".", "get", "(", "'image'", ")", "cover", "=", "infobox", ".", "get", "(", "'Cover'", ")", "or", "infobox", ".", "get", "(", "'cover'", ")", "if", "image", "or...
set image data from action=parse response
[ "set", "image", "data", "from", "action", "=", "parse", "response" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L274-L289
siznax/wptools
wptools/page.py
WPToolsPage._set_query_data
def _set_query_data(self, action='query'): """ set attributes derived from MediaWiki (action=query) """ data = self._load_response(action) page = data['query']['pages'][0] self._handle_continuations(data, action) if action == 'query': self.data['rand...
python
def _set_query_data(self, action='query'): """ set attributes derived from MediaWiki (action=query) """ data = self._load_response(action) page = data['query']['pages'][0] self._handle_continuations(data, action) if action == 'query': self.data['rand...
[ "def", "_set_query_data", "(", "self", ",", "action", "=", "'query'", ")", ":", "data", "=", "self", ".", "_load_response", "(", "action", ")", "page", "=", "data", "[", "'query'", "]", "[", "'pages'", "]", "[", "0", "]", "self", ".", "_handle_continua...
set attributes derived from MediaWiki (action=query)
[ "set", "attributes", "derived", "from", "MediaWiki", "(", "action", "=", "query", ")" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L291-L309
siznax/wptools
wptools/page.py
WPToolsPage._set_query_data_fast_1
def _set_query_data_fast_1(self, page): """ set less expensive action=query response data PART 1 """ self.data['pageid'] = page.get('pageid') assessments = page.get('pageassessments') if assessments: self.data['assessments'] = assessments extract = p...
python
def _set_query_data_fast_1(self, page): """ set less expensive action=query response data PART 1 """ self.data['pageid'] = page.get('pageid') assessments = page.get('pageassessments') if assessments: self.data['assessments'] = assessments extract = p...
[ "def", "_set_query_data_fast_1", "(", "self", ",", "page", ")", ":", "self", ".", "data", "[", "'pageid'", "]", "=", "page", ".", "get", "(", "'pageid'", ")", "assessments", "=", "page", ".", "get", "(", "'pageassessments'", ")", "if", "assessments", ":"...
set less expensive action=query response data PART 1
[ "set", "less", "expensive", "action", "=", "query", "response", "data", "PART", "1" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L311-L349
siznax/wptools
wptools/page.py
WPToolsPage._set_query_data_fast_2
def _set_query_data_fast_2(self, page): """ set less expensive action=query response data PART 2 """ self.data['pageid'] = page.get('pageid') redirects = page.get('redirects') if redirects: self.data['redirects'] = redirects terms = page.get('terms')...
python
def _set_query_data_fast_2(self, page): """ set less expensive action=query response data PART 2 """ self.data['pageid'] = page.get('pageid') redirects = page.get('redirects') if redirects: self.data['redirects'] = redirects terms = page.get('terms')...
[ "def", "_set_query_data_fast_2", "(", "self", ",", "page", ")", ":", "self", ".", "data", "[", "'pageid'", "]", "=", "page", ".", "get", "(", "'pageid'", ")", "redirects", "=", "page", ".", "get", "(", "'redirects'", ")", "if", "redirects", ":", "self"...
set less expensive action=query response data PART 2
[ "set", "less", "expensive", "action", "=", "query", "response", "data", "PART", "2" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L351-L381
siznax/wptools
wptools/page.py
WPToolsPage._set_query_data_slow
def _set_query_data_slow(self, page): """ set more expensive action=query response data """ categories = page.get('categories') if categories: self.data['categories'] = [x['title'] for x in categories] if page.get('contributors'): contributors = p...
python
def _set_query_data_slow(self, page): """ set more expensive action=query response data """ categories = page.get('categories') if categories: self.data['categories'] = [x['title'] for x in categories] if page.get('contributors'): contributors = p...
[ "def", "_set_query_data_slow", "(", "self", ",", "page", ")", ":", "categories", "=", "page", ".", "get", "(", "'categories'", ")", "if", "categories", ":", "self", ".", "data", "[", "'categories'", "]", "=", "[", "x", "[", "'title'", "]", "for", "x", ...
set more expensive action=query response data
[ "set", "more", "expensive", "action", "=", "query", "response", "data" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L383-L412
siznax/wptools
wptools/page.py
WPToolsPage._set_query_image
def _set_query_image(self, page): """ set image data from action=query response """ pageimage = page.get('pageimage') thumbnail = page.get('thumbnail') if pageimage or thumbnail: if 'image' not in self.data: self.data['image'] = [] if...
python
def _set_query_image(self, page): """ set image data from action=query response """ pageimage = page.get('pageimage') thumbnail = page.get('thumbnail') if pageimage or thumbnail: if 'image' not in self.data: self.data['image'] = [] if...
[ "def", "_set_query_image", "(", "self", ",", "page", ")", ":", "pageimage", "=", "page", ".", "get", "(", "'pageimage'", ")", "thumbnail", "=", "page", ".", "get", "(", "'thumbnail'", ")", "if", "pageimage", "or", "thumbnail", ":", "if", "'image'", "not"...
set image data from action=query response
[ "set", "image", "data", "from", "action", "=", "query", "response" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L414-L436
siznax/wptools
wptools/page.py
WPToolsPage._set_random_data
def _set_random_data(self): """ sets page data from random request """ rdata = self._load_response('random') rdata = rdata['query']['random'][0] pageid = rdata.get('id') title = rdata.get('title') self.data.update({'pageid': pageid, ...
python
def _set_random_data(self): """ sets page data from random request """ rdata = self._load_response('random') rdata = rdata['query']['random'][0] pageid = rdata.get('id') title = rdata.get('title') self.data.update({'pageid': pageid, ...
[ "def", "_set_random_data", "(", "self", ")", ":", "rdata", "=", "self", ".", "_load_response", "(", "'random'", ")", "rdata", "=", "rdata", "[", "'query'", "]", "[", "'random'", "]", "[", "0", "]", "pageid", "=", "rdata", ".", "get", "(", "'id'", ")"...
sets page data from random request
[ "sets", "page", "data", "from", "random", "request" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L438-L449
siznax/wptools
wptools/page.py
WPToolsPage._update_data
def _update_data(self, datapoint, key, new_data): """ update or assign new data to datapoint """ if new_data: try: self.data[datapoint].update({key: new_data}) except KeyError: self.data[datapoint] = {key: new_data}
python
def _update_data(self, datapoint, key, new_data): """ update or assign new data to datapoint """ if new_data: try: self.data[datapoint].update({key: new_data}) except KeyError: self.data[datapoint] = {key: new_data}
[ "def", "_update_data", "(", "self", ",", "datapoint", ",", "key", ",", "new_data", ")", ":", "if", "new_data", ":", "try", ":", "self", ".", "data", "[", "datapoint", "]", ".", "update", "(", "{", "key", ":", "new_data", "}", ")", "except", "KeyError...
update or assign new data to datapoint
[ "update", "or", "assign", "new", "data", "to", "datapoint" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L451-L459
siznax/wptools
wptools/page.py
WPToolsPage._update_imageinfo
def _update_imageinfo(self): """ calls get_imageinfo() if data image missing info """ missing = self._missing_imageinfo() deferred = self.flags.get('defer_imageinfo') continuing = self.data.get('continue') if missing and not deferred and not continuing: ...
python
def _update_imageinfo(self): """ calls get_imageinfo() if data image missing info """ missing = self._missing_imageinfo() deferred = self.flags.get('defer_imageinfo') continuing = self.data.get('continue') if missing and not deferred and not continuing: ...
[ "def", "_update_imageinfo", "(", "self", ")", ":", "missing", "=", "self", ".", "_missing_imageinfo", "(", ")", "deferred", "=", "self", ".", "flags", ".", "get", "(", "'defer_imageinfo'", ")", "continuing", "=", "self", ".", "data", ".", "get", "(", "'c...
calls get_imageinfo() if data image missing info
[ "calls", "get_imageinfo", "()", "if", "data", "image", "missing", "info" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L461-L470
siznax/wptools
wptools/page.py
WPToolsPage._update_params
def _update_params(self): """ update params from response data """ if self.data.get('title'): self.params['title'] = self.data.get('title') if self.data.get('pageid'): self.params['pageid'] = self.data.get('pageid') if self.data.get('wikibase'): ...
python
def _update_params(self): """ update params from response data """ if self.data.get('title'): self.params['title'] = self.data.get('title') if self.data.get('pageid'): self.params['pageid'] = self.data.get('pageid') if self.data.get('wikibase'): ...
[ "def", "_update_params", "(", "self", ")", ":", "if", "self", ".", "data", ".", "get", "(", "'title'", ")", ":", "self", ".", "params", "[", "'title'", "]", "=", "self", ".", "data", ".", "get", "(", "'title'", ")", "if", "self", ".", "data", "."...
update params from response data
[ "update", "params", "from", "response", "data" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L472-L481
siznax/wptools
wptools/page.py
WPToolsPage.skip_action
def skip_action(self, action): """ append action to skip flag """ if 'skip' not in self.flags: self.flags['skip'] = [] self.flags['skip'].append(action)
python
def skip_action(self, action): """ append action to skip flag """ if 'skip' not in self.flags: self.flags['skip'] = [] self.flags['skip'].append(action)
[ "def", "skip_action", "(", "self", ",", "action", ")", ":", "if", "'skip'", "not", "in", "self", ".", "flags", ":", "self", ".", "flags", "[", "'skip'", "]", "=", "[", "]", "self", ".", "flags", "[", "'skip'", "]", ".", "append", "(", "action", "...
append action to skip flag
[ "append", "action", "to", "skip", "flag" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L483-L489
siznax/wptools
wptools/page.py
WPToolsPage.get
def get(self, show=True, proxy=None, timeout=0): """ Make Mediawiki, RESTBase, and Wikidata requests for page data some sequence of: - get_parse() - get_query() - get_restbase() - get_wikidata() """ wikibase = self.params.get('wikibase') i...
python
def get(self, show=True, proxy=None, timeout=0): """ Make Mediawiki, RESTBase, and Wikidata requests for page data some sequence of: - get_parse() - get_query() - get_restbase() - get_wikidata() """ wikibase = self.params.get('wikibase') i...
[ "def", "get", "(", "self", ",", "show", "=", "True", ",", "proxy", "=", "None", ",", "timeout", "=", "0", ")", ":", "wikibase", "=", "self", ".", "params", ".", "get", "(", "'wikibase'", ")", "if", "wikibase", ":", "self", ".", "flags", "[", "'de...
Make Mediawiki, RESTBase, and Wikidata requests for page data some sequence of: - get_parse() - get_query() - get_restbase() - get_wikidata()
[ "Make", "Mediawiki", "RESTBase", "and", "Wikidata", "requests", "for", "page", "data", "some", "sequence", "of", ":", "-", "get_parse", "()", "-", "get_query", "()", "-", "get_restbase", "()", "-", "get_wikidata", "()" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L491-L540
siznax/wptools
wptools/page.py
WPToolsPage.get_imageinfo
def get_imageinfo(self, show=True, proxy=None, timeout=0): """ GET MediaWiki request for API:Imageinfo https://www.mediawiki.org/wiki/API:Imageinfo Required {data}: - image: <list> member (<dict>) with 'file' and not 'url' Optional arguments: - [show]: <bool> ec...
python
def get_imageinfo(self, show=True, proxy=None, timeout=0): """ GET MediaWiki request for API:Imageinfo https://www.mediawiki.org/wiki/API:Imageinfo Required {data}: - image: <list> member (<dict>) with 'file' and not 'url' Optional arguments: - [show]: <bool> ec...
[ "def", "get_imageinfo", "(", "self", ",", "show", "=", "True", ",", "proxy", "=", "None", ",", "timeout", "=", "0", ")", ":", "if", "not", "self", ".", "data", ".", "get", "(", "'image'", ")", ":", "raise", "ValueError", "(", "\"get_imageinfo needs a p...
GET MediaWiki request for API:Imageinfo https://www.mediawiki.org/wiki/API:Imageinfo Required {data}: - image: <list> member (<dict>) with 'file' and not 'url' Optional arguments: - [show]: <bool> echo page data if true - [proxy]: <str> use this HTTP proxy - [ti...
[ "GET", "MediaWiki", "request", "for", "API", ":", "Imageinfo", "https", ":", "//", "www", ".", "mediawiki", ".", "org", "/", "wiki", "/", "API", ":", "Imageinfo" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L542-L568
siznax/wptools
wptools/page.py
WPToolsPage.get_more
def get_more(self, show=True, proxy=None, timeout=0): """ Calls get_querymore() Is for convenience. You like. """ return self.get_querymore(show, proxy, timeout)
python
def get_more(self, show=True, proxy=None, timeout=0): """ Calls get_querymore() Is for convenience. You like. """ return self.get_querymore(show, proxy, timeout)
[ "def", "get_more", "(", "self", ",", "show", "=", "True", ",", "proxy", "=", "None", ",", "timeout", "=", "0", ")", ":", "return", "self", ".", "get_querymore", "(", "show", ",", "proxy", ",", "timeout", ")" ]
Calls get_querymore() Is for convenience. You like.
[ "Calls", "get_querymore", "()", "Is", "for", "convenience", ".", "You", "like", "." ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L570-L574
siznax/wptools
wptools/page.py
WPToolsPage.get_parse
def get_parse(self, show=True, proxy=None, timeout=0): """ GET MediaWiki:API action=parse request https://en.wikipedia.org/w/api.php?action=help&modules=parse Required {params}: title OR pageid - title: <str> article title - pageid: <int> Wikipedia database ID O...
python
def get_parse(self, show=True, proxy=None, timeout=0): """ GET MediaWiki:API action=parse request https://en.wikipedia.org/w/api.php?action=help&modules=parse Required {params}: title OR pageid - title: <str> article title - pageid: <int> Wikipedia database ID O...
[ "def", "get_parse", "(", "self", ",", "show", "=", "True", ",", "proxy", "=", "None", ",", "timeout", "=", "0", ")", ":", "if", "not", "self", ".", "params", ".", "get", "(", "'title'", ")", "and", "not", "self", ".", "params", ".", "get", "(", ...
GET MediaWiki:API action=parse request https://en.wikipedia.org/w/api.php?action=help&modules=parse Required {params}: title OR pageid - title: <str> article title - pageid: <int> Wikipedia database ID Optional arguments: - [show]: <bool> echo page data if true ...
[ "GET", "MediaWiki", ":", "API", "action", "=", "parse", "request", "https", ":", "//", "en", ".", "wikipedia", ".", "org", "/", "w", "/", "api", ".", "php?action", "=", "help&modules", "=", "parse" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L576-L605
siznax/wptools
wptools/page.py
WPToolsPage.get_query
def get_query(self, show=True, proxy=None, timeout=0): """ GET MediaWiki:API action=query selected data https://en.wikipedia.org/w/api.php?action=help&modules=query Required {params}: title OR pageid - title: <str> article title - pageid: <int> Wikipedia database ID ...
python
def get_query(self, show=True, proxy=None, timeout=0): """ GET MediaWiki:API action=query selected data https://en.wikipedia.org/w/api.php?action=help&modules=query Required {params}: title OR pageid - title: <str> article title - pageid: <int> Wikipedia database ID ...
[ "def", "get_query", "(", "self", ",", "show", "=", "True", ",", "proxy", "=", "None", ",", "timeout", "=", "0", ")", ":", "if", "not", "self", ".", "params", ".", "get", "(", "'title'", ")", "and", "not", "self", ".", "params", ".", "get", "(", ...
GET MediaWiki:API action=query selected data https://en.wikipedia.org/w/api.php?action=help&modules=query Required {params}: title OR pageid - title: <str> article title - pageid: <int> Wikipedia database ID Optional arguments: - [show]: <bool> echo page data if true ...
[ "GET", "MediaWiki", ":", "API", "action", "=", "query", "selected", "data", "https", ":", "//", "en", ".", "wikipedia", ".", "org", "/", "w", "/", "api", ".", "php?action", "=", "help&modules", "=", "query" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L607-L643
siznax/wptools
wptools/page.py
WPToolsPage.images
def images(self, fields=None, token=None): """ Returns image info keys for kind containing token Args: - fields: <list> image info values wanted - token: <str> substring to match image kind EXAMPLES Get all available image info: >>> page.images() ...
python
def images(self, fields=None, token=None): """ Returns image info keys for kind containing token Args: - fields: <list> image info values wanted - token: <str> substring to match image kind EXAMPLES Get all available image info: >>> page.images() ...
[ "def", "images", "(", "self", ",", "fields", "=", "None", ",", "token", "=", "None", ")", ":", "if", "'image'", "not", "in", "self", ".", "data", ":", "return", "out", "=", "[", "]", "for", "img", "in", "self", ".", "data", "[", "'image'", "]", ...
Returns image info keys for kind containing token Args: - fields: <list> image info values wanted - token: <str> substring to match image kind EXAMPLES Get all available image info: >>> page.images() Get all image kinds: >>> page.images('kind') ...
[ "Returns", "image", "info", "keys", "for", "kind", "containing", "token" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L700-L738
siznax/wptools
wptools/request.py
curl_info
def curl_info(crl): """ returns curl (response) info from Pycurl object """ kbps = crl.getinfo(crl.SPEED_DOWNLOAD) / 1000.0 url = crl.getinfo(crl.EFFECTIVE_URL) url = url.replace("&format=json", '').replace("&formatversion=2", '') # https://travis-ci.org/siznax/wptools/jobs/401109410 tr...
python
def curl_info(crl): """ returns curl (response) info from Pycurl object """ kbps = crl.getinfo(crl.SPEED_DOWNLOAD) / 1000.0 url = crl.getinfo(crl.EFFECTIVE_URL) url = url.replace("&format=json", '').replace("&formatversion=2", '') # https://travis-ci.org/siznax/wptools/jobs/401109410 tr...
[ "def", "curl_info", "(", "crl", ")", ":", "kbps", "=", "crl", ".", "getinfo", "(", "crl", ".", "SPEED_DOWNLOAD", ")", "/", "1000.0", "url", "=", "crl", ".", "getinfo", "(", "crl", ".", "EFFECTIVE_URL", ")", "url", "=", "url", ".", "replace", "(", "...
returns curl (response) info from Pycurl object
[ "returns", "curl", "(", "response", ")", "info", "from", "Pycurl", "object" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/request.py#L134-L154
siznax/wptools
wptools/request.py
WPToolsRequest.get
def get(self, url, status): """ in favor of python-requests for speed """ # consistently faster than requests by 3x # # r = requests.get(url, # headers={'User-Agent': self.user_agent}) # return r.text crl = self.cobj try...
python
def get(self, url, status): """ in favor of python-requests for speed """ # consistently faster than requests by 3x # # r = requests.get(url, # headers={'User-Agent': self.user_agent}) # return r.text crl = self.cobj try...
[ "def", "get", "(", "self", ",", "url", ",", "status", ")", ":", "# consistently faster than requests by 3x", "#", "# r = requests.get(url,", "# headers={'User-Agent': self.user_agent})", "# return r.text", "crl", "=", "self", ".", "cobj", "try", ":", "crl...
in favor of python-requests for speed
[ "in", "favor", "of", "python", "-", "requests", "for", "speed" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/request.py#L52-L76
siznax/wptools
wptools/request.py
WPToolsRequest.curl_perform
def curl_perform(self, crl): """ performs HTTP GET and returns body of response """ bfr = BytesIO() crl.setopt(crl.WRITEFUNCTION, bfr.write) crl.perform() info = curl_info(crl) if info: if self.verbose and not self.silent: for i...
python
def curl_perform(self, crl): """ performs HTTP GET and returns body of response """ bfr = BytesIO() crl.setopt(crl.WRITEFUNCTION, bfr.write) crl.perform() info = curl_info(crl) if info: if self.verbose and not self.silent: for i...
[ "def", "curl_perform", "(", "self", ",", "crl", ")", ":", "bfr", "=", "BytesIO", "(", ")", "crl", ".", "setopt", "(", "crl", ".", "WRITEFUNCTION", ",", "bfr", ".", "write", ")", "crl", ".", "perform", "(", ")", "info", "=", "curl_info", "(", "crl",...
performs HTTP GET and returns body of response
[ "performs", "HTTP", "GET", "and", "returns", "body", "of", "response" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/request.py#L78-L93
siznax/wptools
wptools/request.py
WPToolsRequest.curl_setup
def curl_setup(self, proxy=None, timeout=0): """ Set curl options - http://pycurl.io/docs/latest/ - https://curl.haxx.se/libcurl/c/curl_easy_setopt.html Proxy options (str or dict): proxy = 'https://example.com:80' # pycurl.PROXY proxy = { 'PROXY...
python
def curl_setup(self, proxy=None, timeout=0): """ Set curl options - http://pycurl.io/docs/latest/ - https://curl.haxx.se/libcurl/c/curl_easy_setopt.html Proxy options (str or dict): proxy = 'https://example.com:80' # pycurl.PROXY proxy = { 'PROXY...
[ "def", "curl_setup", "(", "self", ",", "proxy", "=", "None", ",", "timeout", "=", "0", ")", ":", "crl", "=", "pycurl", ".", "Curl", "(", ")", "crl", ".", "setopt", "(", "pycurl", ".", "USERAGENT", ",", "user_agent", "(", ")", ")", "crl", ".", "se...
Set curl options - http://pycurl.io/docs/latest/ - https://curl.haxx.se/libcurl/c/curl_easy_setopt.html Proxy options (str or dict): proxy = 'https://example.com:80' # pycurl.PROXY proxy = { 'PROXY': <str> host, # pycurl.PROXY 'PORT': <int>...
[ "Set", "curl", "options", "-", "http", ":", "//", "pycurl", ".", "io", "/", "docs", "/", "latest", "/", "-", "https", ":", "//", "curl", ".", "haxx", ".", "se", "/", "libcurl", "/", "c", "/", "curl_easy_setopt", ".", "html" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/request.py#L95-L131
siznax/wptools
wptools/query.py
safequote_restbase
def safequote_restbase(title): """ Safequote restbase title possibly having slash in title """ try: return quote(title.encode('utf-8'), safe='') except UnicodeDecodeError: return quote(title, safe='')
python
def safequote_restbase(title): """ Safequote restbase title possibly having slash in title """ try: return quote(title.encode('utf-8'), safe='') except UnicodeDecodeError: return quote(title, safe='')
[ "def", "safequote_restbase", "(", "title", ")", ":", "try", ":", "return", "quote", "(", "title", ".", "encode", "(", "'utf-8'", ")", ",", "safe", "=", "''", ")", "except", "UnicodeDecodeError", ":", "return", "quote", "(", "title", ",", "safe", "=", "...
Safequote restbase title possibly having slash in title
[ "Safequote", "restbase", "title", "possibly", "having", "slash", "in", "title" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L416-L423
siznax/wptools
wptools/query.py
WPToolsQuery.category
def category(self, title, pageid=None, cparams=None, namespace=None): """ Returns category query string """ query = self.LIST.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, LIST='categorymembers') status = pageid or title query += ...
python
def category(self, title, pageid=None, cparams=None, namespace=None): """ Returns category query string """ query = self.LIST.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, LIST='categorymembers') status = pageid or title query += ...
[ "def", "category", "(", "self", ",", "title", ",", "pageid", "=", "None", ",", "cparams", "=", "None", ",", "namespace", "=", "None", ")", ":", "query", "=", "self", ".", "LIST", ".", "substitute", "(", "WIKI", "=", "self", ".", "uri", ",", "ENDPOI...
Returns category query string
[ "Returns", "category", "query", "string" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L129-L159
siznax/wptools
wptools/query.py
WPToolsQuery.labels
def labels(self, qids): """ Returns Wikidata labels query string """ if len(qids) > 50: raise ValueError("The limit is 50.") self.domain = 'www.wikidata.org' self.uri = self.wiki_uri(self.domain) query = self.WIKIDATA.substitute( WIKI=sel...
python
def labels(self, qids): """ Returns Wikidata labels query string """ if len(qids) > 50: raise ValueError("The limit is 50.") self.domain = 'www.wikidata.org' self.uri = self.wiki_uri(self.domain) query = self.WIKIDATA.substitute( WIKI=sel...
[ "def", "labels", "(", "self", ",", "qids", ")", ":", "if", "len", "(", "qids", ")", ">", "50", ":", "raise", "ValueError", "(", "\"The limit is 50.\"", ")", "self", ".", "domain", "=", "'www.wikidata.org'", "self", ".", "uri", "=", "self", ".", "wiki_u...
Returns Wikidata labels query string
[ "Returns", "Wikidata", "labels", "query", "string" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L161-L182
siznax/wptools
wptools/query.py
WPToolsQuery.imageinfo
def imageinfo(self, files): """ Returns imageinfo query string """ files = '|'.join([safequote(x) for x in files]) self.set_status('imageinfo', files) return self.IMAGEINFO.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, FILES=file...
python
def imageinfo(self, files): """ Returns imageinfo query string """ files = '|'.join([safequote(x) for x in files]) self.set_status('imageinfo', files) return self.IMAGEINFO.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, FILES=file...
[ "def", "imageinfo", "(", "self", ",", "files", ")", ":", "files", "=", "'|'", ".", "join", "(", "[", "safequote", "(", "x", ")", "for", "x", "in", "files", "]", ")", "self", ".", "set_status", "(", "'imageinfo'", ",", "files", ")", "return", "self"...
Returns imageinfo query string
[ "Returns", "imageinfo", "query", "string" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L184-L195
siznax/wptools
wptools/query.py
WPToolsQuery.parse
def parse(self, title, pageid=None): """ Returns Mediawiki action=parse query string """ qry = self.PARSE.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, PAGE=safequote(title) or pageid) if pageid and not title: qry = qry.replac...
python
def parse(self, title, pageid=None): """ Returns Mediawiki action=parse query string """ qry = self.PARSE.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, PAGE=safequote(title) or pageid) if pageid and not title: qry = qry.replac...
[ "def", "parse", "(", "self", ",", "title", ",", "pageid", "=", "None", ")", ":", "qry", "=", "self", ".", "PARSE", ".", "substitute", "(", "WIKI", "=", "self", ".", "uri", ",", "ENDPOINT", "=", "self", ".", "endpoint", ",", "PAGE", "=", "safequote"...
Returns Mediawiki action=parse query string
[ "Returns", "Mediawiki", "action", "=", "parse", "query", "string" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L197-L214
siznax/wptools
wptools/query.py
WPToolsQuery.query
def query(self, titles, pageids=None, cparams=None): """ Returns MediaWiki action=query query string """ query = self.QUERY.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, TITLES=safequote(titles) or pageids) status = titles or pageids ...
python
def query(self, titles, pageids=None, cparams=None): """ Returns MediaWiki action=query query string """ query = self.QUERY.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, TITLES=safequote(titles) or pageids) status = titles or pageids ...
[ "def", "query", "(", "self", ",", "titles", ",", "pageids", "=", "None", ",", "cparams", "=", "None", ")", ":", "query", "=", "self", ".", "QUERY", ".", "substitute", "(", "WIKI", "=", "self", ".", "uri", ",", "ENDPOINT", "=", "self", ".", "endpoin...
Returns MediaWiki action=query query string
[ "Returns", "MediaWiki", "action", "=", "query", "query", "string" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L216-L238
siznax/wptools
wptools/query.py
WPToolsQuery.random
def random(self, namespace=0): """ Returns query string for random page """ query = self.LIST.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, LIST='random') query += "&rnlimit=1&rnnamespace=%d" % namespace emoji = [ u'\U...
python
def random(self, namespace=0): """ Returns query string for random page """ query = self.LIST.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, LIST='random') query += "&rnlimit=1&rnnamespace=%d" % namespace emoji = [ u'\U...
[ "def", "random", "(", "self", ",", "namespace", "=", "0", ")", ":", "query", "=", "self", ".", "LIST", ".", "substitute", "(", "WIKI", "=", "self", ".", "uri", ",", "ENDPOINT", "=", "self", ".", "endpoint", ",", "LIST", "=", "'random'", ")", "query...
Returns query string for random page
[ "Returns", "query", "string", "for", "random", "page" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L266-L293
siznax/wptools
wptools/query.py
WPToolsQuery.restbase
def restbase(self, endpoint, title): """ Returns RESTBase query string """ if not endpoint: raise ValueError("invalid endpoint: %s" % endpoint) route = endpoint if title and endpoint != '/page/': route = endpoint + safequote_restbase(title) ...
python
def restbase(self, endpoint, title): """ Returns RESTBase query string """ if not endpoint: raise ValueError("invalid endpoint: %s" % endpoint) route = endpoint if title and endpoint != '/page/': route = endpoint + safequote_restbase(title) ...
[ "def", "restbase", "(", "self", ",", "endpoint", ",", "title", ")", ":", "if", "not", "endpoint", ":", "raise", "ValueError", "(", "\"invalid endpoint: %s\"", "%", "endpoint", ")", "route", "=", "endpoint", "if", "title", "and", "endpoint", "!=", "'/page/'",...
Returns RESTBase query string
[ "Returns", "RESTBase", "query", "string" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L295-L308
siznax/wptools
wptools/query.py
WPToolsQuery.set_status
def set_status(self, action, target): """ Sets query status with format: "{domain} ({action}) {target}" """ try: target = unquote(target) except (AttributeError, TypeError): pass status = "%s (%s) %s" % (self.domain, action, target) status...
python
def set_status(self, action, target): """ Sets query status with format: "{domain} ({action}) {target}" """ try: target = unquote(target) except (AttributeError, TypeError): pass status = "%s (%s) %s" % (self.domain, action, target) status...
[ "def", "set_status", "(", "self", ",", "action", ",", "target", ")", ":", "try", ":", "target", "=", "unquote", "(", "target", ")", "except", "(", "AttributeError", ",", "TypeError", ")", ":", "pass", "status", "=", "\"%s (%s) %s\"", "%", "(", "self", ...
Sets query status with format: "{domain} ({action}) {target}"
[ "Sets", "query", "status", "with", "format", ":", "{", "domain", "}", "(", "{", "action", "}", ")", "{", "target", "}" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L310-L327
siznax/wptools
wptools/query.py
WPToolsQuery.site
def site(self, action): """ Returns site query """ query = None viewdays = 7 hostpath = self.uri + self.endpoint if action == 'siteinfo': query = hostpath + ( '?action=query' '&meta=siteinfo|siteviews' '...
python
def site(self, action): """ Returns site query """ query = None viewdays = 7 hostpath = self.uri + self.endpoint if action == 'siteinfo': query = hostpath + ( '?action=query' '&meta=siteinfo|siteviews' '...
[ "def", "site", "(", "self", ",", "action", ")", ":", "query", "=", "None", "viewdays", "=", "7", "hostpath", "=", "self", ".", "uri", "+", "self", ".", "endpoint", "if", "action", "==", "'siteinfo'", ":", "query", "=", "hostpath", "+", "(", "'?action...
Returns site query
[ "Returns", "site", "query" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L329-L360
siznax/wptools
wptools/query.py
WPToolsQuery.wikidata
def wikidata(self, title, wikibase=None): """ Returns Wikidata query string """ self.domain = 'www.wikidata.org' self.uri = self.wiki_uri(self.domain) query = self.WIKIDATA.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, LANG=self.v...
python
def wikidata(self, title, wikibase=None): """ Returns Wikidata query string """ self.domain = 'www.wikidata.org' self.uri = self.wiki_uri(self.domain) query = self.WIKIDATA.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, LANG=self.v...
[ "def", "wikidata", "(", "self", ",", "title", ",", "wikibase", "=", "None", ")", ":", "self", ".", "domain", "=", "'www.wikidata.org'", "self", ".", "uri", "=", "self", ".", "wiki_uri", "(", "self", ".", "domain", ")", "query", "=", "self", ".", "WIK...
Returns Wikidata query string
[ "Returns", "Wikidata", "query", "string" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L370-L392
siznax/wptools
wptools/restbase.py
WPToolsRESTBase._handle_response
def _handle_response(self): """ returns RESTBase response if appropriate """ content = self.cache['restbase']['info']['content-type'] if content.startswith('text/html'): html = self.cache['restbase']['response'] if isinstance(html, bytes): ...
python
def _handle_response(self): """ returns RESTBase response if appropriate """ content = self.cache['restbase']['info']['content-type'] if content.startswith('text/html'): html = self.cache['restbase']['response'] if isinstance(html, bytes): ...
[ "def", "_handle_response", "(", "self", ")", ":", "content", "=", "self", ".", "cache", "[", "'restbase'", "]", "[", "'info'", "]", "[", "'content-type'", "]", "if", "content", ".", "startswith", "(", "'text/html'", ")", ":", "html", "=", "self", ".", ...
returns RESTBase response if appropriate
[ "returns", "RESTBase", "response", "if", "appropriate" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/restbase.py#L41-L65
siznax/wptools
wptools/restbase.py
WPToolsRESTBase._query
def _query(self, action, qobj): """ returns WPToolsQuery string from action """ return qobj.restbase(self.params['rest_endpoint'], self.params.get('title'))
python
def _query(self, action, qobj): """ returns WPToolsQuery string from action """ return qobj.restbase(self.params['rest_endpoint'], self.params.get('title'))
[ "def", "_query", "(", "self", ",", "action", ",", "qobj", ")", ":", "return", "qobj", ".", "restbase", "(", "self", ".", "params", "[", "'rest_endpoint'", "]", ",", "self", ".", "params", ".", "get", "(", "'title'", ")", ")" ]
returns WPToolsQuery string from action
[ "returns", "WPToolsQuery", "string", "from", "action" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/restbase.py#L67-L72
siznax/wptools
wptools/restbase.py
WPToolsRESTBase._unpack_images
def _unpack_images(self, rdata): """ Set image data from RESTBase response """ image = rdata.get('image') # /page/mobile-sections-lead originalimage = rdata.get('originalimage') # /page/summary thumbnail = rdata.get('thumbnail') # /page/summary if image or ori...
python
def _unpack_images(self, rdata): """ Set image data from RESTBase response """ image = rdata.get('image') # /page/mobile-sections-lead originalimage = rdata.get('originalimage') # /page/summary thumbnail = rdata.get('thumbnail') # /page/summary if image or ori...
[ "def", "_unpack_images", "(", "self", ",", "rdata", ")", ":", "image", "=", "rdata", ".", "get", "(", "'image'", ")", "# /page/mobile-sections-lead", "originalimage", "=", "rdata", ".", "get", "(", "'originalimage'", ")", "# /page/summary", "thumbnail", "=", "...
Set image data from RESTBase response
[ "Set", "image", "data", "from", "RESTBase", "response" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/restbase.py#L120-L155
siznax/wptools
wptools/restbase.py
WPToolsRESTBase.get_restbase
def get_restbase(self, endpoint='/page/', show=True, proxy=None, timeout=0): """ GET RESTBase /page/ endpoints needing only {title} https://en.wikipedia.org/api/rest_v1/ for example: /page/ /page/html/{title} /page/summary/{title}...
python
def get_restbase(self, endpoint='/page/', show=True, proxy=None, timeout=0): """ GET RESTBase /page/ endpoints needing only {title} https://en.wikipedia.org/api/rest_v1/ for example: /page/ /page/html/{title} /page/summary/{title}...
[ "def", "get_restbase", "(", "self", ",", "endpoint", "=", "'/page/'", ",", "show", "=", "True", ",", "proxy", "=", "None", ",", "timeout", "=", "0", ")", ":", "if", "endpoint", "!=", "'/page/'", "and", "not", "self", ".", "params", ".", "get", "(", ...
GET RESTBase /page/ endpoints needing only {title} https://en.wikipedia.org/api/rest_v1/ for example: /page/ /page/html/{title} /page/summary/{title} /page/mobile-sections-lead/{title} Required {params}: None Without arguments, lists REST...
[ "GET", "RESTBase", "/", "page", "/", "endpoints", "needing", "only", "{", "title", "}", "https", ":", "//", "en", ".", "wikipedia", ".", "org", "/", "api", "/", "rest_v1", "/" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/restbase.py#L157-L202
siznax/wptools
wptools/utils.py
get_infobox
def get_infobox(ptree, boxterm="box"): """ Returns parse tree template with title containing <boxterm> as dict: <box> = {<name>: <value>, ...} If simple transform fails, attempts more general assembly: <box> = {'boxes': [{<title>: <parts>}, ...], 'count': <len(boxes)>} ...
python
def get_infobox(ptree, boxterm="box"): """ Returns parse tree template with title containing <boxterm> as dict: <box> = {<name>: <value>, ...} If simple transform fails, attempts more general assembly: <box> = {'boxes': [{<title>: <parts>}, ...], 'count': <len(boxes)>} ...
[ "def", "get_infobox", "(", "ptree", ",", "boxterm", "=", "\"box\"", ")", ":", "boxes", "=", "[", "]", "for", "item", "in", "lxml", ".", "etree", ".", "fromstring", "(", "ptree", ")", ".", "xpath", "(", "\"//template\"", ")", ":", "title", "=", "item"...
Returns parse tree template with title containing <boxterm> as dict: <box> = {<name>: <value>, ...} If simple transform fails, attempts more general assembly: <box> = {'boxes': [{<title>: <parts>}, ...], 'count': <len(boxes)>}
[ "Returns", "parse", "tree", "template", "with", "title", "containing", "<boxterm", ">", "as", "dict", ":" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L22-L48
siznax/wptools
wptools/utils.py
get_links
def get_links(rlinks): """ returns list of titles/urls from query/parse links response """ if rlinks is None: return links = [] for item in rlinks: if 'url' in item: links.append(item['url']) if 'title' in item and 'ns' in item: if item['ns'] == 0:...
python
def get_links(rlinks): """ returns list of titles/urls from query/parse links response """ if rlinks is None: return links = [] for item in rlinks: if 'url' in item: links.append(item['url']) if 'title' in item and 'ns' in item: if item['ns'] == 0:...
[ "def", "get_links", "(", "rlinks", ")", ":", "if", "rlinks", "is", "None", ":", "return", "links", "=", "[", "]", "for", "item", "in", "rlinks", ":", "if", "'url'", "in", "item", ":", "links", ".", "append", "(", "item", "[", "'url'", "]", ")", "...
returns list of titles/urls from query/parse links response
[ "returns", "list", "of", "titles", "/", "urls", "from", "query", "/", "parse", "links", "response" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L51-L64
siznax/wptools
wptools/utils.py
is_text
def is_text(obj, name=None): """ returns True if object is text-like """ try: # python2 ans = isinstance(obj, basestring) except NameError: # python3 ans = isinstance(obj, str) if name: print("is_text: (%s) %s = %s" % (ans, name, obj.__class__), file=sys.s...
python
def is_text(obj, name=None): """ returns True if object is text-like """ try: # python2 ans = isinstance(obj, basestring) except NameError: # python3 ans = isinstance(obj, str) if name: print("is_text: (%s) %s = %s" % (ans, name, obj.__class__), file=sys.s...
[ "def", "is_text", "(", "obj", ",", "name", "=", "None", ")", ":", "try", ":", "# python2", "ans", "=", "isinstance", "(", "obj", ",", "basestring", ")", "except", "NameError", ":", "# python3", "ans", "=", "isinstance", "(", "obj", ",", "str", ")", "...
returns True if object is text-like
[ "returns", "True", "if", "object", "is", "text", "-", "like" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L67-L78
siznax/wptools
wptools/utils.py
json_loads
def json_loads(data): """ python-version-safe json.loads """ try: return json.loads(data, encoding='utf-8') except TypeError: return json.loads(data.decode('utf-8'))
python
def json_loads(data): """ python-version-safe json.loads """ try: return json.loads(data, encoding='utf-8') except TypeError: return json.loads(data.decode('utf-8'))
[ "def", "json_loads", "(", "data", ")", ":", "try", ":", "return", "json", ".", "loads", "(", "data", ",", "encoding", "=", "'utf-8'", ")", "except", "TypeError", ":", "return", "json", ".", "loads", "(", "data", ".", "decode", "(", "'utf-8'", ")", ")...
python-version-safe json.loads
[ "python", "-", "version", "-", "safe", "json", ".", "loads" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L90-L97
siznax/wptools
wptools/utils.py
stderr
def stderr(msg, silent=False): """ write msg to stderr if not silent """ if not silent: print(msg, file=sys.stderr)
python
def stderr(msg, silent=False): """ write msg to stderr if not silent """ if not silent: print(msg, file=sys.stderr)
[ "def", "stderr", "(", "msg", ",", "silent", "=", "False", ")", ":", "if", "not", "silent", ":", "print", "(", "msg", ",", "file", "=", "sys", ".", "stderr", ")" ]
write msg to stderr if not silent
[ "write", "msg", "to", "stderr", "if", "not", "silent" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L110-L115
siznax/wptools
wptools/utils.py
template_to_dict
def template_to_dict(tree, debug=0, find=False): """ returns wikitext template as dict debug = 1 prints minimal debug info to stdout debug > 1 compares _iter() versus _find() results find = True sets values from _find() algorithm (default _iter()) """ # you can comp...
python
def template_to_dict(tree, debug=0, find=False): """ returns wikitext template as dict debug = 1 prints minimal debug info to stdout debug > 1 compares _iter() versus _find() results find = True sets values from _find() algorithm (default _iter()) """ # you can comp...
[ "def", "template_to_dict", "(", "tree", ",", "debug", "=", "0", ",", "find", "=", "False", ")", ":", "# you can compare (most) raw Infobox wikitext like this:", "# https://en.wikipedia.org/wiki/TITLE?action=raw&section=0", "obj", "=", "defaultdict", "(", "str", ")", "erro...
returns wikitext template as dict debug = 1 prints minimal debug info to stdout debug > 1 compares _iter() versus _find() results find = True sets values from _find() algorithm (default _iter())
[ "returns", "wikitext", "template", "as", "dict" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L118-L168
siznax/wptools
wptools/utils.py
template_to_dict_alt
def template_to_dict_alt(tree, title): """ Returns parse tree template as {<title>: <parts>} This is a more general parse tree infobox template parser. """ box = [] part = [] for item in tree.iter(): if item.tag == 'part': if part: box.append(part) ...
python
def template_to_dict_alt(tree, title): """ Returns parse tree template as {<title>: <parts>} This is a more general parse tree infobox template parser. """ box = [] part = [] for item in tree.iter(): if item.tag == 'part': if part: box.append(part) ...
[ "def", "template_to_dict_alt", "(", "tree", ",", "title", ")", ":", "box", "=", "[", "]", "part", "=", "[", "]", "for", "item", "in", "tree", ".", "iter", "(", ")", ":", "if", "item", ".", "tag", "==", "'part'", ":", "if", "part", ":", "box", "...
Returns parse tree template as {<title>: <parts>} This is a more general parse tree infobox template parser.
[ "Returns", "parse", "tree", "template", "as", "{", "<title", ">", ":", "<parts", ">", "}", "This", "is", "a", "more", "general", "parse", "tree", "infobox", "template", "parser", "." ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L171-L199
siznax/wptools
wptools/utils.py
template_to_dict_debug
def template_to_dict_debug(name, item, debug): """ Print debug statements to compare algorithms """ if debug == 1: print("\n%s = " % name) elif debug > 1: print("\n%s" % name) print("=" * 64) print(lxml.etree.tostring(item)) print()
python
def template_to_dict_debug(name, item, debug): """ Print debug statements to compare algorithms """ if debug == 1: print("\n%s = " % name) elif debug > 1: print("\n%s" % name) print("=" * 64) print(lxml.etree.tostring(item)) print()
[ "def", "template_to_dict_debug", "(", "name", ",", "item", ",", "debug", ")", ":", "if", "debug", "==", "1", ":", "print", "(", "\"\\n%s = \"", "%", "name", ")", "elif", "debug", ">", "1", ":", "print", "(", "\"\\n%s\"", "%", "name", ")", "print", "(...
Print debug statements to compare algorithms
[ "Print", "debug", "statements", "to", "compare", "algorithms" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L202-L212
siznax/wptools
wptools/utils.py
template_to_dict_find
def template_to_dict_find(item, debug=0): """ DEPRECATED: Returns infobox parsetree value using etree.find() Older template_to_dict() algorithm, uses etree.xpath() to "lookup" or find specific elements, but fails to include tail text in the order it is found, and does not _exclude_ <ext> tags (refe...
python
def template_to_dict_find(item, debug=0): """ DEPRECATED: Returns infobox parsetree value using etree.find() Older template_to_dict() algorithm, uses etree.xpath() to "lookup" or find specific elements, but fails to include tail text in the order it is found, and does not _exclude_ <ext> tags (refe...
[ "def", "template_to_dict_find", "(", "item", ",", "debug", "=", "0", ")", ":", "if", "debug", ">", "1", ":", "print", "(", "\"template_to_dict_find:\"", ")", "tmpl", "=", "item", ".", "find", "(", "'value'", ")", ".", "find", "(", "'template'", ")", "i...
DEPRECATED: Returns infobox parsetree value using etree.find() Older template_to_dict() algorithm, uses etree.xpath() to "lookup" or find specific elements, but fails to include tail text in the order it is found, and does not _exclude_ <ext> tags (references, etc.). Compare to template_to_dict_iter().
[ "DEPRECATED", ":", "Returns", "infobox", "parsetree", "value", "using", "etree", ".", "find", "()" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L215-L237
siznax/wptools
wptools/utils.py
template_to_dict_iter
def template_to_dict_iter(item, debug=0): """ Returns infobox parsetree value using etree.iter() Preferred template_to_dict() algorithm, uses etree.iter() to iterate over elements, accumulating tail text in order, but not preserving `<ext>` tags (references, etc.). The advantage is that it pick...
python
def template_to_dict_iter(item, debug=0): """ Returns infobox parsetree value using etree.iter() Preferred template_to_dict() algorithm, uses etree.iter() to iterate over elements, accumulating tail text in order, but not preserving `<ext>` tags (references, etc.). The advantage is that it pick...
[ "def", "template_to_dict_iter", "(", "item", ",", "debug", "=", "0", ")", ":", "valarr", "=", "[", "]", "found_template", "=", "False", "if", "debug", ">", "1", ":", "print", "(", "\"template_to_dict_iter:\"", ")", "for", "elm", "in", "item", ".", "iter"...
Returns infobox parsetree value using etree.iter() Preferred template_to_dict() algorithm, uses etree.iter() to iterate over elements, accumulating tail text in order, but not preserving `<ext>` tags (references, etc.). The advantage is that it picks up MORE templates and links that may be mixed in wit...
[ "Returns", "infobox", "parsetree", "value", "using", "etree", ".", "iter", "()" ]
train
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L240-L277