def init(): #获取当前脚本执行的目录 root_dir = os.path.abspath(os.path.dirname(__file__)) #sys.path.append(root_dir) #配置文件路径 config_file = os.path.join(root_dir, 'config.ini') if not os.path.isfile(config_file): #文件不存在 print "\033[31;1m[Error]===> 文件不存在\033[0m" sys.exit(0) #读取配置文件 cf = ConfigParser.ConfigParser() cf.read(config_file) #read server domain_img = cf.get("Domain", "domain_img") sql_search_coupon = cf.get("SQL", "couponSql") sql_search_house = cf.get("SQL", "houseSql") sql_search_shop = cf.get("SQL", "shopSql") sql_search_secondhand = cf.get("SQL", "secondhandSql") sqls = (sql_search_coupon, sql_search_house, sql_search_shop, sql_search_secondhand) db_conn = mysql.Mysql(host=cf.get("Database", "host"), port=cf.getint("Database", "port"), user=cf.get("Database", "user"), pwd=cf.get("Database", "pwd"), db=cf.get("Database", "db"), charset=cf.get("Database", "charset")) no_img_uri = cf.get("URI", "defaultNoImgUri") gen = HtmlGenerator(root_dir, domain_img, db_conn, no_img_uri) out_put_path = cf.get("FILE", "outPutPath") return gen, sqls, out_put_path
def __init__(self): my = mysql.Mysql() my.connect_mysql() self.my = my self.cur = my.cur lg = logoutput.Logger() self.lg = lg
def __init__(self): self.lg = logoutput.Logger() # 打开excel表格 try: # data = xlrd.open_workbook(path) self.open_excel() self.table = self.data.sheet_by_index(0) self.ROW_COUNT = self.table.nrows except Exception as e: self.lg.error(e) self.lg.error("打开Excel表格失败!") # 数据库连接 try: self.db = mysql.Mysql() self.db.connect_mysql() except Exception as e: self.lg.error(e) self.lg.error("连接数据库失败!")
#读取配置文件 cf = ConfigParser.ConfigParser() cf.read('config.ini') #read server domain_img = cf.get("Domain", "domain_img") domain_i = cf.get("Domain", "domain_i") domain_fang = cf.get("Domain", "domain_fang") domain_www = cf.get("Domain", "domain_www") sql_search_coupon = cf.get("SQL", "couponSql") sql_search_house = cf.get("SQL", "houseSql") sql_search_shop = cf.get("SQL", "shopSql") sql_search_secondhand = cf.get("SQL", "secondhandSql") db_conn = mysql.Mysql(host=cf.get("Database", "host"), port=cf.getint("Database", "port"), user=cf.get("Database", "user"), pwd=cf.get("Database", "pwd"), db=cf.get("Database", "db"), charset=cf.get("Database", "charset")) no_img_uri = cf.get("URI", "defaultNoImgUri") coupons = db_conn.getAll(sql_search_coupon) houses = db_conn.getAll(sql_search_house) mylookup = TemplateLookup(directories=['template'], input_encoding='utf-8', output_encoding='utf-8', default_filters=['decode.utf8'], module_directory='/tmp/mako_modules') mytemplate = mylookup.get_template("base.html") print mytemplate.render_unicode(coupons=coupons, houses=houses)