Skip to content

Commit

Permalink
added new class for dumping persons
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 committed May 5, 2022
1 parent 4c2de41 commit 5f5377f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
46 changes: 46 additions & 0 deletions freud_api_crawler/entities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import requests
import freud_api_crawler.freud_api_crawler as frd
from freud_api_crawler.string_utils import always_https


class FrdPerson(frd.FrdClient):

"""class to interact with person endpoint"""

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.person_ep = f"{self.endpoint}taxonomy_term/personen"

def yield_persons(self):
""" iterates through person endpoint and yields dict with some data """
counter = 1
url = self.person_ep
next_page = True
while next_page:
print(url)
response = None
result = None
x = None
response = requests.get(
url,
cookies=self.cookie,
allow_redirects=True
)
result = response.json()
links = result['links']
if links.get('next', False):
orig_url = links['next']['href']
url = always_https(orig_url)
else:
next_page = False
for x in result['data']:
item = {}
item['id'] = f"frd_person_{counter:05}"
item['drupal_hash'] = x['id']
for y in [
'drupal_internal__tid',
'name',
]:
item[y] = x['attributes'][y]
counter += 1
yield(item)
6 changes: 6 additions & 0 deletions tests/test_freud_api_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from freud_api_crawler import freud_api_crawler as frd
from freud_api_crawler import string_utils
from freud_api_crawler import tei_utils
from freud_api_crawler.entities import FrdPerson


WERK_ID = "9d035a03-28d7-4013-adaf-63337d78ece4"
Expand Down Expand Up @@ -55,6 +56,11 @@ def setUp(self):
def tearDown(self):
"""Tear down test fixtures, if any."""

def test_001__persons(self):
persons = FrdPerson(auth_items=frd.AUTH_ITEMS)
first_person = persons.yield_persons().__next__()
self.assertTrue(first_person['id'][-1] == '1')

def test_002_endpoints_with_auth(self):
"""Test of endpoints-method"""
frd_obj = frd.FrdClient(auth_items=frd.AUTH_ITEMS)
Expand Down

0 comments on commit 5f5377f

Please sign in to comment.