-
-
Save reuke/1794fad03fca4e5d5c05d43ab181437d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import requests | |
import os | |
import sys | |
import random | |
import string | |
FILTERS = [ | |
"smile", | |
"smile_2", | |
"hot", | |
"old", | |
"young", | |
"female", | |
"female_2", | |
"makeup", | |
"impression", | |
"bangs", | |
"glasses", | |
"wave", | |
"male", | |
"hipster", | |
"pan", | |
"lion", | |
"hitman", | |
"heisenberg" | |
] | |
def upload_photo(path, filter_name, out_path): | |
deviceID = ''.join(random.choice(string.letters) for i in range(8)) | |
headers = {'User-agent': "FaceApp/1.0.229 (Linux; Android 4.4)", 'X-FaceApp-DeviceID': deviceID} | |
res = requests.post('http://node-01.faceapp.io/api/v2.7/photos', headers=headers, files={'file': open(path, "rb")}) | |
code = res.json().get('code') | |
if not code: | |
print 'Error getting code' | |
sys.exit(1) | |
res2 = requests.get('http://node-01.faceapp.io/api/v2.7/photos/%s/filters/%s?cropped=%s' % (code, filter_name, "1"), headers=headers) | |
if 'x-faceapp-errorcode' in res2.headers: | |
print "Error %s" % res2.headers['x-faceapp-errorcode'] | |
sys.exit(1) | |
open(out_path, 'wb').write(res2.content) | |
def main(): | |
if len(sys.argv) != 4: | |
print 'Usage: python faceapp.py image_path filter out_path' | |
print 'Where filter is one of: %s' % (' '.join(FILTERS)) | |
sys.exit(1) | |
prog, path, filter_name, out_path = sys.argv | |
if filter_name not in FILTERS: | |
print 'Filter should be one of: %s' % (' '.join(FILTERS)) | |
sys.exit(1) | |
path = os.path.abspath(path) | |
if not os.path.exists(path): | |
print 'File %s not found' % path | |
sys.exit(1) | |
upload_photo(path, filter_name, out_path) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment