Page MenuHomec4science

99_oacct_import.py
No OneTemporary

File Metadata

Created
Tue, May 21, 03:08

99_oacct_import.py

#!/usr/bin/env python
# coding: utf-8
# # Projet Open Access Compliance Check Tool (OACCT)
#
# Projet P5 de la bibliothèque de l'EPFL en collaboration avec les bibliothèques des Universités de Genève, Lausanne et Berne : https://www.swissuniversities.ch/themen/digitalisierung/p-5-wissenschaftliche-information/projekte/swiss-mooc-service-1-1-1-1
#
# Ce notebook permet d'importer les données en utilisant l'API :
#
# https://oacct-test.epfl.ch/api/
#
# Exemple avec Journals :
#
# https://oacct-test.epfl.ch/api/journal/
#
# GET /api/journal/
#
# HTTP 200 OK
# Allow: GET, POST, HEAD, OPTIONS
# Content-Type: application/json
# Vary: Accept
#
# []
#
# Media type: application/json
#
# Content:
# ``` json
# {
# "issn": [],
# "name": "",
# "name_short_iso_4": "",
# "website": "",
# "oa_options": "",
# "starting_year": null,
# "end_year": null,
# "doaj_seal": false,
# "doaj_status": false,
# "lockss": false,
# "nlch": false,
# "portico": false,
# "qoam_av_score": null
# }
# ```
#
# In[1]:
import json
import requests
import codecs
oacct_login = 'oacct_test'
oacct_pwd = '2f4dBRhyj7'
headers = {'accept': 'application/json'}
# In[2]:
# test sans authentifications
url = 'https://oacct-test.epfl.ch/api/country/'
r = requests.get(url)
print(r)
# In[3]:
print(r.text)
# In[6]:
# test avec authentification
url = 'https://oacct-test.epfl.ch/api/country/3'
r2 = requests.get(url, auth=(oacct_login, oacct_pwd))
print(r2)
# In[7]:
print(r2.text)
# In[9]:
journal = {
"id": 1,
"name": "Revue médicale suisse",
"name_short_iso_4": "Rev. méd. suisse",
"starting_year": "2005",
"end_year": "9999",
"website": "",
"country": 215.0,
"language": "138",
"publisher": "1",
"doaj_seal": 0,
"doaj_status": 0,
"lockss": 0,
"portico": 0,
"nlch": 0,
"qoam_av_score": "",
"oa_status": 1,
"issn": "1234-5678"
}
# In[11]:
# test avec post
url = 'https://oacct-test.epfl.ch/api/journal/'
r2 = requests.post(url, auth=(oacct_login, oacct_pwd), headers=headers, data=journal)
print(r2)
# In[12]:
print(r2.text)
# In[13]:
country = {
"name": "Sildavie",
"iso_code": "II",
"id": 333
}
# In[14]:
# test avec post
url = 'https://oacct-test.epfl.ch/api/country/'
r2 = requests.post(url, auth=(oacct_login, oacct_pwd), headers=headers, data=country)
print(r2)
# In[15]:
print(r2.json())
# In[16]:
country2 = {
"id": 1000000,
"name": "Sildavie3",
"iso_code": "II"
}
# In[17]:
# test avec put
url = 'https://oacct-test.epfl.ch/api/country/1000000'
r2 = requests.put(url, auth=(oacct_login, oacct_pwd), headers=headers, data=country2)
print(r2)
# In[18]:
print(r2.json())
# In[19]:
# convert to json
json_response = r2.json()
print(json_response)
# In[20]:
# get the name
name = json_response['name']
name

Event Timeline