Python“跟踪”错误,未定义“ getResponse”

时间:2019-12-23 17:19:53

标签: python-3.x vk

我在做什么错?我正在尝试通过“ vk”社交网络的api收集一些数据。

map_data = {}
step = 24*60*60 # step - 1 day
i = minTS
geo = omsk
while i < maxTS:
    resp = getVK(geo, i, i+step, 0)
#     save_to_list(resp, data, evpphotos)f
    save_to_map(resp)
    count = resp['response']['count']
    returned = len(resp['response']['items'])
    print ('{}: count {} ret {}'.format(time.strftime("%d.%m.%Y", time.localtime(i)), count, returned))
    if count > returned:
        offset = returned
        while offset < count and offset < 3000:
            resp = getVK(geo, i, i+step, offset)
#             save_to_list(resp, data, evpphotos)
            save_to_map(resp)
            count = resp['response']['count']
            returned = len(resp['response']['items'])
#             print ('{}: count {} ret {} off {}'.format(time.strftime("%d.%m.%Y", time.localtime(i)), count, returned, offset))
            offset = offset + returned
            if returned == 0:
                break
    i = i + step
    sleep(0.5)  

执行时,会产生以下错误

NameError                                 Traceback (most recent call last)
 in 
      4 geo = omsk
      5 while i < maxTS:
----> 6     resp = getVK(geo, i, i+step, 0)
      7 #     save_to_list(resp, data, evpphotos)f
      8     save_to_map(resp)

 in getVK(geo, minTimestamp, maxTimestamp, offset)
     12         'sort': 0   # by date of creation
     13     }
---> 14     return getResponse("https://api.vk.com/method/photos.search",
     15     params=params, verify=True).json()

NameError: name 'getResponse' is not defined

我根本不是程序员,但是收集这些数据是我论文的重要部分

  

getvk

def getVK(geo, minTimestamp, maxTimestamp, offset):
    params = {
        'lat': geo[0],
        'long': geo[1],
        'count': '1000',
        'offset': offset,
        'radius': dist,
        'start_time': minTimestamp,
        'end_time': maxTimestamp,
        'access_token': VK_ACCESS_TOKEN,
        'v': VK_VERSION,
        'sort': 0   # by date of creation
    }
    return getResponse("https://api.vk.com/method/photos.search",
    params=params, verify=True).json()

0 个答案:

没有答案