私はFacebook APIを使用していて、投稿の反応を見ています。 FBは最大100レコードまで応答を制限しますが、次のロットなどを取得するためにページ番号を付けます。私の発電機のアプリケーションはここで間違っていますか?
私のテストケースは100回を越える反応(最後のカウント:550)を持っています。返されたいのはタプルのリストで、各タプルはその投稿に対する反応です。ここで
は私がこれまで持っているものです...出力リストは、それがループ内の一部のデータやスピンを待ってハングアップすることが
import requests
def get_next_linksv3(page):
while True:
#try:
r = requests.get(page)
r_json = r.json()
if 'paging' in r_json.keys() and 'next' in r_json['paging']:
page = r_json['paging']['next']
yield page
else:
return
def process_follow_on_reactions_link(next_link, list_reaction_tuples):
nr = requests.get(next_link)
r_json = nr.json()
tmp_list = []
if 'data' in r_json.keys():
for nrecord in r_json['data']:
reaction_id = nrecord['id']
reaction_id_name = nrecord['name']
reaction_type = nrecord['type']
tmp_list.append((reaction_id,reaction_id_name,reaction_type))
return tmp_list
def process_initial_reactions_link(link):
list_reaction_tuples = []
r = requests.get(link)
r_json = r.json()
if 'reactions' in r_json.keys():
for record in r_json['reactions']['data']:
reaction_id = record['id']
reaction_id_name = record['name']
reaction_type = record['type']
list_reaction_tuples.append((reaction_id,reaction_id_name,reaction_type))
if 'reactions' in r_json.keys() and 'paging' in r_json['reactions'] and 'next' in r_json['reactions']['paging']:
next_link = r_json['reactions']['paging']['next']
gen = get_next_linksv3(next_link)
while True:
try:
list_reaction_tuples = list_reaction_tuples + (process_follow_on_reactions_link(next(gen), list_reaction_tuples))
except StopIteration:
return list_reaction_tuples
return list_reaction_tuples
tuple_list = process_initial_reactions_link(target_link)
どこがハングしますか? – mic4ael
トレースバックを投稿してください。 – 0decimal0
コードを編集して、ハングする時間が長くなるようにしましたが、現在100以上の期待される結果がありません。 –