代码拉取完成,页面将自动刷新
#!/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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。