コード例 #1
0
def get_articles():
    #
    keywords = WEIXIN_CHECK.get_keywords(fs)
    #
    urls = get_urls()
    unquoted_urls = list()
    for each_url in urls:
        unquoted_urls.append(urllib.unquote(each_url))
    #
    res = dict()
    #
    try:
        conn, cur = ADMIN_WEIXIN_CHECK.get_conn_for_mysql_art()
        table = ADMIN_WEIXIN_CHECK.get_table()
        #
        update_sql = "update " + table +" set keywords='%s' where url in (%s)"
        in_clause = ', '.join(list(map(lambda x: '%s', unquoted_urls)))
        update_sql = update_sql % (keywords, in_clause)
        #
        #print update_sql
        cur.execute(update_sql, unquoted_urls)
        #
        cur.close()
        conn.close()
        #
        UTIL.append_result_ok(res)
    except Exception, e:
        #
        UTIL.append_result_error(res, e)
コード例 #2
0
def get_articles():
    #
    sql_where = ADMIN_WEIXIN_CHECK.get_where_from_fs(fs)
    sql_limit = ADMIN_WEIXIN_CHECK.get_limit_from_fs(fs)
    #
    res = dict()
    res["articles"] = list()
    #
    try:
        conn, cur = ADMIN_WEIXIN_CHECK.get_conn_for_mysql_art()
        table = ADMIN_WEIXIN_CHECK.get_table()
        sql_select = "select * from " + table
        #
        sql_select += sql_where
        sql_select += " order by pub_time desc"
        sql_select += sql_limit
        #print sql_select
        #
        cur.execute(sql_select)
        all_data = cur.fetchall()
        for row in all_data:
            temp_row = copy.deepcopy(row)
            #
            res["articles"].append(UTIL.get_dict_in_utf8(temp_row))
        #
        '''
        '''
        cur.close()
        conn.close()
        #
        UTIL.append_result_ok(res)
    except Exception, e:
        #
        UTIL.append_result_error(res, e)
コード例 #3
0
ファイル: api_mysql_art_count.py プロジェクト: TeaEra/CZT_Web
def get_articles():
    #
    sql_where = ADMIN_WEIXIN_CHECK.get_where_from_fs(fs)
    #
    res = dict()
    res["articles"] = list()
    #
    try:
        conn, cur = ADMIN_WEIXIN_CHECK.get_conn_for_mysql_art()
        table = ADMIN_WEIXIN_CHECK.get_table()
        #
        sql_select = "select count(*) as total_num from " + table 
        sql_select += sql_where
        #
        #print sql_where
        #print sql_select
        cur.execute(sql_select)
        all_data = cur.fetchall()
        res["count"] = all_data
        #
        cur.close()
        conn.close()
        #
        UTIL.append_result_ok(res)
    except Exception, e:
        #
        UTIL.append_result_error(res, e)
コード例 #4
0
ファイル: NAVE.py プロジェクト: jonathansan04/Final
 def __init__(self):
     Sprite.__init__(self)
     self.imagenes = [
         UTIL.cargar_imagen('Imagenes/rocket.png'),
         UTIL.cargar_imagen('Imagenes/rocket.png')
     ]
     self.image = self.imagenes[0]
     self.rect = self.image.get_rect()
     self.rect.move_ip(400, 450)
     self.vida = 100
     self.punt = 0.0
コード例 #5
0
def game():
    pygame.init()
    pygame.mixer.init()
    screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
    jugando = True
    pygame.display.set_caption("Galaxy")
    fuente = pygame.font.Font(None, 30)
    background_image = UTIL.cargar_imagen('Imagenes/fondo.jpg')
    pierde_vida = UTIL.cargar_sonido('Sonidos/el-pollo_1.mp3')
    #gana_punt = UTIL.cargar_sonido('Sonidos/misc108.mp3')
    pygame.mouse.set_visible(False)
    temporizador = pygame.time.Clock()
    NAVE = Nave()
    ASTEROIDE = [
        Asteroide((0, 40), 6),
        Asteroide((0, 0), 6),
        Asteroide((50, 100), 4),
        Asteroide((100, 200), 10),
        Asteroide((150, 300), 8),
        Asteroide((200, 70), 20),
        Asteroide((200, 50), 20)
    ]
    while jugando:
        NAVE.update()
        if NAVE.vida <= 0:
            jugando = False
        texto_vida = fuente.render("Vida: " + str(NAVE.vida), 1,
                                   (250, 250, 250))
        for n in ASTEROIDE:
            n.update()
        NAVE.image = NAVE.imagenes[0]
        for n in ASTEROIDE:
            if NAVE.rect.colliderect(n.rect):
                NAVE.image = NAVE.imagenes[1]
                pierde_vida.play()
                NAVE.vida -= 1

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
        screen.blit(background_image, (0, 0))
        screen.blit(NAVE.image, NAVE.rect)
        for n in ASTEROIDE:
            screen.blit(n.image, n.rect)
        screen.blit(texto_vida, (20, 10))
        pygame.display.update()
        pygame.time.delay(10)
        texto_vida = fuente.render("Puntaje: " + str(NAVE.punt), 1,
                                   (250, 250, 250))
        screen.blit(texto_vida, (400, 10))
        pygame.display.update()
        pygame.time.delay(10)
