From be337ae9e1c82a02f2ea71e795edad8646825468 Mon Sep 17 00:00:00 2001 From: N07070 Date: Tue, 24 Feb 2015 13:14:11 +0100 Subject: [PATCH 1/2] Update utils.py Added a way to save all the images in a snapbot_saves folder. It creates it if it doesn't exist, then comes back to the original folder. --- snapchat_bots/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/snapchat_bots/utils.py b/snapchat_bots/utils.py index 1425804..c92bee7 100755 --- a/snapchat_bots/utils.py +++ b/snapchat_bots/utils.py @@ -1,4 +1,4 @@ -import tempfile, mimetypes, datetime, subprocess, re, math +import tempfile, mimetypes, datetime, subprocess, re, math, os from PIL import Image from constants import MEDIA_TYPE_IMAGE, MEDIA_TYPE_VIDEO, MEDIA_TYPE_VIDEO_WITHOUT_AUDIO, SNAP_IMAGE_DIMENSIONS @@ -13,12 +13,17 @@ def create_temporary_file(suffix): def save_snap(snap): now = datetime.datetime.now() + before_folder = os.getcwd() + if not os.path.exists("snapbot_saves"): + os.makedirs("snapbot_saves") + os.chdir("snapbot_saves") filename = '%s-%s.%s.%s-%s:%s:%s%s' % (snap.sender, now.month, now.day, now.year, now.hour, now.minute, now.second, snap.file.name[-4:]) with open(filename, 'wb') as f: data = snap.file.file.read(8192) while data: f.write(data) data = snap.file.file.read(8192) + os.chdir(before_folder) def is_video_file(path): return mimetypes.guess_type(path)[0].startswith("video") From 71112bc86291538020d0440923c552f07eb4c986 Mon Sep 17 00:00:00 2001 From: N07070 Date: Wed, 25 Feb 2015 03:50:16 +0100 Subject: [PATCH 2/2] Update utils.py Added an argument to the save_snap(), to be the name of the directory in which it will be saved. --- snapchat_bots/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/snapchat_bots/utils.py b/snapchat_bots/utils.py index c92bee7..a172908 100755 --- a/snapchat_bots/utils.py +++ b/snapchat_bots/utils.py @@ -11,12 +11,12 @@ def file_extension_for_type(media_type): def create_temporary_file(suffix): return tempfile.NamedTemporaryFile(suffix=suffix, delete=False) -def save_snap(snap): +def save_snap(snap,dir_name): now = datetime.datetime.now() before_folder = os.getcwd() - if not os.path.exists("snapbot_saves"): - os.makedirs("snapbot_saves") - os.chdir("snapbot_saves") + if not os.path.exists(dir_name): + os.makedirs(dir_name) + os.chdir(dir_name) filename = '%s-%s.%s.%s-%s:%s:%s%s' % (snap.sender, now.month, now.day, now.year, now.hour, now.minute, now.second, snap.file.name[-4:]) with open(filename, 'wb') as f: data = snap.file.file.read(8192)