summaryrefslogtreecommitdiff
path: root/getApplicationId.py
blob: d46f9b070181c03b4f8bc3a56c5a8f0eefd6ed50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python3
# coding=utf-8
import time
import pymysql.cursors
import ast

def get_app_id(app, api_host):
    # http测试环境返回group_id
    mysql_host = api_host[7:]
    
    # https 环境返回group_id
    # mysql_host = api_host[8:]
    # 集成测试环境
    db = pymysql.connect(host=mysql_host,
                        user='test',
                        password='test',
                        database='tsg-bifang')
    # 45.250 环境
    # db = pymysql.connect(host=mysql_host,
    #                     user='root',
    #                     password='Bifang&*()',
    #                     database='tsg-bifang-2402')
    app_group_id_list=[]
    # 该方法用于将字符串类型的['ssl', 'http']转换为list类型的['ssl', 'http'](在无法使用list函数直接转换的情况下)
    app = ast.literal_eval(app)
    for app_name in app:
        sql="select group_id from app_id_dict where app_name= 'appname'"
        sql=sql.replace("appname", app_name)
        #print(sql)
        #连接数据库
        mycursor = db.cursor()
        #根据sql查询
        mycursor.execute(sql)
        #获取查询结果
        myresult = mycursor.fetchall()
        #处理查询结果,获取id
        app_id=myresult[0][0]
        app_group_id_list.append(app_id)
    return app_group_id_list

def get_app_id_2(app, api_host):
    """
    # 返回app id值
    :param app:  例如:"['http']"
    :param api_host: "http://192.168.44.72"
    :return:
    """
    mysql_host = api_host[7:]
    # mysql_host = "192.168.40.198"
    db = pymysql.connect(host=mysql_host,
                        user='test',
                        password='test',
                        database='tsg-bifang')
    app_group_id_list=[]
    # 该方法用于将字符串类型的['ssl', 'http']转换为list类型的['ssl', 'http'](在无法使用list函数直接转换的情况下)
    app = ast.literal_eval(app)
    for app_name in app:
        sql="select app_id from app_id_dict where app_name= 'appname'"
        sql=sql.replace("appname", app_name)
        #print(sql)
        #连接数据库
        mycursor = db.cursor()
        #根据sql查询
        mycursor.execute(sql)
        #获取查询结果
        myresult = mycursor.fetchall()
        #处理查询结果,获取id
        app_id=myresult[0][0]
        app_group_id_list.append(app_id)
        #print(app_group_id_list)
    return app_group_id_list

if __name__ == '__main__':
    api_host = "http://192.168.44.72"
    appid = get_app_id("['http']", api_host)
    time.sleep(3)