コード例 #6
0
def get_articles():
    #
    type = get_type()
    #
    # The following convertion is important!!!
    type = UTIL.get_str_in_gbk(type)
    #
    res = dict()
    res['articles'] = list()
    #
    try:
        conn = \
            MySQLdb.connect(
                host = host, 
                user = user, 
                passwd = pwd, 
                db = db, 
                charset = charset,
                cursorclass = MySQLdb.cursors.DictCursor
            )
        cur = conn.cursor()
        fields = "*"
        select_sql = \
                "select " + fields \
                + " from ubs_black_app_weixin_check where type='%s'"
        #select_sql += " and sync_status=2"
        select_sql += " order by pub_time desc"
        select_sql += " limit 10"
        cur.execute(select_sql % (type))
        all_data = cur.fetchall()
        for row in all_data:
            temp_row = copy.deepcopy(row)
            #
            # Get other details from mongodb;
            url = temp_row['url'].encode("gbk")
            mongo_article = UTIL.get_article_by_url(url, is_convert=False)
            if mongo_article:
                #
                temp_row['img'] = mongo_article['img_list'][0]
                temp_row['topic1'] = mongo_article['topic1']
                temp_row['topic2'] = mongo_article['topic2']
                temp_row['topic3'] = mongo_article['topic3']
                #
                res['articles'].append(UTIL.get_dict_in_utf8(temp_row))
            #
        #
        cur.close()
        conn.close()
    except Exception, e:
        print "Can not Connect to mysql server"
コード例 #7
0
ファイル: ASTEROIDE.py プロジェクト: jonathansan04/Final
 def __init__(self, coord, vel):
     Sprite.__init__(self)
     self.image = UTIL.cargar_imagen('Imagenes/asteroid.png')
     self.rect = self.image.get_rect()
     self.rect.move_ip(coord[0], coord[1])
     self.dir = "l"
     self.velocidad = vel
コード例 #8
0
def get_file():
    #
    res = dict()
    #
    # file-path
    temp_dir = "/search/chenzhengtong/weixin-recom/tempFiles/"
    full_path = temp_dir + "single.csv"
    f = open(full_path)
    lines = f.readlines(100000)
    #
    format_list = ["main_type", "title", "url", "level"]
    #
    if not lines:
        print "error"
    else:
        try:
            #
            conn, cur = ADMIN_OA.get_conn_for_mysql_oa()
            #
            for each_line in lines:
                line = str.rstrip(each_line)
                temp_list = line.split(",")
                #
                content_list = list()
                content_list.append(
                    unicode(temp_list[0], "gbk").encode("gbk")
                )
                content_list.append(
                    unicode(temp_list[1], "gbk").encode("gbk")
                )
                content_list.append(
                    temp_list[2].split(CONST.OPENID_PREFIX)[1]
                )
                content_list.append(temp_list[3])
                #
                sql_ui = ADMIN_OA.get_ui_sql(content_list)
                #print sql_ui
                #
                cur.execute(sql_ui)
            #
            cur.close()
            conn.close()
            #
            UTIL.append_result_ok(res)
        except Exception, e:
            #
            UTIL.append_result_error(res, e)
コード例 #9
0
def verify_article(url, verify_res):
    #
    res = dict()
    #
    unquoted_url = urllib.unquote(url)
    unquoted_url = unquoted_url.replace("______", "&")
    #print unquoted_url
    res['verify_result'] = UTIL.verify_article_by_url(unquoted_url, verify_res)
    return res
コード例 #10
0
ファイル: api_pymongo_article.py プロジェクト: TeaEra/CZT_Web
def get_articles(urls):
    #
    res = dict()
    res['articles'] = list()
    #
    for each_url in urls:
        unquoted_each_url = urllib.unquote(each_url)
        res['articles'].append(UTIL.get_article_by_url(unquoted_each_url))
    return res
