Skip to content

Commit

Permalink
Use token auth for import
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Oct 6, 2023
1 parent cee2a2f commit ef36e62
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions apis_ontology/management/commands/import.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import requests
import os

from django.core.management.base import BaseCommand

Expand All @@ -8,14 +9,17 @@

from django.db import utils

SRC="https://apis.acdh.oeaw.ac.at/apis/api"
SRC = "https://apis.acdh.oeaw.ac.at/apis/api"


TOKEN = os.environ.get("TOKEN")
HEADERS = {"Authorization": f"Token {TOKEN}"}

def import_texts():
nextpage = f"{SRC}/metainfo/text/?format=json&limit=1000"
while nextpage:
print(nextpage)
page = requests.get(nextpage)
page = requests.get(nextpage, headers=HEADERS)
data = page.json()
nextpage = data['next']
for result in data['results']:
Expand All @@ -31,7 +35,7 @@ def import_sources():
nextpage = f"{SRC}/metainfo/source/?format=json&limit=1000"
while nextpage:
print(nextpage)
page = requests.get(nextpage)
page = requests.get(nextpage, headers=HEADERS)
data = page.json()
nextpage = data['next']
for result in data["results"]:
Expand All @@ -47,7 +51,7 @@ def import_uris():
nextpage = f"{SRC}/metainfo/uri/?format=json&limit=1000"
while nextpage:
print(nextpage)
page = requests.get(nextpage)
page = requests.get(nextpage, headers=HEADERS)
data = page.json()
nextpage = data['next']
for result in data["results"]:
Expand Down Expand Up @@ -140,7 +144,7 @@ def import_professions():
nextpage = f"{SRC}/vocabularies/professiontype/?format=json&limit=1000"
while nextpage:
print(nextpage)
page = requests.get(nextpage)
page = requests.get(nextpage, headers=HEADERS)
data = page.json()
nextpage = data['next']
for result in data["results"]:
Expand Down Expand Up @@ -177,7 +181,7 @@ def import_entities():
nextpage = f"{SRC}/entities/{entity}/?format=json&limit=500"
while nextpage:
print(nextpage)
page = requests.get(nextpage)
page = requests.get(nextpage, headers=HEADERS)
data = page.json()
nextpage = data['next']
for result in data["results"]:
Expand Down Expand Up @@ -253,7 +257,7 @@ def import_relations():
nextpage = f"{SRC}/relations/{relation}/?format=json&limit=500"
while nextpage:
print(nextpage)
page = requests.get(nextpage)
page = requests.get(nextpage, headers=HEADERS)
data = page.json()
nextpage = data["next"]
for result in data["results"]:
Expand Down

0 comments on commit ef36e62

Please sign in to comment.