[docs]def_get_cloudcasts():# we should page through for a while, but at a certain point it probably# isn't worth the load timesforpage_indexinrange(20):url=MIXCLOUD_FEED_URL.format(settings.MIXCLOUD_USERNAME)ck='mixcloud:api-page:{}'.format(page_index)hit=cache.get(ck)ifhit:page=hitelse:try:resp=requests.get(url,params={'limit':MIXCLOUD_PAGE_LIMIT,'offset':page_index*MIXCLOUD_PAGE_LIMIT,},timeout=TIMEOUT,)exceptrequests.RequestExceptionase:# mission failed; we'll get 'em next timelogger.exception(e)breaktry:page=resp.json()exceptJSONDecodeError:logger.exception(resp.text)return[]cache.set(ck,page,60*20)data=page.get('data',[])ifnotdata:breakyield fromdata
[docs]defcloudcasts_for(date)->list[Any]:hunting_for=date.strftime('%d/%m/%Y')cloudcasts=[]forcloudcastin_get_cloudcasts():matched_item=Falseifhunting_forincloudcast['name']:cloudcasts.append(cloudcast)matched_item=Trueifcloudcastsandnotmatched_item:# we've matched something, and the next item isn't also a# match, which means we don't need to worry about the next item# being a match either; the only cases where a show has# multiple cloudcasts, they'll be adjacentbreakreturnsorted(cloudcasts,key=lambdac:c['created_time'])