1 Star 0 Fork 0

abc-edb-fund/edb_mapping_nbs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
config.py 5.53 KB
一键复制 编辑 原始数据 按行查看 历史
李新 提交于 2018-07-16 18:41 . Initial Commit
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/7/16 18:36
# @Author : Orient
# @File : config.py
# @Software: PyCharm
import pymysql
import pymongo
import sys
import traceback
#地区行政级别关键词
dict_region = {
"省": "",
"市": "",
"盟": "",
"地区": "",
"自治区": "",
"自治州": "",
"回族": "",
"壮族": "",
"藏族": "",
"羌族": "",
"傣族": "",
"苗族": "",
"白族": "",
"侗族": "",
"彝族": "",
"蒙古族": "",
"傈僳族": "",
"朝鲜族": "",
"哈尼族": "",
"布依族": "",
"景颇族": "",
"土家族": "",
"维吾尔": "",
"特别行政区":""}
dict_symbol = {
"/": "",
":": "",
"_": "",
"、": "",
"(": "",
")": "",
"(": "",
")": "",
"&": "",
"%": "",
"%": "",
"≥": "",
"=": "",
"=": "",
"—": "",
"-": "" }
#mongo连接信息
MONGODB_CONFIG_CT = {
'host': '114.55.39.144',
'port': 3717,
'db_name': 'original_data',
'username': 'crawler_team',
'password': 'Ur4Q6h2pgA6X4G9h'
}
MONGODB_CONFIG_TS = {
'host': '114.55.39.146',
'port': 3717,
'db_name': 'table_search',
'username': 'dev_search',
'password': '8d008c639a75'
}
MONGODB_CONFIG_test = {
'host': '118.178.129.165',
'port': 3717,
'db_name': 'original_data',
'username': 'cr',
'password': 'ZVwnHviworld12ACE'
}
# MySQL连接信息
config_data_center = {
'host': '118.31.118.16',
'port': 3306,
'user': 'dc_select',
'passwd': 'Aenl1pnBtXWpQ5DW',
'db': 'data_center',
'charset': 'utf8'
}
config_dzh = {
'host':'47.96.254.85',
'port':3306,
'user':'edb_team',
'passwd':'QINkGJ3q2G8HzkiZ',
'db':'dzh',
'charset':'utf8'
}
config_li = {
'host':'127.0.0.1',
'port':3306,
'user':'root',
'passwd':'anton826',
'db':'data_production',
'charset':'utf8'
}
config_kk = {
'host':'47.96.254.85',
'port':3306,
'user':'edb_team',
'passwd':'QINkGJ3q2G8HzkiZ',
'db':'data_center',
'charset':'utf8'
}
#MySQL连接
def conn_kk():
conn = pymysql.connect(**config_kk)
cursor = conn.cursor()
return cursor
def conn_li():
conn = pymysql.connect(**config_li)
cursor = conn.cursor()
return cursor
def conn_data_center():
conn = pymysql.connect(**config_data_center)
cursor = conn.cursor()
return cursor
def province():
conn = pymysql.connect(**config_kk)
cursor = conn.cursor()
#抽取省份名
sql_province = '''select distinct province from data_center.edb_indicator_value'''
cursor.execute(sql_province)
row = cursor.fetchall()
province = []
for i in range(len(row)):
region_name = row[i][0]
if region_name:
for item in dict_region.items():
region_name = region_name.replace(item[0], item[1])
if region_name in province:
pass
else:
province.append(region_name)
return province
def city():
#抽取城市名
conn = pymysql.connect(**config_kk)
cursor = conn.cursor()
sql_city = '''select distinct city from data_center.edb_indicator_value'''
cursor.execute(sql_city)
row = cursor.fetchall()
city = []
for i in range(len(row)):
region_name = row[i][0]
if region_name:
for item in dict_region.items():
region_name = region_name.replace(item[0], item[1])
if region_name in city:
pass
else:
city.append(region_name)
return city
#mongo连接
class MongoConnCT(object):
def __init__(self):
# connect db
try:
self.conn = pymongo.MongoClient(MONGODB_CONFIG_CT['host'], MONGODB_CONFIG_CT['port'])
self.db = self.conn[MONGODB_CONFIG_CT['db_name']] # connect db
self.username=MONGODB_CONFIG_CT['username']
self.password=MONGODB_CONFIG_CT['password']
if self.username and self.password:
self.connected = self.db.authenticate(self.username, self.password)
else:
self.connected = True
except Exception:
print(traceback.format_exc())
print('Connect Statics Database Fail.')
sys.exit(1)
class MongoConnTS(object):
def __init__(self):
# connect db
try:
self.conn = pymongo.MongoClient(MONGODB_CONFIG_TS['host'], MONGODB_CONFIG_TS['port'])
self.db = self.conn[MONGODB_CONFIG_TS['db_name']] # connect db
self.username=MONGODB_CONFIG_TS['username']
self.password=MONGODB_CONFIG_TS['password']
if self.username and self.password:
self.connected = self.db.authenticate(self.username, self.password)
else:
self.connected = True
except Exception:
print(traceback.format_exc())
print('Connect Statics Database Fail.')
sys.exit(1)
class MongoConntest(object):
def __init__(self):
# connect db
try:
self.conn = pymongo.MongoClient(MONGODB_CONFIG_test['host'], MONGODB_CONFIG_test['port'])
self.db = self.conn[MONGODB_CONFIG_test['db_name']] # connect db
self.username=MONGODB_CONFIG_test['username']
self.password=MONGODB_CONFIG_test['password']
if self.username and self.password:
self.connected = self.db.authenticate(self.username, self.password)
else:
self.connected = True
except Exception:
print(traceback.format_exc())
print('Connect Statics Database Fail.')
sys.exit(1)
if __name__ == '__main__':
pass
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/edbmapping/edb_mapping_nbs.git
git@gitee.com:edbmapping/edb_mapping_nbs.git
edbmapping
edb_mapping_nbs
edb_mapping_nbs
master

搜索帮助