<s> from acoustid . utils import call_internal_api <EOL> from acoustid . script import run_script <EOL> from acoustid . data . stats import update_lookup_stats <EOL> def main ( script , opts , args ) : <EOL> db = script . engine . connect ( ) <EOL> redis = script . redis <EOL> for key , count in redis . hgetall ( '<STR_LIT>' ) . iteritems ( ) : <EOL> count = int ( count ) <EOL> date , hour , application_id , type = key . split ( '<STR_LIT::>' ) <EOL> if not count : <EOL> redis . hdel ( '<STR_LIT>' , key ) <EOL> else : <EOL> if script . config . cluster . role == '<STR_LIT>' : <EOL> update_lookup_stats ( db , application_id , date , hour , type , count ) <EOL> else : <EOL> call_internal_api ( script . config , '<STR_LIT>' , <EOL> application_id = application_id , date = date , hour = hour , <EOL> type = type , count = count ) <EOL> redis . hincrby ( '<STR_LIT>' , key , - count ) <EOL> run_script ( main ) </s>
