-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters