|
| 1 | +#!/usr/bin/env python2 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +# $File: cmdtool.py |
| 4 | +# $Date: Sat Apr 06 15:42:43 2013 +0800 |
| 5 | + |
| 6 | +# |
| 7 | +# This program is free software. It comes without any warranty, to |
| 8 | +# the extent permitted by applicable law. You can redistribute it |
| 9 | +# and/or modify it under the terms of the Do What The Fuck You Want |
| 10 | +# To Public License, Version 2, as published by Sam Hocevar. See |
| 11 | +# http://sam.zoy.org/wtfpl/COPYING (copied as below) for more details. |
| 12 | +# |
| 13 | +# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
| 14 | +# Version 2, December 2004 |
| 15 | +# |
| 16 | +# Copyright (C) 2004 Sam Hocevar <[email protected]> |
| 17 | +# |
| 18 | +# Everyone is permitted to copy and distribute verbatim or modified |
| 19 | +# copies of this license document, and changing it is allowed as long |
| 20 | +# as the name is changed. |
| 21 | +# |
| 22 | +# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
| 23 | +# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
| 24 | +# |
| 25 | +# 0. You just DO WHAT THE FUCK YOU WANT TO. |
| 26 | + |
| 27 | +def init(): |
| 28 | + import sys |
| 29 | + import os |
| 30 | + import os.path |
| 31 | + if sys.version_info.major != 2: |
| 32 | + sys.exit('Python 2 is required to run this program') |
| 33 | + |
| 34 | + fdir = None |
| 35 | + if hasattr(sys, "frozen") and \ |
| 36 | + sys.frozen in ("windows_exe", "console_exe"): |
| 37 | + fdir = os.path.dirname(os.path.abspath(sys.executable)) |
| 38 | + sys.path.append(fdir) |
| 39 | + fdir = os.path.join(fdir, '..') |
| 40 | + else: |
| 41 | + fdir = os.path.dirname(__file__) |
| 42 | + |
| 43 | + with open(os.path.join(fdir, 'apikey.cfg')) as f: |
| 44 | + exec(f.read()) |
| 45 | + |
| 46 | + srv = locals().get('SERVER') |
| 47 | + from facepp import API |
| 48 | + return API(API_KEY, API_SECRET, srv = srv) |
| 49 | + |
| 50 | +api = init() |
| 51 | + |
| 52 | +from facepp import API, File |
| 53 | + |
| 54 | +del init |
| 55 | + |
| 56 | +def _run(): |
| 57 | + global _run |
| 58 | + _run = lambda: None |
| 59 | + |
| 60 | + msg = """ |
| 61 | +=================================================== |
| 62 | +Welcome to Face++ Interactive Shell! |
| 63 | +Here, you can explore and play with Face++ APIs :) |
| 64 | +--------------------------------------------------- |
| 65 | +Getting Started: |
| 66 | + 0. Register a user and API key on http://www.faceplusplus.com |
| 67 | + 1. Write your API key/secret in apikey.cfg |
| 68 | + 2. Start this interactive shell and try various APIs |
| 69 | + For example, to find all faces in a local image file, just type: |
| 70 | + api.detection.detect(img = File(r'<path to the image file>')) |
| 71 | +
|
| 72 | +Enjoy! |
| 73 | +""" |
| 74 | + |
| 75 | + try: |
| 76 | + from IPython import embed |
| 77 | + embed(banner2 = msg) |
| 78 | + except ImportError: |
| 79 | + import code |
| 80 | + code.interact(msg, local = globals()) |
| 81 | + |
| 82 | + |
| 83 | +if __name__ == '__main__': |
| 84 | + _run() |
0 commit comments