def params(self, params): if params: return '?' + '&'.join( '%s=%s' % (uquote(str(k)), uquote(str(v))) for k, v in params.items() ) return ''
def possible_doi(author, title, n=10): ''' Takes in an author and title, returns a doi, and the best leven dist. ''' url = "https://api.crossref.org/works?rows={}&query.author={}&query.title={}" r = requests.get(url.format(n, uquote(author), uquote(title))) print(r, title) d = r.json() doi_list = [] # List of tuples for item in d['message']['items']: doi_title = item['title'] print(doi_title) doi = item['DOI'] ratio = fuzz.ratio(doi_title, title) doi_list.append((doi_title, doi, ratio)) return max(doi_list, key=itemgetter(2))[1:]
def quote(value, safe="", encoding="utf-8"): return uquote(value.encode(encoding), safe)
def quote(value, safe='', encoding='utf-8'): return uquote(value.encode(encoding), safe)
def quote(url, safe='/', encoding=None, errors=None): """Wrapper for urllib.parse.quote""" return uquote(url, safe=safe, encoding=encoding, errors=errors)
def unquote(string): try: return uquote(string) except: # pylint: disable=bare-except return string