-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWOS.py
executable file
·150 lines (113 loc) · 4.26 KB
/
WOS.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
#
# Information about a Web of Science reference / Citation
import re
import alert
import html.parser
#SENDER = "[email protected]"
SENDER = "[email protected]"
class WOSPaper(alert.PaperAlert):
"""
Describe a particular paper being reported by Web of Science
"""
def __init__(self):
"""
Next thing is get DOIs and sources, clean up auhors,
"""
self.title = ""
self.authors = ""
self.source = ""
self.doiUrl = ""
self.doi = ""
self.url = ""
self.hopkinsUrl = ""
self.search = "WoS: "
return None
def getTitleLower(self):
return(re.sub(r'\W+', '', self.title.lower()))
def getFirstAuthorLastName(self):
if self.authors:
return(self.authors[0].split()[-1])
else:
return None
def getFirstAuthorLastNameLower(self):
firstAuthor = self.getFirstAuthorLastName()
if firstAuthor:
firstAuthor = firstAuthor.lower()
return firstAuthor
class Email(alert.Alert, html.parser.HTMLParser):
"""
All the information in a Web of Science Email.
Parse HTML email body from Web Of Science. The body maybe reporting more than one
paper.
"""
paperStartRe = re.compile(r'Record \d+ of \d+\.')
citedArticleRe = re.compile(r'.*Cited Article:.*')
def __init__(self, email):
alert.Alert.__init__(self)
html.parser.HTMLParser.__init__(self)
self.inTitle = False
self.inTitleValue = False
self.inAuthors = False
self.inCitedArticle = False
self.inCitedArticleValue = False
self.inSource = False
self.search = "WoS: "
self.feed(str(email.getBodyText())) # process the HTML body text.
return None
def handle_data(self, data):
data = data.strip().strip(r'\r\n')
# print("In handle_data: " + data)
starting = Email.paperStartRe.match(data)
if starting:
# Each paper starts with: "Record m of n. "
self.current = WOSPaper()
self.papers.append(self.current)
elif data == "Title:":
self.inTitle = True
# print("Set inTitle")
elif data == "Authors:":
self.inAuthors = True
elif Email.citedArticleRe.match(data):
self.inCitedArticle = True
# print("Set inCitedArticle")
elif data == "Source:":
self.inSource = True
elif data == "Language:":
self.inSource = False
elif self.inTitleValue:
self.current.title = data
# print("Set Title= " + self.current.title)
elif self.inAuthors:
self.current.authors = data
self.inAuthors = False
elif self.inCitedArticleValue:
# need to strip "]]>" from anywhere. Bug in WOS, if punctuation in title.
self.search += data.replace("]]>","")
self.inCitedArticle = False
self.inCitedArticleValue = False
# print("Set Search: " + self.search)
elif self.inSource:
self.current.source += data + " "
def handle_starttag(self, tag, attrs):
# print("In handle_starttag: " + tag)
if self.inTitle and tag == "value":
self.inTitleValue = True
# print("Set inTitleValue")
elif self.inCitedArticle and tag == "font":
self.inCitedArticleValue = True
# print("Set inCitedArticleValue")
elif self.inSource and tag == "a":
self.current.doiUrl = attrs[0][1].lower()
self.current.doi = self.current.doiUrl[18:]
def handle_endtag(self, tag):
# print("In handle_endtag: " + tag)
if self.inTitleValue and tag == "value":
# print("Clearing inTitleValue, inTitle")
self.inTitleValue = False
self.inTitle = False
elif self.inCitedArticleValue and tag == "font":
# print("Clearing inCitedArticleValue, inCitedArticle")
self.inCitedArticleValue = False
self.inCitedArticle = False