<s> import os <EOL> import tornado . locale <EOL> from celery . task import task <EOL> from tornado . options import options <EOL> from d3status . db import load_model <EOL> from d3status . tasks import apns_tasks <EOL> @ task <EOL> def status_notification_task ( changed_status ) : <EOL> status_notifciation ( changed_status ) <EOL> def status_notifciation ( changed_status ) : <EOL> notifications = { } <EOL> for category , services in changed_status . iteritems ( ) : <EOL> for name , st in services . iteritems ( ) : <EOL> if name == "<STR_LIT>" : <EOL> notifications [ category ] = st <EOL> for category , st in notifications . iteritems ( ) : <EOL> status = "<STR_LIT>" if st else "<STR_LIT>" <EOL> offset = <NUM_LIT:0> <EOL> limit = <NUM_LIT:200> <EOL> while True : <EOL> subscribers = load_model ( "<STR_LIT>" ) . get_subscribers ( limit , offset ) <EOL> if not subscribers : <EOL> break <EOL> for subscribe in subscribers : <EOL> if category in subscribe . categorys : <EOL> alert = _trans_alert ( "<STR_LIT>" , <EOL> category , status , subscribe . locale ) <EOL> apns_tasks . apns_push_task . delay ( subscribe . token , { } , <EOL> alert = alert , badge = <NUM_LIT:1> , <EOL> sound = "<STR_LIT:default>" ) <EOL> offset += len ( subscribers ) <EOL> def _trans ( s , locale ) : <EOL> locale = tornado . locale . get ( locale ) <EOL> s = locale . translate ( s ) . strip ( "<STR_LIT>" ) <EOL> return s <EOL> def _trans_alert ( alert , category , status , locale ) : <EOL> def _ ( s ) : <EOL> return _trans ( s , locale ) <EOL> return _ ( alert ) % ( _ ( category ) , _ ( status ) ) <EOL> _i18n_dir = os . path . join ( os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT:..>" ) , '<STR_LIT>' ) <EOL> tornado . locale . load_translations ( _i18n_dir ) </s>
