To download the information from ISSN related to the journals found close din oaire and oalex

This commit is contained in:
Miriam Baglioni 2024-12-11 11:32:57 +01:00
parent 15205a7ed2
commit 08ec032ca6
1 changed files with 144 additions and 0 deletions

144
downloadFromISSN.ipynb Normal file
View File

@ -0,0 +1,144 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"id": "d671915a-cc99-4533-9bae-a099b09aa297",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import json"
]
},
{
"cell_type": "code",
"execution_count": 61,
"id": "e0042241-45a9-4bc7-98f3-fbcf61a883db",
"metadata": {},
"outputs": [],
"source": [
"\n",
"headers = {\n",
" 'Accept': 'application/json',\n",
"}\n",
"\n",
"response = requests.get('https://api.issn.org/authenticate/[user]/[param]', headers=headers)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "1a60844e-5e2e-420c-b95d-1cd6a0c8e8fa",
"metadata": {},
"outputs": [],
"source": [
"ACCESS_TOKEN = json.loads(response.text)['token']"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "d4c853bf-935e-4822-859c-b4018f3eb10f",
"metadata": {},
"outputs": [],
"source": [
"#downloading closed from oaire\n",
"fin = open('./input/OpenAireClosed.json')\n",
"fout = open('downloadedITNotOpen.json','w')\n",
"\n",
"headers = {\n",
" 'Accept': 'application/json',\n",
" 'Content-Type': 'application/json',\n",
" 'Authorization': 'JWT ' + ACCESS_TOKEN\n",
"}\n",
"\n",
"params = {\n",
" 'natifjson': 'true',\n",
"}\n",
"\n",
"lines = fin.read()\n",
"dic = json.loads(lines[0])\n",
"\n",
"downloaded = []\n",
"for entry in dic:\n",
" issn = ''\n",
" if 'issnPrinted' in entry and entry['issnPrinted'] != '':\n",
" issn = entry['issnPrinted']\n",
" elif 'issnOnline' in entry and entry['issnOnline'] != '':\n",
" issn = entry['issnOnline']\n",
" if issn!='' and not issn in downloaded:\n",
" json_data = {\"search\":[issn], 'page':0, 'size':10}\n",
" response = requests.post('https://api.issn.org/search', params=params, headers=headers, json=json_data)\n",
" fout.write(json.dumps(response.text) + \"\\n\")\n",
" downloaded.append(issn)\n",
"\n",
"fout.close()"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "b02bc2d6-38b2-4a19-9395-6875cda450e2",
"metadata": {},
"outputs": [],
"source": [
"#downloading closed from oalex\n",
"fin = open('./input/itClosedFromOpenAlex.json')\n",
"fout = open('downloadedItNotOpenoalex.json','w')\n",
"\n",
"headers = {\n",
" 'Accept': 'application/json',\n",
" 'Content-Type': 'application/json',\n",
" 'Authorization': 'JWT ' + ACCESS_TOKEN\n",
"}\n",
"\n",
"params = {\n",
" 'natifjson': 'true',\n",
"}\n",
"\n",
"lines = fin.read().split(\"\\n\")\n",
"\n",
"downloaded = []\n",
"for line in lines:\n",
" if line == '':\n",
" continue\n",
" dic = json.loads(line[:-1])\n",
" issn = ''\n",
" if 'issn_l' in dic and dic['issn_l'] != '':\n",
" issn = dic['issn_l']\n",
" elif 'issn' in dic and len(dic['issn']) >= 1:\n",
" issn = dic['issn'][0]\n",
" if issn!='' and not issn in downloaded:\n",
" json_data = {\"search\":[issn], 'page':0, 'size':10}\n",
" response = requests.post('https://api.issn.org/search', params=params, headers=headers, json=json_data)\n",
" fout.write(response.text + \"\\n\")\n",
" downloaded.append(issn) \n",
" \n",
"\n",
"fout.close()\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}