def main(): arguments = docopt(__doc__) quiet = arguments['--quiet'] unzip = arguments['--unzip'] username = arguments['--username'] auth_token = arguments['--auth-token'] gmail = arguments['--gmail'] if arguments['--gpasswd'] is None: gpasswd = getpass('Gmail password:'******'--gpasswd'] path = arguments['<path>'] if not os.path.isdir(path): print('No such directory: {0}'.format(arguments['<path>'])) sys.exit(1) s = Snapchat() if auth_token: s.restore_token(username, auth_token, gmail, gpasswd) else: if arguments['--password'] is None: password = getpass('Password:'******'--password'] if not s.login(username, password, gmail, gpasswd)['updates_response'].get('logged'): print('Invalid username or password') sys.exit(1) for snap in s.get_friend_stories(): filename = '{0}.{1}'.format(snap['id'], get_file_extension(snap['media_type'])) abspath = os.path.abspath(os.path.join(path, filename)) if os.path.isfile(abspath): continue data = s.get_story_blob(snap['media_id'], snap['media_key'], snap['media_iv']) if data is None: continue with open(abspath, 'wb') as f: f.write(data) if not quiet: print('Saved: {0}'.format(abspath)) if is_zipfile(abspath) and unzip: unzip_snap_mp4(abspath, quiet)
def process_snap(s, snap, path, quiet=False, unzip=False): filename = '{0}_{1}.{2}'.format(snap['sender'], snap['id'], get_file_extension(snap['media_type'])) abspath = os.path.abspath(os.path.join(path, filename)) if os.path.isfile(abspath): return data = s.get_blob(snap['id']) if data is None: return with open(abspath, 'wb') as f: f.write(data) if not quiet: print('Saved: {0}'.format(abspath)) if is_zipfile(abspath) and unzip: unzip_snap_mp4(abspath, quiet)
def check_snaps(s, path, whitelist, base_url): # Download all our snaps and add items to our feed for snap in s.get_friend_stories(): filename = '{0}.{1}'.format(snap['id'], get_file_extension(snap['media_type'])) abspath = os.path.abspath(os.path.join(path, filename)) if os.path.isfile(abspath): continue data = s.get_story_blob(snap['media_id'], snap['media_key'], snap['media_iv']) if data is None: continue # in_whitelist determines whether we should publish this story # or just download it. In this case, chmod so nginx can read. in_whitelist = False if whitelist: if snap['id'].split('~')[0] in whitelist: in_whitelist = True else: in_whitelist = True with open(abspath, 'wb') as f: # Let webserver read it if we publish it if not in_whitelist: os.chmod(abspath, 0o600) else: os.chmod(abspath, 0o644) f.write(data) date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M") print('{0} Saved {1}'.format(date, urlparse.urljoin(base_url, filename))) if is_zipfile(abspath): unzip_snap_mp4(abspath, quiet=False)