Skip to content

Instantly share code, notes, and snippets.

@mahdizojaji
Last active July 20, 2019 00:42
Show Gist options
  • Save mahdizojaji/1255ecbb5e0340b30214e0010c464776 to your computer and use it in GitHub Desktop.
Save mahdizojaji/1255ecbb5e0340b30214e0010c464776 to your computer and use it in GitHub Desktop.
#!/usr/bin/python2
import requests
import os
import sys
import random
import string
FILTERS = [
"smile",
"smile_2",
"hot",
"old",
"young",
"female",
"male"
]
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('https://node-01.faceapp.io/api/v2.3/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('https://node-01.faceapp.io/api/v2.3/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