所以,我試圖建立一個Flask應用程序,以跟蹤我的電視節目(只是爲了好玩)...但現在我正在嘗試處理API本身(TVmaze ),我會用「箭」作爲例子。我想要做的是創建一個dict
像這樣all_seasons = {season_number:{'ep_number':{'ep_name':'Exemple...', ep_num: ep_number}}}
所以例如,如果我想獲得本賽季的名字4第22集我會這樣做all_seasons[4][22]['ep_name']
並以某種方式設法做到這一點(但),但這是我得到:將數據添加到字典
{1: {23: {'ep_name': 'Sacrifice', 'ep_num': 23}},
2: {23: {'ep_name': 'Unthinkable', 'ep_num': 23}},
3: {23: {'ep_name': 'My Name is Oliver Queen', 'ep_num': 23}},
4: {23: {'ep_name': 'Schism', 'ep_num': 23}},
5: {23: {'ep_name': 'Lian Yu', 'ep_num': 23}}}
我只得到每個季節的第23集。我正在使用的代碼:
for i in range(len(seasonNum) +1):
while e <= total2:
if e_data[e]['season'] == i+1:
temp = i + 1
ep_num = e_data[e]['number']
ep_title = e_data[e]['name']
all_seasons[temp] = {ep_num:{'ep_name':ep_title, 'ep_num':ep_num}}
print("Season %d Episode %d - %s"%(temp, ep_num, ep_title))
else:
i+=1
e+=1
我將打印語句僅用於調試以及打印它的工作原理。顯示每個季節的所有劇集
Season 1 Episode 1 - Pilot
Season 1 Episode 2 - Honor Thy Father
Season 1 Episode 3 - Lone Gunmen
Season 1 Episode 4 - An Innocent Man
Season 1 Episode 5 - Damaged
Season 1 Episode 6 - Legacies
Season 1 Episode 7 - Muse of Fire
Season 1 Episode 8 - Vendetta
Season 1 Episode 9 - Year's End
Season 1 Episode 10 - Burned
Season 1 Episode 11 - Trust But Verify
Season 1 Episode 12 - Vertigo
Season 1 Episode 13 - Betrayal
Season 1 Episode 14 - The Odyssey
...
然後繼續。
'seasonNum','total2','e_data'等是什麼? –
'seasonNum'是節目的季節數是'dict {1:1,2:2,3:3,4:4,5:5,6:6}','total2'是數字在這種情況下,情節女巫是114或115,「電子數據」就是我從http://www.tvmaze.com/api的api'show episodes list'中得到的,每集都會返回一個json。 –
我認爲'seasonNum'可能是一個簡單的列表。 –