def main(): arguments = docopt(__doc__) quiet = arguments['--quiet'] username = arguments['--username'] if arguments['--password'] is None: password = getpass('Password:'******'--password'] path = arguments['<path>'] if not os.path.isdir(path): print('No such directory: {0}'.format(arguments['<path>'])) sys.exit(1) s = Snapchat() if not s.login(username, password).get('logged'): print('Invalid username or password') sys.exit(1) for snap in s.get_friend_stories(): 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): continue data = s.get_story_blob(snap['media_id'], base64.b64decode(snap['media_key']), base64.b64decode(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))
def fetch(): try: s = pysnap.Snapchat() if not s.login(username, password)['updates_response'].get('logged'): irc.reply('Invalid username or password.') return for snap in s.get_snaps(): # media_type 3 is friend requests. status 2 means it is read if snap['media_type'] == 3 or snap['status'] == 2: continue #boop = 'ID: {0}\tMedia id: {1}\tMedia type: {2}\tTime: {3}\tSender: {4}\tRecipient: {5}\tStatus: {6}\tScreenshot count: {7}\tSent: {8}\tOpened: {9}'.format(snap['id'], snap['media_id'], snap['media_type'], snap['time'], snap['sender'], snap['recipient'], snap['status'], snap['screenshot_count'], snap['sent'], snap['opened']) #self.log.info(str(boop)) sent = time.strftime( '%Y-%m-%dT%H:%M', time.gmtime(int(str(snap['sent'])[:-3]))) filename = '{2}_{0}.{1}'.format( snap['sender'], pysnap.get_file_extension(snap['media_type']), sent) abspath = os.path.abspath(os.path.join( localpath, filename)) if os.path.isfile(abspath): continue data = s.get_blob(snap['id']) if data is None: continue with open(abspath, 'wb') as f: f.write(data) irc.reply('[{0}] New snap from: {1}! - {2}{3}'.format( username, snap['sender'], address, filename)) if markasread: s.mark_viewed(snap['id']) except Exception as e: self.log.error('SupySnap: ' + str(e))
def process_snap(s, snap, path, quiet=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 Snap to path: {0}'.format(abspath)) if is_zipfile(abspath): zipped_snap = ZipFile(abspath) unzip_dir = os.path.join(path, '{0}_{1}'.format(snap['sender'], snap['id'])) zipped_snap.extractall(unzip_dir) if not quiet: print('Unzipped {0} to {1}'.format(filename, unzip_dir)) postToBrunonia(filename, s) else: postToBrunonia(abspath, s)
def main(): arguments = docopt(__doc__) quiet = arguments['--quiet'] username = arguments['--username'] if arguments['--password'] is None: password = getpass('Password:'******'--password'] #path = arguments['<path>'] path = "snaps" if not os.path.isdir(path): print('No such directory: {0}'.format(arguments['<path>'])) sys.exit(1) s = Snapchat() if not s.login(username, password).get('logged'): print('Invalid username or password') sys.exit(1) for snap in s.get_snaps(): 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): continue data = s.get_blob(snap['id']) if data is None: continue with open(abspath, 'wb') as f: f.write(data) # If we successfully mark this as viewed, go ahead and email it. if s.mark_viewed(snap['id']): # Setup email message msg = MIMEMultipart() msg['From'] = "Snapchat" msg['To'] = email_toaddrs msg['Subject'] = "Snapchat from %s" % snap['sender'] body = "You have received a new snapchat from %s" % snap['sender'] msg.attach(MIMEText(body, "plain")) msg.attach(MIMEImage(data)) # The actual mail send if not quiet: print("Sending mail!") server = smtplib.SMTP() server.connect('mailhub.iastate.edu', 25) server.ehlo() server.starttls() #server.login('username', 'password') server.sendmail(email_fromaddr, email_toaddrs, msg.as_string()) server.quit() if not quiet: print('Saved: {0}'.format(abspath))
def main(): arguments = docopt(__doc__) quiet = arguments['--quiet'] username = arguments['--username'] if arguments['--password'] is None: password = getpass('Password:'******'--password'] path = arguments['<path>'] if not os.path.isdir(path): print('No such directory: {0}'.format(arguments['<path>'])) sys.exit(1) s = Snapchat() if not s.login(username, password).get('logged'): print('Invalid username or password') sys.exit(1) while True: try: for snap in s.get_snaps(): 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): continue data = s.get_blob(snap['id']) if data is None: continue with open(abspath, 'wb') as f: f.write(data) if not quiet: print('Saved: {0}'.format(abspath)) time.sleep(5*60) except HTTPError: # v pripade ze se prihlasim na snapchatu na mobilu tak me to odhlasi tady print('logged of, waiting for another five minutes') time.sleep(5*60) del s s = Snapchat() if not s.login(username, password).get('logged'): print('Invalid username or password') sys.exit(1)
def process_snap(s, snap, path, quiet=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): zipped_snap = ZipFile(abspath) unzip_dir = os.path.join(path, '{0}_{1}'.format(snap['sender'], snap['id'])) zipped_snap.extractall(unzip_dir) if not quiet: print('Unzipped {0} to {1}'.format(filename, unzip_dir))
def __init__(self, **opts): self.uploaded = False self.duration = opts['duration'] self.media_type = opts['media_type'] if 'sender' in opts: self.sender = opts['sender'] self.snap_id = opts['snap_id'] self.from_me = False else: self.snap_id = uuid.uuid4().hex self.from_me = True if 'data' in opts: self.media_type = opts['media_type'] suffix = "." + get_file_extension(opts['media_type']) self.file = create_temporary_file(suffix) if (self.media_type is MEDIA_TYPE_VIDEO) or ( self.media_type is MEDIA_TYPE_VIDEO_NOAUDIO) or ( opts['data'][0:2] == b'\x00\x00'): self.file.write(opts['data']) self.file.flush() else: print self.media_type #, opts try: image = Image.open(StringIO(opts['data'])) resize_image(image, self.file.name) except Exception as e: print "Unable to process image " + str(e) else: path = opts['path'] self.file = open(path)
def process_snap(snap, s=snapchat, path='app/static/snap/', quiet=False): snap = snap['story'] filename = '{0}.{1}'.format(snap['media_id'], get_file_extension(snap['media_type'])) snap['filename'] = 'snap/' + filename snap['mediatext'] = False abspath = os.path.abspath(os.path.join(path, filename)) if os.path.isdir(path + snap['id']): snap['mediatext'] = True snap['filename'] = 'snap/{}/media.mp4'.format(snap['id']) return snap if os.path.isfile(abspath): return snap data = s.get_blob(snap['id']) if data is None: return snap with open(abspath, 'wb') as f: f.write(data) if not quiet: print('Saved: {0}'.format(abspath)) if is_zipfile(abspath): zipped_snap = ZipFile(abspath) unzip_dir = os.path.join(path, '{}'.format(snap['id'])) zipped_snap.extractall(unzip_dir) if not quiet: print('Unzipped {0} to {1}'.format(filename, unzip_dir)) for f in glob('{}{}/media*'.format(path, snap['id'])): os.rename(f, '{}{}/media.mp4'.format(path, snap['id'])) for f in glob('{}{}/overlay*'.format(path, snap['id'])): os.rename(f, '{}{}/overlay.png'.format(path, snap['id'])) snap['mediatext'] = True snap['filename'] = 'snap/{}/media.mp4'.format(snap['id']) return snap
def __init__(self, **opts): self.uploaded = False self.duration = opts['duration'] self.media_type = opts['media_type'] if 'sender' in opts: self.sender = opts['sender'] self.snap_id = opts['snap_id'] self.from_me = False else: self.snap_id = uuid.uuid4().hex self.from_me = True if 'data' in opts: self.media_type = opts['media_type'] suffix = "." + get_file_extension(opts['media_type']) self.file = create_temporary_file(suffix) if (self.media_type is MEDIA_TYPE_VIDEO) or (self.media_type is MEDIA_TYPE_VIDEO_NOAUDIO) or (opts['data'][0:2] == b'\x00\x00'): self.file.write(opts['data']) self.file.flush() else: print self.media_type#, opts try: image = Image.open(StringIO(opts['data'])) resize_image(image, self.file.name) except Exception as e: print "Unable to process image "+str(e) else: path = opts['path'] self.file = open(path)
def sendSnapToStory(s, snap, path, saveImg,verbose): 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): return data = s.get_blob(snap['id']) if data is None: return if verbose: print('Valid, moving forward') print('Marking snap viewed') s.mark_viewed(snap['id']) with open(abspath, 'wb') as f: f.write(data) if verbose: print('Sending snap to story') s.send_to_story(s.upload(abspath),5,get_media_type(data)) if not saveImg: if verbose: print('Removing tmp file') os.remove(abspath) return
def test(self, irc, msg, args, channel): """[channel] Manually trigger SupySnap.""" seconds = self.registryValue('interval', channel) username = self.registryValue('username', channel) password = self.registryValue('password', channel) address = self.registryValue('address', channel) localpath = self.registryValue('localpath', channel) markasread = self.registryValue('markasread', channel) if not username or username == '': irc.error('No username entered.') return if not password or password == '': irc.error('No password entered.') return if not address or address == '': irc.error('No address entered.') return if not localpath or localpath == '': irc.error('No local path entered.') return if not os.path.isdir(localpath): os.makedirs(localpath) name = self._name(channel) self.log.info('Creating Snapchat object') s = pysnap.Snapchat() self.log.info('Attempting to log in with username and password ' + username + '/' + password) login = s.login(username, password) self.log.info(str(login)) if not login['updates_response'].get('logged'): irc.reply('Invalid username or password.') return self.log.info('Login successful.') replies = 0 for snap in s.get_snaps(): self.log.info('Looping through snaps! - ' + str(snap)) # media_type 3 is friend requests. status 2 means it is read if snap['media_type'] == 3 or snap['status'] == 2: continue #boop = 'ID: {0}\tMedia id: {1}\tMedia type: {2}\tTime: {3}\tSender: {4}\tRecipient: {5}\tStatus: {6}\tScreenshot count: {7}\tSent: {8}\tOpened: {9}'.format(snap['id'], snap['media_id'], snap['media_type'], snap['time'], snap['sender'], snap['recipient'], snap['status'], snap['screenshot_count'], snap['sent'], snap['opened']) #self.log.info(str(boop)) sent = time.strftime('%Y-%m-%dT%H:%M', time.gmtime(int(str(snap['sent'])[:-3]))) filename = '{2}_{0}.{1}'.format( snap['sender'], pysnap.get_file_extension(snap['media_type']), sent) abspath = os.path.abspath(os.path.join(localpath, filename)) if os.path.isfile(abspath): continue data = s.get_blob(snap['id']) if data is None: continue with open(abspath, 'wb') as f: f.write(data) irc.reply('[{0}] New snap from: {1}! - {2}{3}'.format( username, snap['sender'], address, filename)) replies += 1 if markasread: s.mark_viewed(snap['id']) if replies == 0: irc.reply('No new snaps.')