def category_read_main():
    finish = True
    rows = db_zoom.db_get_g(db_sql.sql_zoom_cate_read_get, ())
    i_t = len(rows)
    i = 0
    for row in rows:
        i = i + 1
        print '%d of %d'%(i, i_t)
        finish = False
        cate_name = row[0]
        cate_path = row[1]
        cate_param = row[2]
        category_read(cate_name, cate_path, cate_param)
        #break
    return finish
def app_read_main():
    finish = True
    rows = db_zoom.db_get_g(db_sql.sql_zoom_app_get, ())
    i_t = len(rows)
    i = 0
    for row in rows:
        i = i + 1
        print '%d of %d'%(i, i_t), 
        finish = False
        app_name = row[0]
        app_path = row[1]
        app_id = row[2]
        app_read_status = row[3]
        url = app_path.replace('.html', '_download.html').strip()
        #url = app_path.replace('.html', '_download.html?nav=halloween').strip()
        print '** zoom app %s **'%(url)
        status, body = zoom_http_get(url)
        if status == 404:
            print '== 404'
            db_zoom.db_execute_g(db_sql.sql_zoom_app_update, ('', app_path, ))
            continue
        if status != 200:
            print 'exception'
            continue
        soup = BeautifulSoup(body)
        if soup.body.text.strip().find('Access not allowed. If you think this is an error, please contact us at [email protected]') > 0:
            raise Exception('Access not allowed. If you think this is an error, please contact us at [email protected]')
        ### from here
        app_id = None
        divs_fa = soup.find_all(name='span', attrs={'class':'package'})
        for divs_f in divs_fa:
            app_id = divs_f.text.replace('Package ', '').strip()
            print app_id
            db_zoom.db_execute_g(db_sql.sql_app_insert, (app_id, ))
        db_zoom.db_execute_g(db_sql.sql_zoom_app_update, (app_id, app_path))
        util.sleep_i(10)
    return finish