<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import os . path <EOL> import sys <EOL> from getpass import getpass <EOL> from zipfile import is_zipfile , ZipFile <EOL> from docopt import docopt <EOL> from pysnap import get_file_extension , Snapchat <EOL> def process_snap ( s , snap , path , quiet = False ) : <EOL> filename = '<STR_LIT>' . format ( snap [ '<STR_LIT>' ] , snap [ '<STR_LIT:id>' ] , <EOL> get_file_extension ( snap [ '<STR_LIT>' ] ) ) <EOL> abspath = os . path . abspath ( os . path . join ( path , filename ) ) <EOL> if os . path . isfile ( abspath ) : <EOL> return <EOL> data = s . get_blob ( snap [ '<STR_LIT:id>' ] ) <EOL> if data is None : <EOL> return <EOL> with open ( abspath , '<STR_LIT:wb>' ) as f : <EOL> f . write ( data ) <EOL> if not quiet : <EOL> print ( '<STR_LIT>' . format ( abspath ) ) <EOL> if is_zipfile ( abspath ) : <EOL> zipped_snap = ZipFile ( abspath ) <EOL> unzip_dir = os . path . join ( path , '<STR_LIT>' . format ( snap [ '<STR_LIT>' ] , <EOL> snap [ '<STR_LIT:id>' ] ) ) <EOL> zipped_snap . extractall ( unzip_dir ) <EOL> if not quiet : <EOL> print ( '<STR_LIT>' . format ( filename , unzip_dir ) ) <EOL> def main ( ) : <EOL> arguments = docopt ( __doc__ ) <EOL> quiet = arguments [ '<STR_LIT>' ] <EOL> username = arguments [ '<STR_LIT>' ] <EOL> if arguments [ '<STR_LIT>' ] is None : <EOL> password = getpass ( '<STR_LIT>' ) <EOL> else : <EOL> password = arguments [ '<STR_LIT>' ] <EOL> path = arguments [ '<STR_LIT>' ] <EOL> if not os . path . isdir ( path ) : <EOL> print ( '<STR_LIT>' . format ( arguments [ '<STR_LIT>' ] ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> s = Snapchat ( ) <EOL> if not s . login ( username , password ) [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) : <EOL> print ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> for snap in s . get_snaps ( ) : <EOL> process_snap ( s , snap , path , quiet ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
