import argparse
import math
import requests
import sys
import time
import types

try:
    import xml.etree.cElementTree as ET
except ImportError:
    import xml.etree.ElementTree as ET

URL_APPLE = 'http://localhost:5001/apple/'
URL_GOOGLE = 'http://localhost:5001/google/'

def find(args):
    ns = {'ss': 'urn:schemas-microsoft-com:office:spreadsheet'}
    tree = ET.ElementTree(file=args.xml)

    total_bundleid = 0
    total_not_found = 0
    total_err = 0
    d = tree.find('ss:Worksheet/ss:Table/ss:Row/ss:Cell/ss:Data', ns)
    for elem in tree.iterfind('ss:Worksheet/ss:Table/ss:Row', ns):
        for data in elem.iterfind('ss:Cell/ss:Data', ns):
            text = data.text
            not_access_api = False
            t1 = time.time()
            if type(text) is types.StringType and not text.isdigit():
                text = text.lower()
                total_bundleid += 1
                try:
                    r = requests.get(URL_APPLE + text, timeout=10)
                except Exception:
                    time.sleep(1)
                    continue
                r_map = r.json()
                if 'not_access_apple_api' in r_map:
                    not_access_api = True
                if 'err' in r_map or r_map[text] == "not found":
                    try:
                        r = requests.get(URL_GOOGLE + text, timeout=10)
                    except Exception:
                        continue
                print r.text

                if text in r.json() and r.json()[text] == "not found":
                    total_not_found += 1

                if 'err' in r.json():
                    total_err += 1

                diff = time.time() - t1 - 3;
                #if diff < 0 and not not_access_api:
                #    time.sleep(math.ceil(-diff))

    print 'total: ' + str(total_bundleid)
    print 'total "not found": ' + str(total_not_found)
    print 'total "errors": ' + str(total_err)



def main():
    project_name = 'client'

    parser = argparse.ArgumentParser(prog=project_name)
    parser.add_argument('-x', '--xml', default='./list.xml',help="specify a bunldID list in xml format.", required=True)

    args = parser.parse_args()

    find(args)

if __name__ == '__main__':

    main()

@@ -271,24 +271,837 @@
 e/'%0A
-%0Adef find(args):
+URL_NOT_FOUND = 'http://localhost:5001/notfound/'%0A%0Adef refind_not_found():%0A    print 'find bundleId from Notfound table first...'%0A    r = requests.post(URL_NOT_FOUND)%0A    l = r.json()%0A%0A    for k in l:%0A        try:%0A            r = requests.get(URL_APPLE + k, timeout=10)%0A        except Exception:%0A            time.sleep(1)%0A            continue%0A%0A        r_map = r.json()%0A        if 'err' in r_map or r_map%5Bk%5D == %22not found%22:%0A            try:%0A                r = requests.get(URL_GOOGLE + k, timeout=10)%0A            except Exception:%0A                continue%0A%0A        r_map = r.json()%0A        if 'err' in r_map or r_map%5Bk%5D == %22not found%22:%0A            print r.text%0A            continue%0A%0A        r = requests.delete(URL_APPLE + k)%0A        print r.text%0A%0A%0Adef find(args):%0A    print 'find bundleId from xml file: %7B0%7D...'.format(args.xml)
 %0A   
@@ -2246,37 +2246,8 @@
 inue
-%0A                print r.text
 %0A%0A  
@@ -2351,24 +2351,84 @@
 t_found += 1
+%0A                    r = requests.post(URL_NOT_FOUND + text)
 %0A%0A          
@@ -2491,16 +2491,46 @@
 r += 1%0A%0A
+                print r.text%0A%0A
         
@@ -3063,24 +3063,65 @@
 rse_args()%0A%0A
+    refind_not_found()%0A    time.sleep(5)%0A
     find(arg

update client.py, find bundleID in not_found_app table first.