Exemplo n.º 1
0
def main():
		try:
			os.makedirs(DOWNLOAD_PATH)
		except OSError as exception:
			if exception.errno != errno.EEXIST:
				raise

		for attempt in range(0,MAX_FAILURES):
			try:
				while True:
					#Loop is less fragile with a new session generated every iteration
					snap_user = Snapchat(USERNAME, PASSWORD)
					
					#Accept every new friend request
					accept_friend_requests(snap_user)
					
					#Download all new snaps
					download_new_snaps(snap_user)
					
					#Upload and potentially delete data
					process_approved_snaps(snap_user)

					#Potentially delete data
					process_unapproved_snaps()

					#Mark all snaps as read		
					snap_user.clear_feed()

					#Logout
					snap_user.logout()

					#Block the loop for a random number of seconds to avoid upsetting Snapchat
					sleep_random()
			except:
				print "\nEXECUTION ENDED IN ERROR\n"
				if attempt < MAX_FAILURES:
					print "Restarting AutoSnapper: %d Attempts Remaining\n" % (MAX_FAILURES - attempt - 1)
				else:
					print "Max Attempts Reached\n"
					raise
Exemplo n.º 2
0
 def __init__(self):
     self.window = Tk()
     self.main_window_init()
     self.client = Snapchat()
     self.start()
Exemplo n.º 3
0
def get_images(request):
    s = Snapchat()
    s.login('YOUR_SNAPCHAT_USERNAME', 'YOUR_SNAPCHAT_PASSWORD')
    download_snaps(s)
    x = get_newest_snaps()
    return JsonResponse({'result': x})
Exemplo n.º 4
0
    path = PATH + filename
    with open(path, 'wb') as fout:
        fout.write(result)
    return True


def download_snaps(s):
    """Download all snaps that haven't already been downloaded."""

    existing = get_downloaded()

    snaps = s.get_snaps()
    for snap in snaps:
        id = snap['id']
        if id[-1] == 's' or id in existing:
            print 'Skipping:', id
            continue

        result = download(s, snap)

        if not result:
            print 'FAILED:', id
        else:
            print 'Downloaded:', id


if __name__ == '__main__':
    s = Snapchat()
    s.login('USERNAME', 'PASSWORD')
    download_snaps(s)
Exemplo n.º 5
0
from snapchat import Snapchat
import getpass
from pprint import pprint

# Enter your snapchat credentials (they will be used securely)
USERNAME = #Your Snapchat username
PASSWORD = #Your Snapchat password


TARGET = #Some other Snapchat username
SAVE_TO = "downloaded_snap"
UPLOAD_FROM = #some local file

s = Snapchat(USERNAME, PASSWORD)

# Add a friend by username
s.add_friend(TARGET)


# Get a list (meta-data) of your recent snaps
snap_info = s.get_snaps()
for snap in snap_info:
	print snap
	print "\n\n"


