Commit 1cbc7043 authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

start class to perform request with TogoWS

parent a122ba2f
from abc import abstractmethod, ABC
import requests
class TogoWS(ABC):
BASE_URL = 'http://togows.org'
@abstractmethod
def get(self, entry_id):
pass
class TogoWSEntry(TogoWS):
TYPE = 'entry'
def __init__(self, database, format='json'):
self.database = database
self.format = format
def get(self, entry_id):
full_url = f"{self.BASE_URL}/{self.TYPE}/{self.database}/{entry_id}.{self.format}"
response = requests.get(full_url)
response.raise_for_status()
return response.json()
def get_field(self, entry_id, field):
full_url = f"{self.BASE_URL}/{self.TYPE}/{self.database}/{entry_id}.{field}.{self.format}"
response = requests.get(full_url)
response.raise_for_status()
return response.json()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment