<commit_before>#!/usr/bin/env python

"""
snapchatfs.py provides a clean CLI for uploading, storing, managing, and
downloading arbitrary data files from Snapchat.
"""

import hashlib
from snapchat_core import *

__author__ = "<NAME>, <NAME>"
__copyright__ = "Copyright 2013, <NAME> and <NAME>"
__credits__ = ["<NAME>", "<NAME>"]

__license__ = "MIT"
__version__ = "0.1"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__status__ = "Prototype"


def bold(text):
    return '\033[1m%s\033[0m' % text

def sent_id_to_received_id(id):
    """
    Sent IDs have an 's' at the end, while received IDs have an 'r' on the
    end. This method strips 's' off and replaces it with an 'r'.
    """
    return id[:-1] + 'r'

def download_all_sfs(username, password):
    ss = SfsSession(username, password)
    ss.login()
    snaps = ss.get_snaps(lambda snap: isinstance(snap, SentSnap)
                         and SfsSession._is_sfs_id(snap.client_id))

    filenames_seen_so_far = set()
    content_seen_so_far = set()
    print '%s\t%s' % ('\033[1mFilename\033[0m'
                      , '\033[1mContent hash\033[0m')
    for snap in snaps:
        filename, content_hash = ss._parse_sfs_id(snap.client_id)

        if (filename in filenames_seen_so_far) \
           and (content_hash in content_seen_so_far):
            continue
        else:
            print '%s\t%s' % (filename, content_hash)
            filenames_seen_so_far.add(filename)
            content_seen_so_far.add(content_hash)

def all_downloadable_sfs_files(username, password):
    ss = SfsSession(username, password)
    ss.login()

    # get list of downloadable ids
    downloadable_snaps = ss.get_snaps(lambda snap: snap.viewable)
    downloadable_snaps_ids = set([snap.id for snap in downloadable_snaps])

    # get list of snaps sent
    snaps_sent = ss.get_snaps(lambda snap: isinstance(snap, SentSnap)
                              and SfsSession._is_sfs_id(snap.client_id))

    # for deduping -- a file is a duplicate if its content and its name
    # are the same
    filenames_seen_so_far = set()
    content_seen_so_far = set()

    # grab all "unique" files stored in Snapchat FS
    sfs_files = []
    for snap in snaps_sent:
        filename, content_hash = ss._parse_sfs_id(snap.client_id)
        received_id = sent_id_to_received_id(snap.id)

        if (filename in filenames_seen_so_far) \
           and (content_hash in content_seen_so_far):
            continue
        elif received_id in downloadable_snaps_ids:
            filenames_seen_so_far.add(filename)
            content_seen_so_far.add(content_hash)
            sfs_files.append((filename, content_hash, received_id, snap))

    return sfs_files

def list_all_downloadable_sfs_files(username, password):
    files = all_downloadable_sfs_files(username, password)

    print '\t'.join([bold('Filename'), bold('Content hash')])
    for filename, content_hash, received_id, snap in files:
        print '%s\t%s...%s' % (filename, content_hash[:17]
                               , content_hash[-3:])


if __name__ == '__main__':
    # TODO: FILL IN YOUR CREDENTIALS HERE.
    #ss = SnapchatSession('', '')
    ss.login()
    filename = 'file.txt'
    sfs_id = generate_sfs_id(filename)
    ss.upload_image(filename, sfs_id)
    ss.send_image_to('abecedarius', sfs_id)
<commit_msg>Remove hacky __main__ test from snapchatfs.py<commit_after>#!/usr/bin/env python

"""
snapchatfs.py provides a clean CLI for uploading, storing, managing, and
downloading arbitrary data files from Snapchat.
"""

import hashlib
from snapchat_core import *

__author__ = "<NAME>, <NAME>"
__copyright__ = "Copyright 2013, <NAME> and <NAME>"
__credits__ = ["<NAME>", "<NAME>"]

__license__ = "MIT"
__version__ = "0.1"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__status__ = "Prototype"


def bold(text):
    return '\033[1m%s\033[0m' % text

def sent_id_to_received_id(id):
    """
    Sent IDs have an 's' at the end, while received IDs have an 'r' on the
    end. This method strips 's' off and replaces it with an 'r'.
    """
    return id[:-1] + 'r'

def download_all_sfs(username, password):
    ss = SfsSession(username, password)
    ss.login()
    snaps = ss.get_snaps(lambda snap: isinstance(snap, SentSnap)
                         and SfsSession._is_sfs_id(snap.client_id))

    filenames_seen_so_far = set()
    content_seen_so_far = set()
    print '%s\t%s' % ('\033[1mFilename\033[0m'
                      , '\033[1mContent hash\033[0m')
    for snap in snaps:
        filename, content_hash = ss._parse_sfs_id(snap.client_id)

        if (filename in filenames_seen_so_far) \
           and (content_hash in content_seen_so_far):
            continue
        else:
            print '%s\t%s' % (filename, content_hash)
            filenames_seen_so_far.add(filename)
            content_seen_so_far.add(content_hash)

def all_downloadable_sfs_files(username, password):
    ss = SfsSession(username, password)
    ss.login()

    # get list of downloadable ids
    downloadable_snaps = ss.get_snaps(lambda snap: snap.viewable)
    downloadable_snaps_ids = set([snap.id for snap in downloadable_snaps])

    # get list of snaps sent
    snaps_sent = ss.get_snaps(lambda snap: isinstance(snap, SentSnap)
                              and SfsSession._is_sfs_id(snap.client_id))

    # for deduping -- a file is a duplicate if its content and its name
    # are the same
    filenames_seen_so_far = set()
    content_seen_so_far = set()

    # grab all "unique" files stored in Snapchat FS
    sfs_files = []
    for snap in snaps_sent:
        filename, content_hash = ss._parse_sfs_id(snap.client_id)
        received_id = sent_id_to_received_id(snap.id)

        if (filename in filenames_seen_so_far) \
           and (content_hash in content_seen_so_far):
            continue
        elif received_id in downloadable_snaps_ids:
            filenames_seen_so_far.add(filename)
            content_seen_so_far.add(content_hash)
            sfs_files.append((filename, content_hash, received_id, snap))

    return sfs_files

def list_all_downloadable_sfs_files(username, password):
    files = all_downloadable_sfs_files(username, password)

    print '\t'.join([bold('Filename'), bold('Content hash')])
    for filename, content_hash, received_id, snap in files:
        print '%s\t%s...%s' % (filename, content_hash[:17]
                               , content_hash[-3:])
{'fraction_non_alphanumeric': 0.1055910294346675, 'fraction_numerical': 0.010590250739760162, 'mean_word_length': 2.9962663347853145, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5686839', 'n_tokens_mistral': 2213, 'n_tokens_neox': 2111, 'n_words': 513}