コード例 #11
0
ファイル: api_mysql_oa_select.py プロジェクト: TeaEra/CZT_Web
def get_oas():
    #
    sql_where = ADMIN_OA.get_where_from_fs(fs)
    sql_limit = ADMIN_OA.get_limit_from_fs(fs)
    #
    res = dict()
    res["oas"] = list()
    #
    try:
        conn, cur = ADMIN_OA.get_conn_for_mysql_oa()
        select_sql = "select * from t_account_manager"
        #
        select_sql += sql_where
        #
        select_sql += sql_limit
        all_data = UTIL.run_conn_select(cur, select_sql)
        #
        for row in all_data:
            res["oas"].append(UTIL.get_dict_in_utf8(row))
        #
        cur.close()
        conn.close()
        #
        UTIL.append_result_ok(res)
    except Exception, e:
        #
        UTIL.append_result_error(res, e)
コード例 #12
0
def get_articles():
    #
    enable_time = \
        datetime.datetime.fromtimestamp(
            int(WEIXIN_CHECK.get_enable_time(fs)) / 1000
        )
    disable_time = \
        datetime.datetime.fromtimestamp(
            int(WEIXIN_CHECK.get_disable_time(fs)) / 1000
        )
    #print enable_time.strftime('%Y-%m-%d %H:%M:%S')
    #print disable_time.strftime('%Y-%m-%d %H:%M:%S')
    enable_time = enable_time.strftime('%Y-%m-%d %H:%M:%S')
    disable_time = disable_time.strftime('%Y-%m-%d %H:%M:%S')
    modify_time = UTIL.get_styled_today()
    #
    title = WEIXIN_CHECK.get_title(fs)
    readnum = WEIXIN_CHECK.get_readnum(fs)
    status = WEIXIN_CHECK.get_status(fs)
    type = WEIXIN_CHECK.get_type(fs)
    #
    title = UTIL.get_str_in_gbk(title)
    type = UTIL.get_str_in_gbk(type)
    keywords = WEIXIN_CHECK.get_keywords(fs)
    #
    urls = WEIXIN_CHECK.get_urls(fs)
    unquoted_urls = list()
    for each_url in urls:
        unquoted_urls.append(urllib.unquote(each_url))
    #
    res = dict()
    #
    try:
        conn, cur = ADMIN_WEIXIN_CHECK.get_conn_for_mysql_art()
        table = ADMIN_WEIXIN_CHECK.get_table()
        #
        update_sql = "update " + table + " set keywords='%s', title='%s', read_num='%s', topic1='%s', status=%s, start_time='%s', end_time='%s', modify_time='%s' where url in (%s)"
        in_clause = ', '.join(list(map(lambda x: '%s', unquoted_urls)))
        update_sql = update_sql % (keywords, title, readnum, type, status, enable_time, disable_time, modify_time, in_clause)
        #
        #print update_sql
        cur.execute(update_sql, unquoted_urls)
        #
        cur.close()
        conn.close()
        #
        UTIL.append_result_ok(res)
        #
        res["appendix"] = {}
        res["appendix"]["start_time"] = enable_time
        res["appendix"]["end_time"] = disable_time
        res["appendix"]["modify_time"] = modify_time
    except Exception, e:
        #
        UTIL.append_result_error(res, e)
コード例 #13
0
def get_count():
    #
    sql_where = ADMIN_OA.get_where_from_fs(fs)
    #
    res = dict()
    #
    try:
        conn, cur = ADMIN_OA.get_conn_for_mysql_oa()
        sql_select = "select exists(select 1 from t_account_manager"
        sql_select += sql_where
        sql_select += ") as dup_check"
        #
        all_data = UTIL.run_conn_select(cur, sql_select)
        res["count"] = all_data
        #
        cur.close()
        conn.close()
        #
        UTIL.append_result_ok(res)
    except Exception, e:
        #
        UTIL.append_result_error(res, e)
コード例 #14
0
ファイル: api_mysql_oa_delete.py プロジェクト: TeaEra/CZT_Web
def get_res():
    #
    sql_where = ADMIN_OA.get_where_from_fs(fs)
    #
    res = dict()
    #
    try:
        conn, cur = ADMIN_OA.get_conn_for_mysql_oa()
        sql_delete = "delete from t_account_manager"
        #
        sql_delete += sql_where 
        #
        #print sql_delete
        TE_CUSTOM.run_sql(cur, sql_delete)
        #
        cur.close()
        conn.close()
        #
        UTIL.append_result_ok(res)
    except Exception, e:
        #
        UTIL.append_result_error(res, e)
