Пример #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
Пример #2
0
			log ('Successfully downloaded ' + snap['id'])

			try:
				with open(media_path, 'w') as f:
					log ('Writing to cache from ' + snap['id'])
					f.write(media)
			except TypeError as e:
				log ('Error saving file: {0}'.format(e))

			queue = glob.glob('queue/*')
			if len(queue):
				queue_file = queue[0]
				log ('Uploading item from {0}'.format(queue_file))
				# possible that the media did not upload
				media_id = s.upload(Snapchat.MEDIA_IMAGE, queue_file)
				log ('Sending {0}'.format(media_id))
				# possible that the media did not send
				s.send(media_id, sender)
				log ('Deleting ' + queue_file)
				os.remove(queue_file)

			try:
				with open('queue/' + snap['id'], 'w') as f:
					log ('Writing to queue from ' + snap['id'])
					f.write(media)
			except TypeError as e:
				log ('Error saving file: {0}'.format(e))

except KeyboardInterrupt:
	s.logout()
	log('Logging out')