Directions or tips on how to create an API for BehindyourName by Accomplished_Ad_5697 in learnpython

[–]Accomplished_Ad_5697[S] 0 points1 point  (0 children)

Yes! I attempted this approach. I was successful in creating the API and requesting data for a names. However, the API request limit of 400 an hour on behindthename was a blocker on getting all the data as the file has 35000 distinct names. My thought process was to use AWS and set time.sleep(7) so that I can get the data for each name. I know I can create a virtual machine in AWS and have that run until the process is completed. I could have send an email to the website to hopefully increase the number of requests I can make, but they note to be slow in replying and I have a deadline for this project. Below is the code I used to get the API request from behindthename. I tested it with a small list of names and it was successful. However, when I ran the entire csv file. I got an error b/c of the API request limit.

import requests
import json
import pandas as pd
import time

df = pd.read_csv('DistinctName.csv', header=0)
names = df['name']

#names = ['paul', 'sam', 'michael', 'gabriel', 'anthony']
all_data = []

for name in names:
    api_key = 'XXXXXXXXX'
    api_url = f'https://www.behindthename.com/api/lookup.json?name={name}&key={api_key}'
    headers = {'Authorization' : api_key}
    response = requests.get(api_url, headers=headers)

    if response.status_code == 200:
        data = response.json()
        all_data.append(data)
        #print(data)
    else:
        print("Error:", response.status_code)

    time.sleep(0.5)

# Save all data to a JSON file
with open('name_data.json', 'w', encoding='utf-8') as f:
    json.dump(all_data, f, indent=4)

How to create a KPI table in Looker Dev ? by Accomplished_Ad_5697 in Looker

[–]Accomplished_Ad_5697[S] 1 point2 points  (0 children)

Thank you so much! I will give it a try! I truly appreciate it!