コード例 #15
0
ファイル: api_mysql_oa_count.py プロジェクト: TeaEra/CZT_Web
def get_count():
    #
    sql_where = ADMIN_OA.get_where_from_fs(fs)
    #
    res = dict()
    #
    try:
        conn, cur = ADMIN_OA.get_conn_for_mysql_oa()
        select_sql = "select count(*) as total_num from t_account_manager"
        #
        select_sql += sql_where
        #
        all_data = UTIL.run_conn_select(cur, select_sql)
        res["count"] = all_data
        #
        cur.close()
        conn.close()
        #
        UTIL.append_result_ok(res)
    except Exception, e:
        #
        UTIL.append_result_error(res, e)
コード例 #16
0
ファイル: api_mysql_oa_insert.py プロジェクト: TeaEra/CZT_Web
def get_res():
    #
    insert_details = ADMIN_OA.get_insert_details_from_fs(fs)
    #
    res = dict()
    #
    try:
        conn, cur = ADMIN_OA.get_conn_for_mysql_oa()
        insert_sql = "insert into t_account_manager"
        #
        insert_sql += insert_details 
        #
        #print insert_sql
        TE_CUSTOM.run_sql(cur, insert_sql)
        #
        cur.close()
        conn.close()
        #
        UTIL.append_result_ok(res)
    except Exception, e:
        #
        UTIL.append_result_error(res, e)
コード例 #17
0
def get_articles():
    #
    res = dict()
    res["all_types"] = list()
    #
    try:
        conn, cur = ADMIN_WEIXIN_CHECK.get_conn_for_mysql_art()
        table = ADMIN_WEIXIN_CHECK.get_table()
        #
        select_sql = "select topic1 from " + table + " group by(topic1)"
        cur.execute(select_sql)
        #
        all_data = cur.fetchall()
        for row in all_data:
            res["all_types"].append(UTIL.get_dict_in_utf8(row))
        #
        cur.close()
        conn.close()
        #
        UTIL.append_result_ok(res)
    except Exception, e:
        #
        UTIL.append_result_error(res, e)
コード例 #18
0
def get_user_info_by_id():
    #
    mid = get_mid()
    #
    connection = pymongo.Connection(HOST, PORT)
    #
    #db = connection.userDB
    #db = connection.AuserDB
    db = connection.userInfoDB
    #
    collection = db.user_info
    condition = {"_id" : mid}
    curr_user = collection.find_one(condition)
    #
    connection.close()
    #
    if curr_user:
        return UTIL.get_dict_in_utf8(curr_user)
    return {}
コード例 #19
0
def copy_data():
    try:
        conn = MySQLdb.connect(host=host, user=user, passwd=pwd, db=db, charset=charset, cursorclass=MySQLdb.cursors.DictCursor)
        cur = conn.cursor()
        cur2 = conn.cursor()
        select_sql = "select url from ubs_black_app_weixin_check"
        #
        '''
        cond_sql = " where url='http://mp.weixin.qq.com/s?__biz=MzA5NDM2MTUzOA==&amp;mid=200642399&amp;idx=3&amp;sn=6ab1a91b8171279279f6dc58f842c673&amp;3rd=MzA3MDU4NTYzMw==&amp;scene=6#rd'"
        select_sql += cond_sql
        '''
        #
        cur.execute(select_sql)
        all_data = cur.fetchall()
        #
        data_count = 0
        test_count = 0
        for row in all_data:
            data_count += 1
            if data_count % 1000 == 0:
                print ">>>Already scanned: " + str(data_count)
            url=row['url'].encode("gbk")
            mongo_article = UTIL.get_article_by_url(url, is_convert=False)
            if mongo_article:
                test_count += 1
                #
                img = mongo_article['img_list'][0]
                topic1 = mongo_article['topic1']
                topic2 = mongo_article['topic2']
                topic3 = mongo_article['topic3']
                #
                update_sql = "update ubs_black_app_weixin_check set img='%s', topic1='%s', topic2='%s', topic3='%s' where url='%s'"
                cur2.execute(update_sql % (img, topic1, topic2, topic3, url))
        #
        print data_count
        print test_count
        #
        cur.close()
        conn.close()
    except Exception, e:
        #print "Can not connect to mysql server"
        print e
