<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> from service import upload <EOL> from utils import base_url <EOL> import logging <EOL> import Image <EOL> import ImageOps <EOL> import cStringIO <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> """<STR_LIT>""" <EOL> CONTACTS = [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ base_url + "<STR_LIT>" ] <EOL> } <EOL> ] <EOL> """<STR_LIT>""" <EOL> WELCOMES = [ <EOL> { <EOL> "<STR_LIT:html>" : ( "<STR_LIT>" <EOL> "<STR_LIT>" + base_url + "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> } <EOL> ] <EOL> def _make_linear_ramp ( white ) : <EOL> """<STR_LIT>""" <EOL> ramp = [ ] <EOL> r , g , b = white <EOL> for i in range ( <NUM_LIT:255> ) : <EOL> ramp . extend ( ( r * i / <NUM_LIT:255> , g * i / <NUM_LIT:255> , b * i / <NUM_LIT:255> ) ) <EOL> return ramp <EOL> def _apply_sepia_filter ( image ) : <EOL> """<STR_LIT>""" <EOL> sepia = _make_linear_ramp ( ( <NUM_LIT:255> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> orig_mode = image . mode <EOL> if orig_mode != "<STR_LIT:L>" : <EOL> image = image . convert ( "<STR_LIT:L>" ) <EOL> image = ImageOps . autocontrast ( image ) <EOL> image . putpalette ( sepia ) <EOL> if orig_mode != "<STR_LIT:L>" : <EOL> image = image . convert ( orig_mode ) <EOL> return image <EOL> def handle_item ( item , notification , service , test ) : <EOL> """<STR_LIT>""" <EOL> if "<STR_LIT>" in notification : <EOL> for action in notification [ "<STR_LIT>" ] : <EOL> if "<STR_LIT:type>" in action and action [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> break <EOL> else : <EOL> return <EOL> else : <EOL> return <EOL> if "<STR_LIT>" in item : <EOL> for rec in item [ "<STR_LIT>" ] : <EOL> if rec [ "<STR_LIT:id>" ] == "<STR_LIT>" : <EOL> break <EOL> else : <EOL> return <EOL> else : <EOL> return <EOL> imageId = None <EOL> if "<STR_LIT>" in item : <EOL> for att in item [ "<STR_LIT>" ] : <EOL> if att [ "<STR_LIT>" ] . startswith ( "<STR_LIT>" ) : <EOL> imageId = att [ "<STR_LIT:id>" ] <EOL> break <EOL> if imageId is None : <EOL> logging . info ( "<STR_LIT>" ) <EOL> return <EOL> attachment_metadata = service . timeline ( ) . attachments ( ) . get ( <EOL> itemId = item [ "<STR_LIT:id>" ] , attachmentId = imageId ) . execute ( ) <EOL> content_url = attachment_metadata . get ( "<STR_LIT>" ) <EOL> resp , content = service . _http . request ( content_url ) <EOL> if resp . status != <NUM_LIT:200> : <EOL> logging . info ( "<STR_LIT>" ) <EOL> tempimg = cStringIO . StringIO ( content ) <EOL> im = Image . open ( tempimg ) <EOL> new_im = _apply_sepia_filter ( im ) <EOL> f = cStringIO . StringIO ( ) <EOL> new_im . save ( f , "<STR_LIT>" ) <EOL> content = f . getvalue ( ) <EOL> f . close ( ) <EOL> new_item = { } <EOL> new_item [ "<STR_LIT>" ] = [ { "<STR_LIT:action>" : "<STR_LIT>" } ] <EOL> result = upload . multipart_insert ( new_item , content , "<STR_LIT>" , service , test ) <EOL> logging . info ( result ) </s>
