Skip to content

Instantly share code, notes, and snippets.

@bugparty
Created April 26, 2017 11:01
Show Gist options
  • Save bugparty/7683b2a7fb60310d3e43819dc6951f5d to your computer and use it in GitHub Desktop.
Save bugparty/7683b2a7fb60310d3e43819dc6951f5d to your computer and use it in GitHub Desktop.
how to cal how many bytes do you shrink from png ..etc to webp in android studio
# coding: utf8
#see https://developer.android.com/studio/write/convert-webp.html
from functools import reduce
intBase = 1024
intKB = intBase
intMB = intKB * intBase
intGB = intMB * intBase
def str2int(str):
if str.endswith("bytes"):
return int(str[:-6])
elif str.endswith("KB"):
return int(float(str[:-3]) * intKB)
elif str.endswith("MB"):
return int(float(str[-3]) * intMB)
else:
raise AssertionError("input format unexpected")
f = open("log.txt", encoding="utf8")
lines = map(lambda str: str.strip(), f.readlines())
//下午 means am, 下午 means pm, if you are using english, replace with your own
lines = filter( lambda str: (str.startswith("下午")
or str.startswith("上午"))
and str[-5:] == 'saved',lines)
lines = map(lambda str: str[7:][:-6],lines)
lines = map(str2int, lines)
bytes_count = reduce(lambda y,x:y+x, lines, 0)
def bytesPrinter(amountInbytes):
result = ''
if (amountInbytes > intGB):
l,d = (amountInbytes//intGB, amountInbytes%intGB)
if l > 0:
result+=str(l)+"GB"
amountInbytes = d
if amountInbytes > intMB:
l,d = (amountInbytes//intMB, amountInbytes%intMB)
if l > 0:
result+=str(l)+"MB"
amountInbytes = d
if amountInbytes > intKB:
l,d = (amountInbytes//intKB, amountInbytes%intKB)
if l > 0:
result+=str(l)+"KB"
amountInbytes = d
if amountInbytes > 0:
result+=str(amountInbytes)+"bytes"
return result
print("reduced amount is :", bytesPrinter(bytes_count))
f.close()
#I copied it from Android Studio messages tab
下午2:40 66.6 KB saved
下午2:41 77.7 KB saved
下午2:41 1.3 KB saved
下午2:42 1.3 KB saved
下午2:42 1.2 KB saved
下午2:44 66.6 KB saved
下午2:45 1.4 KB saved
下午2:46 1.2 KB saved
下午2:46 0 files were converted
1 9-patch files were skipped
下午2:47 29.5 KB saved
下午2:47 2.9 KB saved
下午2:48 1.4 KB saved
下午2:48 959 bytes saved
下午2:48 1.4 KB saved
下午2:48 1.2 KB saved
下午2:49 1.3 KB saved
下午2:49 1.9 KB saved
下午2:49 1.3 KB saved
下午2:50 1.1 KB saved
下午2:50 1.2 KB saved
下午2:51 605 bytes saved
下午2:51 7.6 KB saved
下午2:51 1008 bytes saved
下午2:51 2.5 KB saved
下午2:51 462 bytes saved
下午2:51 1.2 KB saved
下午2:51 155.5 KB saved
下午2:52 5.3 KB saved
下午2:52 6.5 KB saved
下午2:52 850 bytes saved
下午2:52 4.3 KB saved
下午2:53 3.1 KB saved
下午2:53 1.3 KB saved
下午2:54 3.2 KB saved
下午2:55 1.4 KB saved
下午2:55 2.8 KB saved
下午2:55 1.4 KB saved
下午2:55 0 files were converted
1 9-patch files were skipped
下午2:55 16 files were converted
19.7 KB saved
下午2:56 3 files were converted
2.9 KB saved
下午2:56 66.3 KB saved
下午2:56 866 bytes saved
下午2:57 12 files were converted
9.6 KB saved
下午2:57 33.0 KB saved
下午2:58 8 files were converted
5.2 KB saved
下午2:58 1.9 KB saved
下午2:58 58.2 KB saved
下午3:00 138.4 KB saved
下午3:01 24 files were converted
26.3 KB saved
下午3:01 580 bytes saved
下午3:01 14.6 KB saved
下午3:02 2.3 KB saved
下午3:02 12.2 KB saved
下午3:02 12.3 KB saved
下午3:02 194 bytes saved
下午3:03 9.0 KB saved
下午3:03 11.7 KB saved
下午3:03 10.6 KB saved
下午3:03 66.6 KB saved
下午3:04 617 bytes saved
下午3:04 62.3 KB saved
下午3:05 1.1 KB saved
下午3:05 18.1 KB saved
下午3:05 18.3 KB saved
下午3:05 709 bytes saved
下午3:06 1.5 KB saved
下午3:06 1.8 KB saved
下午3:06 2.3 KB saved
下午3:06 1.3 KB saved
下午3:07 2.0 KB saved
下午3:07 0 files were converted
0 bytes saved
1 launcher icons were skipped
下午3:08 5.1 KB saved
下午3:08 62 bytes saved
下午3:09 22.8 KB saved
下午3:09 0 files were converted
1 9-patch files were skipped
下午3:09 438 bytes saved
下午3:09 95 bytes saved
下午3:09 85 bytes saved
下午3:10 962 bytes saved
下午3:10 624 bytes saved
下午3:10 1.1 KB saved
下午3:10 933 bytes saved
下午3:10 66 bytes saved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment