aboutsummaryrefslogtreecommitdiff
path: root/autoJPEG.py
diff options
context:
space:
mode:
authorache <ache@ache.one>2021-09-09 08:37:25 +0200
committerache <ache@ache.one>2021-09-09 08:37:25 +0200
commit91c8bd9405c612f454fea1c13b3d5d517a145159 (patch)
tree5bd0d922fa058f2ed068beec1c113a0eb77e74d1 /autoJPEG.py
parentautoWall: Delete current wallpaper (diff)
autoJPEG: Init
Diffstat (limited to 'autoJPEG.py')
-rw-r--r--autoJPEG.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/autoJPEG.py b/autoJPEG.py
new file mode 100644
index 0000000..6297dac
--- /dev/null
+++ b/autoJPEG.py
@@ -0,0 +1,51 @@
+from os import listdir
+from os.path import isfile, join
+
+
+ORIG_FILES = '/var/spool/sms/inbox/'
+DEST_FILES = '/var/spool/sms/mms/'
+
+JPEG_TAG = b'\xFF\xD8\xFF\xE0\x00\x10JFIF'
+
+
+def listMMS():
+ return sorted([f for f in listdir(ORIG_FILES) if
+ isfile(join(ORIG_FILES, f)) and f.endswith('.bin')])[::-1]
+
+def listNewMMS():
+ mmss = listMMS()
+
+ listFile = [f[:f.rfind('_')] for f in listdir(DEST_FILES) if
+ isfile(join(DEST_FILES, f)) and f.rfind('_') > 0]
+
+ for mms in mmss:
+ mmsTitle = mms[:-4]
+ if mmsTitle not in listFile:
+ yield mms
+
+
+def extractJPG(mmsFile, name):
+ i = 1
+
+ fileOut = None
+
+ with open('mmsFile', 'rb') as f:
+ for line in f:
+ if JPEG_TAG in line:
+ index = line.index(JPEG_TAG)
+ if fileOut is not None:
+ fileOut.write(line[:index])
+ fileOut.close()
+ fileOut = open(DEST_FILES + name + '_' + str(i) + '.jpg', 'wb')
+ i += 1
+ fileOut.write(line[index:])
+ else:
+ if fileOut is not None:
+ fileOut.write(line)
+
+
+if __name__ == "__main__":
+ for f in listNewMMS():
+ print(f)
+ extractJPG('./mmsFile3', 'romane2')
+ # listMMS = listMMS():