-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoorlib.py
50 lines (39 loc) · 1.51 KB
/
noorlib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#! /usr/bin/python
# -*- coding: utf-8 -*-
"""Codes specifically related to Noormags website."""
import re
import requests
import commons
import bibtex
# import ris[1]
class Response(commons.BaseResponse):
"""Create NoorLib response object."""
def __init__(self, noormags_url, date_format='%Y-%m-%d'):
"""Make the dictionary and run self.generate()."""
self.date_format = date_format
self.url = noormags_url
self.bibtex = get_bibtex(noormags_url)
self.dictionary = bibtex.parse(self.bibtex)
#self.ris = get_ris(noormags_url)[1]
#self.dictionary = ris.parse(self.ris)[1]
self.generate()
def get_bibtex(noormags_url):
"""Get bibtex file content from a noormags url. Return as string."""
pagetext = requests.get(noormags_url).text
article_id = re.search(
'CitationHandler\.ashx\?id=(\d+)',
pagetext).group(1)
url = 'http://www.noorlib.ir/View/HttpHandler/CitationHandler.ashx?' +\
'id=' + article_id + '&format=BibTex'
bibtex = requests.get(url).text
return bibtex
def get_ris(noormags_url):
# This is copied from noormags module (currently not supported but may
# be)[1]
"""Get ris file content from a noormags url. Return as string."""
pagetext = requests.get(noormags_url).text
article_id = re.search('RIS&id=(\d+)', pagetext).group(1)
url = 'http://www.noormags.com/view/CitationHandler.ashx?' +\
'format=RIS&id=' + article_id
ris = requests.get(url).text
return ris