コード例 #20
0
ファイル: api_mysql_oa_update.py プロジェクト: TeaEra/CZT_Web
def get_oas():
    #
    update_details = ADMIN_OA.get_update_details_from_fs(fs)
    #
    res = dict()
    res["oas"] = list()
    #
    try:
        conn, cur = ADMIN_OA.get_conn_for_mysql_oa()
        update_sql = "update t_account_manager set"
        #
        update_sql += update_details 
        #
        UTIL.run_conn_update(cur, update_sql)
        #
        cur.close()
        conn.close()
        #
        UTIL.append_result_ok(res)
    except Exception, e:
        #
        UTIL.append_result_error(res, e)
コード例 #21
0
    cv2.rectangle(img, (0, 70), (319, 950), (0, 255, 0), 3)
    img1 = img[70:950, 0:319]
    hsv = cv2.cvtColor(img1, cv2.COLOR_BGR2HSV)
    lower_range = np.array([0, 10, 60])
    upper_range = np.array([20, 150, 255])
    mask = cv2.inRange(hsv, lower_range, upper_range)
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3))
    mask = cv2.erode(mask, kernel, iterations=1)
    mask = cv2.dilate(mask, kernel, iterations=1)
    # blur = cv2.blur(mask, (5, 5))
    blurred_hsv = cv2.GaussianBlur(mask, (9, 9), 0)
    res = cv2.bitwise_and(img1, img1, mask=blurred_hsv)
    cv2.imshow("frame", img)
    _, contours, _ = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
                                      cv2.CHAIN_APPROX_SIMPLE)
    cnt = ut.getMaxContour(contours, 4000)
    #cv2.putText(img1, "hello world!", (120, 90), font, 1, (200, 255, 255), 2)

    if cnt is not None:
        label = ut.getGestureImg(cnt, img, mask, model)
        if (label is not None):
            if (temp == 0):
                previouslabel = label
            if previouslabel == label:
                previouslabel = label
                temp += 1
            else:
                temp = 0
            #print(label)
            print(chr(label + 64))
            #text=ch.getText(text=chr(label+64))
コード例 #22
0
def get_file():
    #
    temp_dir = "/search/chenzhengtong/weixin-recom/tempFiles/"
    #
    file = fs["files"]
    #
    res = dict()
    #
    if file.filename:
        #
        # file-name
        #fn = file.filename
        fn = "single.csv"
        fn = os.path.basename(fn)
        #
        # file-path
        full_path = temp_dir + fn
        #
        #
        if os.path.isfile(full_path):
            os.remove(full_path)
        #
        #
        chunk = file.file.read()
        open(full_path, 'wb').write(chunk)
        #
        #
        f = open(full_path)
        lines = f.readlines(100000)
        oi_list = list()
        #
        if not lines:
            print "error"
        else:
            try:
                #
                conn, cur = ADMIN_OA.get_conn_for_mysql_oa()
                #
                for each_line in lines:
                    line = str.rstrip(each_line)
                    temp_list = line.split(",")
                    #
                    oi = temp_list[2].split(CONST.OPENID_PREFIX)[1]
                    oi_list.append(oi)
                #
                sql = "select count(*) as dup_num from t_account_manager where openid in "
                sql_in = ""
                for each_oi in oi_list[:-1]:
                    sql_in += "'" + each_oi + "',"
                sql_in += "'" + oi_list[-1] + "'"
                sql += "(" + sql_in + ")"
                #print sql
                all_data = UTIL.run_conn_select(cur, sql)
                res["count"] = all_data
                #
                cur.close()
                conn.close()
                #
                UTIL.append_result_ok(res)
            except Exception, e:
                #
                UTIL.append_result_error(res, e)
コード例 #23
0
####  give P and several Q and choice and segment array  #####
print('Training start....')
for i in range(testNum):
	start_time = time.time()
	print("building model")
	model = TENSORFLOW_MODEL.MODEL(	MODEL_X_DIMENSION,
									MODEL_Y_DIMENSION,
									MODEL_WIDTH,
									MODEL_LEARNING_RATE,
									KERNEL_NUM,
									parameterPath,
									MODEL_BATCHSIZE,
									LONGEST_P_NUM
								)
	print("building finish")
	model.initialize()
	UTIL.Train_TestMODEL(	train_q,
							val_q,
							plotFilePath,
							model,
							MODEL_EPOCH,
							MODEL_BATCHSIZE,
							LONGEST_P_NUM
						)
	print("--- MODEL %s seconds ---" % (time.time() - start_time))