Newer
Older
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
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from lxml import etree\n",
"import requests\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def getLinksAndBarcodes(local_mms_id):\n",
" cont=requests.get('https://open-na.hosted.exlibrisgroup.com/alma/43ACC_ONB/bf/entity/instance/' + local_mms_id).content\n",
" e = etree.XML(cont)\n",
" namespaces = {\n",
" 'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',\n",
" 'bf': 'http://id.loc.gov/ontologies/bibframe/',\n",
" 'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',\n",
" 'bflc': 'http://id.loc.gov/ontologies/bflc/'\n",
" }\n",
" result = e.xpath('/rdf:RDF/bf:Instance/bf:hasItem/bf:Item/bf:electronicLocator/rdfs:Resource/bflc:locator/@rdf:resource', namespaces=namespaces)\n",
" barcodes = []\n",
" for link in result:\n",
" splits = link.split('%2B')\n",
" if len(splits) >= 2:\n",
" barcodes.append('+' + link.split('%2B')[1])\n",
" print (local_mms_id + ': ' + \", \".join(barcodes))\n",
" linksJoined = \", \".join(result)\n",
" barcodesJoined = \", \".join(barcodes)\n",
" return [linksJoined, barcodesJoined]"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"NaN 990032334150603338\nNaN 990035648370603338\nNaN 990031644540603338\nName: MMS-ID, dtype: int64"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.read_excel('ABOExamplesFromALMA.xlsx')\n",
"df_sample = df.sample(3).copy()\n",
"df_sample['MMS-ID']"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"990032334150603338: +Z227525900, +Z172047601\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"990035648370603338: +Z219890307, +Z255756803\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"990031644540603338: +Z136879807, +Z172905502\n"
]
}
],
"source": [
"df_sample[['Viewerlinks','Barcodes']] = df_sample.apply(lambda row: getLinksAndBarcodes(str(row['MMS-ID'])), axis=1, result_type='expand')"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"writer = pd.ExcelWriter(r'ABOExamplesFromALMAextended.xlsx', engine='xlsxwriter',options={'strings_to_urls': False})\n",
"df_sample.to_excel(writer)\n",
"writer.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}