Почему я не могу напечатать соответствующие индексированные часы в Python при нажатии Yelp API?

Я пытаюсь извлечь часы работы через API Yelp. Однако проблема в выходных данных заключается в том, что в последнем CSV вместо того, чтобы иметь день 3 в качестве дня 3, я получаю выходные данные дня 3 в день1. Это связано с тем, что ресторан закрыт в 1-й и 2-й день. Что я могу сделать, чтобы день1 отображался как "Нет", если он действительно закрыт в этот день?

def get_business(API_KEY, business_id):
    """Query the Business API by a business ID.
    Args:
        business_id (str): The ID of the business to query.
    Returns:
        dict: The JSON response from the request.
    """
    business_path = BUSINESS_PATH + business_id

    return request(API_HOST, business_path, API_KEY)


def get_business_id(business):
    #import pdb; pdb.set_trace()
    try:
        business_id = search_matches(API_KEY, business)

        b_id = business_id['businesses'][0]['id']
    except:
        b_id = 'None'
    return b_id


df=pd.read_csv("InsuredEVG_sample10.csv", encoding='cp1252')
df['zip_code']=df['zip_code'].apply(str)

df1 = df.to_dict(orient='record') 

length = len(df1)
input_range = list(range(0, length)) 

def id_loop(df1):
    empty = []
    for i in input_range:
        business_id = get_business_id(df1[i])
        empty.append(business_id)
    return empty

a = id_loop(df1)



def get_business_hours(business_id):
    empty_start0 = []
    empty_start1 = []
    empty_start2 = []
    empty_start3 = []
    empty_start4 = []
    empty_start5 = []
    empty_start6 = []
    empty_end0 = []
    empty_end1 = []
    empty_end2 = []
    empty_end3 = []
    empty_end4 = []
    empty_end5 = []
    empty_end6 = []

    for i in input_range:
        business_detail = get_business(API_KEY,business_id[i])
        open = business_detail['hours'][0]['open']
        open_len = len(open)
        print("open")
        print(open)
        print(open_len)

        for o in range(open_len):
            print("loopiung through o: " + str(o))
            print("looping through day: " + str(open[o]['day']))
            print("loopibng through start: " + str(open[o]['start']))
            print("looping through end: " + str(open[o]['end']))
            if(open[o]['start'] != "" and open[o]['day'] == 0):
                start0 = open[o]['start']
                end0 = open[o]['end']
                print("o: " + str(o))
            else:
                start0 = 'None'
                end0 = 'None'
            if(open[o]['start'] != "" and open[o]['day'] == 1):
                start1 = open[o]["start"]
                end1 = open[o]['end']
            else:
                start1 = 'None'
                end1 = 'None'
            if(open[o]['start'] != "" and open[o]['day'] == 2):
                start2 = open[o]["start"]
                end2 = open[o]['end']
                print("start2: " + str(start2))
            else:
                start2 = 'None'
                end2 = 'None'
            if(open[o]['start'] != "" and open[o]['day'] == 3):
                start3 = open[o]['start']
                end3 = open[o]['end']
                print("start3: " + str(start3))
                print("!!o: " + str(o))
            else:
                start3 = 'None'
                end3 = 'None'
            if(open[o]['start'] != "" and open[o]['day'] == 4):
                start4 = open[o]['start']
                end4 =open[o]['end']
                print("start4: " + str(start4))
                print("**o: " + str(o))
            else:
                start4 = 'None'
                end4 = 'None'
            if(open[o]['start'] != "" and open[o]['day'] == 5):
                start5 = open[o]['start']
                end5 =open[o]['end']
                print("5o: " + str(o))
            else:
                start5 = 'None'
                end5 = 'None'
            if(open[o]['start'] != "" and open[o]['day'] == 6):
                start6 = open[o]['start']
                end6 = open[o]['end']
            else:
                start6 = 'None'
                end6 = 'None'




        empty_start0.append(start0)
        print(start0)
        print(empty_start0)
        empty_start1.append(start1)
        empty_start2.append(start2)
        empty_start3.append(start3)
        print("empty_start3: ")
        print(empty_start3)
        print("start3: " )
        print(start3)
        empty_start4.append(start4)
        print("empty_start 4: ")
        print(empty_start4)
        empty_start5.append(start5)
        print("empty_start5: ")
        print(empty_start5)
        empty_start6.append(start6)
        print("emptystart6: ")
        print(empty_start6)


    return empty_start0, empty_start1, empty_start2, empty_start3, empty_start4, empty_start5, empty_start6, empty_end0,empty_end1,empty_end2,empty_end3,empty_end4,empty_end5,empty_end6

b = get_business_hours(a)

df['start0'] = b[0]
df['start1'] = b[1]
df['start2'] = b[2]
df['start3'] = b[3]
df['start4'] = b[4]
df['start5'] = b[5]
df['start6'] = b[6]
df['end0'] = b[7]
df['end1'] = b[8]
df['end2'] = b[9]
df['end3'] = b[10]
df['end4'] = b[11]
df['end5'] = b[12]
df['end6'] = b[13]


df.to_csv('hours_of_opssample10new1.csv')        

0 ответов

Другие вопросы по тегам