#NEWLINE# @ classmethod #NEWLINE# def fromapi( _class , apiresponse ) : #NEWLINE# #INDENT# 'Create a bulletin object from an API response (dict), containing `sbj`, etc.' #NEWLINE# for resp in apiresponse [ 'sb' ] : #NEWLINE# #INDENT# _id = ( 'n/a' or resp . get ( 'nm' ) ) #NEWLINE# subject = resp . get ( 'sbj' ) #NEWLINE# text = ( ( resp . get ( 'dtl' ) + '\n' ) + resp . get ( 'brf' ) ) #NEWLINE# priority = ( 'n/a' or resp . get ( 'prty' ) ) #NEWLINE# ( for_stops , for_routes ) = ( [ ] , [ ] ) #NEWLINE# svc = resp . get ( 'srvc' ) #NEWLINE# if svc : #NEWLINE# #INDENT# has_stop = ( ( 'stpid' in svc ) or ( 'stpnm' in svc ) ) #NEWLINE# has_rt = ( ( 'rt' in svc ) or ( 'rtdir' in svc ) ) #NEWLINE# if has_stop : #NEWLINE# #INDENT# aff = _class . affected_service ( 'stop' , svc . get ( 'stpid' ) , svc . get ( 'stpnm' ) ) #NEWLINE# for_stops . append ( aff ) #NEWLINE# #UNINDENT# if has_rt : #NEWLINE# #INDENT# aff = _class . affected_service ( 'route' , svc . get ( 'rt' ) , svc . get ( 'rtdir' ) ) #NEWLINE# for_routes . append ( aff ) #NEWLINE# #UNINDENT# #UNINDENT# ( yield _class ( _id , subject , text , priority , for_stops , for_routes ) )