本文整理匯總了Python中rdflib.URIRef.format方法的典型用法代碼示例。如果您正苦於以下問題:Python URIRef.format方法的具體用法?Python URIRef.format怎麽用?Python URIRef.format使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rdflib.URIRef
的用法示例。
在下文中一共展示了URIRef.format方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: DOI
# 需要導入模塊: from rdflib import URIRef [as 別名]
# 或者: from rdflib.URIRef import format [as 別名]
class DOI(DOIMetadata):
"""find and download a pdf for the doi given
>>> DOI('10.1016/0166-218X(92)00170-Q')
"""
headers = generic_headers
headers['Host'] = 'gen.lib.rus.ec'
headers['Referer'] = 'http://gen.lib.rus.ec/scimag/'
url = 'http://gen.lib.rus.ec/scimag/?s={}&journalid=&v=&i=&p=&redirect=1'
def __init__(self, doi, *args, **kwargs):
super().__init__(doi, *args, **kwargs)
self.url = URIRef(self.url.format(self.doi))
r = requests.get(self.url, headers=self.headers)
r.raise_for_status()
self.links = re.compile(r'a href="([^"]+pdf)"').findall(r.text)
link, *links = self.links
r = requests.get(link, stream=True)
self.filename = Literal('.'.join((doi.replace('/','_'), 'pdf')))
with open(self.filename, 'wb') as fd:
for chunk in r.iter_content(1024*10):
fd.write(chunk)
self.path = URIRef(urljoin('file:', pjoin(os.getcwd(), self.filename)))
self.graph.add((self.path, URIRef('http://purl.org/dc/terms/identifier'), self.doi))
self.graph.commit()