# Download your most recently received snap
# This will fail if you have already opened the snap
snap_id = snap_info[0]['id']
s.download_media(snap_id, SAVE_TO)
Exemplo n.º 6
0
def cli():
    clear()
    s = Snapchat()
    username = raw_input('Please enter username: '******'win'):
        password = getpass.getpass('Please enter password: '******'Please enter password (empty for token entry): ')
    if password == '':
        auth_token = raw_input('Please enter auth token: ')
        if not s.login_token(username, auth_token):
            raw_input('Invalid username/auth token combo')
            clear()
            exit()
    else:
        if not s.login(username, password):
            raw_input('Invalid username/password combo')
            clear()
            exit()

    pynotify.init("pySnap")
    queue = Queue.Queue()
    bg_scheduler = sched.scheduler(time.time, time.sleep)
    bg_scheduler.enter(300, 1, check_snaps, (s, bg_scheduler, queue))
    bg_check = threading.Thread(target=bg_scheduler.run)
    bg_check.setDaemon(True)
    bg_check.start()
    snaps = s.get_snaps()
    user_input = None
    functions = {
        'R': lambda: s.get_snaps(),
        'S': send
    }
    clear()
    while user_input != 'X':
        print 'Welcome to Snapchat!'
        print 'Logged in as {0} (token {1})'.format(username, s.auth_token)
        print
        print '{0} pending snaps:'.format(len(snaps))
        num = 1
        for snap in snaps:
            #print snap
            #print snap['media_type']
            dt = datetime.fromtimestamp(snap['sent'] / 1000)
            ext = s.media_type(snap['media_type'], binary=False)
            timestamp = str(snap['sent']).replace(':', '-')
            filename = '{}+{}+{}.{}'.format(timestamp, snap['sender'], snap['id'], ext)
            path = PATH + filename

            # check if file already exists so we don't need to redownload
            '''
            if not os.path.isfile(path):
                data = s.get_snap(snap['id'])
                with open(path, 'wb') as outfile:
                    outfile.write(data)
            '''

            snap['path'] = path
            print '[{0}] Snap from {1} ({2}s, Sent {3})'.format(num, snap['sender'], snap['time'], dt)
            num += 1
        print
        print '[R] - refresh snaps'
        print '[S] - send a snap'
        print '[X] - exit'
        user_input = raw_input('Enter an option: ').upper()
        num_input = int(user_input) if user_input.isdigit() else None
        if len(snaps) >= num_input > 0:
            dt = datetime.fromtimestamp(snap['sent'] / 1000)
            ext = s.media_type(snap['media_type'], binary=False)
            timestamp = str(snap['sent']).replace(':', '-')
            filename = '{}+{}+{}.{}'.format(timestamp, snap['sender'], snap['id'], ext)
            path = PATH + filename
            snap = snaps[num_input - 1]
            if not os.path.isfile(path):
                data = s.get_snap(snap['id'])
                with open(path, 'wb') as outfile:
                    outfile.write(data)

            snap['path'] = path
            file_path = snap['path']

            # open /dev/null or equivalent so we can redirect stdout/stderr to it
            nullfile = open(os.devnull, 'w')

            # cross-platform method to open a media file
            p = None
            scheduler = sched.scheduler(time.time, time.sleep)
#            try:
            if True:
                if sys.platform.startswith('linux'):
                    p = subprocess.Popen(['xdg-open', file_path], stdout=nullfile, stderr=nullfile, preexec_fn=os.setsid)
                elif sys.platform.startswith('darwin'):
                    p = subprocess.Popen(['open', file_path], stdout=nullfile, stderr=nullfile)
                elif sys.platform.startswith('win'):
                    p = subprocess.Popen(['start /WAIT', file_path], stdout=nullfile, stderr=nullfile)
                else:
                    print 'I don\'t recognize your operating system: {0}'.format(sys.platform)
                scheduler.enter(snap['time'], 1, mark_read, (s, snap, p, queue))
                t = threading.Thread(target=scheduler.run)
                t.start()
#            except:
#                print 'Uh oh, I was unable to open the file.'

        elif user_input in functions:
            if user_input == 'R':
                queue.put(functions[user_input]())
                print 'Refreshed!'
            else:
                functions[user_input](s)
        elif user_input != 'X':
            print 'I don\'t recognize that command.'

        if user_input != 'X':
            raw_input('Press enter to continue...')
            clear()

        if not queue.empty():
            while not queue.empty():
                buf = queue.get()
            new_snaps = []
            for st in buf:
                found = False
                for snap in snaps:
                    if st['id'] == snap['id']:
                        found = True
                        break
                if found == True:
                    new_snaps.append(st)
            for snap in new_snaps:
                title = 'New snap from {0}!'.format(snap['sender'])
                dt = datetime.fromtimestamp(snap['sent'] / 1000)
                message = '{0} seconds, sent {1}'.format(snap['time'], dt)
                notice = pynotify.Notification(title, message)
                notice.show()
    #        snaps = buf 
    sys.exit(0)