示例#1
0
 def __init__(self):
     handlers = [
         (r"/get_host", GethostHandler),
     ]
     settings = dict(
         xsrf_cookies=True,
         cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
         login_url="/auth/login",
         debug=True,
     )
     super(ApiApplication, self).__init__(handlers, **settings)
     self.db = torndb.Connection(host=options.db_host,
                                 user=options.db_user,
                                 database=options.db_database,
                                 password=options.db_password)
示例#2
0
def torndb_query_menulistings(shop_id):
    
    menu_select = 'SELECT * FROM ' + table_menulist + shop_id
    
    dic_json = {}
    conn = torndb.Connection('localhost', database_name, user='******', password='******', charset='utf8')
    datas = conn.query(menu_select)
    dic_json["menulistings" + shop_id] = datas if datas else None
    conn.close();
    
    if not dic_json["menulistings" + shop_id]: 
        return None
    
    json_obj = tornado.escape.json.dumps(dic_json, encoding="UTF-8", ensure_ascii=False) 
    return json_obj
示例#3
0
文件: __init__.py 项目: yujiye/Codes
def connect_db(connNum):
    c = current_app.config
    dbName = "MYSQL_DB_NAME" if connNum == 1 else "MYSQL_DB_NAME_2"
    
    conn = torndb.Connection(
        c.get("MYSQL_DB_HOST"),
        c.get(dbName),
        c.get("MYSQL_DB_USER"),
        c.get("MYSQL_DB_PASSWD"),
        time_zone='+8:00',
        charset='utf8mb4',
        maxcached=10, maxconnections=20)
    conn.execute("set sql_safe_updates=1")
    conn.execute("set autocommit=1")
    return conn
	def get(self):
		db = None
		rows = None
		db    = torndb.Connection(host="localhost", database="alterrefront", user="******", password="******")

		category = "meet"
		rows  = db.query("""
							select title, description, media, url, price, location from ads where category=%s
						""", (category))
		db.close()
		results = dict()
		results["ads"] = rows
		results["total"] = len(rows)
		self.set_header("Content-Type", "application/json")
		self.write(json.dumps(results))
示例#5
0
def getSampleWords(queryStr, fieldName):
    db = torndb.Connection(host=options.mysql_host,
                           database='iculture',
                           user=options.mysql_user,
                           password=options.mysql_password)
    result = []
    print 'to mysql:' + queryStr
    dbresult = []

    dbresult = db.query(queryStr)
    for post in dbresult:
        word = post[fieldName]
        result.append(word[:2])

    return result
示例#6
0
def likeQuery(key):
    # 建立数据库的连接
    conn = torndb.Connection(host='127.0.0.1', database='tornaod20180830', user='******', password='******')

    sql = 'select * from t_auser where uname like "%%{uname}%%"'.format(uname=key)

    print sql

    #执行插入操作
    rowList = conn.query(sql)

    print rowList

    #断开连接
    conn.close()
    def __init__(self):
        self.db = torndb.Connection(host="127.0.0.1",
                                    database="grudio",
                                    user="******",
                                    password="******")
        self.projectDir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), os.path.pardir))
        self.configFile = os.path.join(self.projectDir, "config.json")
        self.songsAbsDir = self.projectDir + "/songs"
        self.songsRelativeDir = "songs"

        self.next_playing_songs_ids = []

        with open(self.configFile) as json_file:
            self.config = json.load(json_file)
示例#8
0
    def __init__(self):
        handlers = urls
        settings = dict(
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            debug=True,
            allow_remote_access=True,
        )
        conn = torndb.Connection(config.DB_HOST + ":" + str(config.DB_PORT),
                                 config.DB_NAME,
                                 user=config.DB_USER,
                                 password=config.DB_PWD)
        self.db = conn

        tornado.web.Application.__init__(self, handlers, **settings)
示例#9
0
def completeTask(info, result, dataDir=None):
    mid = info['id']
    if result:
        sqlstring = 'UPDATE %s SET `status`=2 WHERE `id`="%s"' % (
            lp_photo_summary, mid)
    else:
        sqlstring = 'UPDATE %s SET `status`=4 WHERE `id`="%s"' % (
            lp_photo_summary, mid)

    conn = torndb.Connection(host="192.168.1.119",
                             database="data_transfer",
                             user="******",
                             password=passwd)
    conn.execute(sqlstring)
    conn.close()
示例#10
0
 def __init__(self):
     handlers = auto_get_urls()
     settings = dict(
         template_path=os.path.join(os.path.dirname(__file__), "templates"),
         static_path=os.path.join(os.path.dirname(__file__), "static"),
         debug=True,
         cookie_secret=
         "6dsfd1oETzKXQs45432334322GaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
         login_url="/login",
     )
     tornado.web.Application.__init__(self, handlers, **settings)
     self.db = torndb.Connection(host=options.mysql_host,
                                 database=options.mysql_database,
                                 user=options.mysql_user,
                                 password=options.mysql_password)
示例#11
0
 def get(self):
     db = torndb.Connection(host='localhost', database='yhy2', user='******', password='******')
     collections = db.query('select * from collection order by created_at desc limit 4')
     result = {}
     for collection in collections:
         collection['id'] = collection.id
         collection['name'] = collection.name
         collection['introduce'] = collection.introduce
         collection['img'] = collection.img
         collection['created_at'] = collection.created_at.strftime("%Y-%m-%d %H:%M:%S")
     db.close()
     result['code'] = '0'
     result['body'] = {'collection': collections}
     result['message'] = '成功'
     self.write(json_encode(result))
示例#12
0
文件: main.py 项目: andrewwuan/dude
    def __init__(self):
        handlers = [
            (r"/", MainHandler),
            (r"/wav", WavHandler),
            (r"/message", MessageHandler),
            (r"/brightness", BrightnessHandler),
            (r"/temperature", TemperatureHandler),
            (r"/last_user", LastUserHandler),
        ]
        tornado.web.Application.__init__(self, handlers)

        # Have one global connection to the blog DB across all handlers
        self.db = torndb.Connection(
            host=options.mysql_host, database=options.mysql_database,
            user=options.mysql_user, password=options.mysql_password)
示例#13
0
    def __init__(self):
        handlers = [(r'^/$', Indexhandler)]

        settings = dict(
            static_path=os.path.join(current_path, "static".decode('utf-8')),
            template_path=os.path.join(current_path,
                                       "templates".decode('utf-8')),
            debug=True)

        super(Application, self).__init__(handlers, **settings)
        # 连接MySQL数据库
        self.db = torndb.Connection(host='localhost',
                                    database='tornado1',
                                    user='******',
                                    password='******')
示例#14
0
文件: server.py 项目: phantom0925/001
    def __init__(self, *args, **kwargs):

        super(Application, self).__init__(*args, **kwargs)
        # self.db = torndb.Connection(
        # 	host = config.mysql_options["host"],
        # 	database = config.mysql_options["database"],
        # 	user = config.mysql_options["user"],
        # 	password = config.mysql_options["password"]
        # )
        self.db = torndb.Connection(**config.mysql_options)
        # self.redis = redis.StrictRedis(
        # 	host = config.redis_options["host"],
        # 	port = config.redis_options["port"]
        # 	)
        self.redis = torndb.StrictRedis(**config.redis_options)
示例#15
0
    def probe_epg(self):
        db = torndb.Connection(
            host = '******',
            database = **,
            user = '******',
            password = '******');

        #sql = 'select CHANNEL_CODE from LV_CHANNEL where IS_ONLINE=1 order by CHANNEL_CODE';
        sql = 'select CHANNEL_NAME from LV_CHANNEL where IS_ONLINE=1 order by CHANNEL_NAME';
        _all = None;
        try:
            _all = db.query(sql);
        except Exception,e:
            config.logging.error("probe_epg.connect db err,e=[%]" %(e));
            return;
示例#16
0
 def migrate2db(self, keyword):
     #db = torndb.Connection("127.0.0.1", "sales_help", "root", "123456")
     db = torndb.Connection("58.211.114.118", "ec_food", "food", "food")
     f = open(keyword + ".txt", "r")
     line = f.readline()
     while ('' != line and line is not None):
         cityName, name, address, phone, lng, lat = line.split("\t")
         #id = db.execute_lastrowid(
         #"insert into sales_service_point(sp_name,phone,address,lng_baidu,lat_baidu,createtime,product_category_ids) values(%s,%s,%s,%s,%s,%s,%s)",
         #name,phone,address,lng,lat,datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),"0")
         id = db.execute_lastrowid(
             "insert into biz_corp_shop(shop_name,phone,address,lng_baidu,lat_baidu,create_time,pid) values(%s,%s,%s,%s,%s,%s,%s)",
             name, phone, address, lng, lat,
             datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "0")
         line = f.readline()
示例#17
0
    def __init__(self):
        handlers = [
            url(r"/", HomeHandler),
            #注册,登录,登出,账号删除,个人资料展示页面,个人资料编辑-丰玉霖
            url(r"/signup", UserCreateHandler),
            url(r"/login", UserLoginHandler),
            url(r"/logout", UserLogoutHandler),
            url(r"/close", UserDeleteHandler),
            url(r"/u/([0-9]+)/profile/*", ProfileHandler),
            url(r"/u/([0-9]+)/profile/edit", ProfileEditHandler),

            #新建相册,相册列表,相册编辑,相册删除-阙中元,魏晓飞
            url(r"/albums/new", AlbumCreateHandler, name="AlbumCreate"),
            url(r"/u/([0-9]+)/albums/*", AlbumsListHandler),
            url(r"/u/([0-9]+)/albums/([0-9]+)/edit", AlbumEditHandler),
            url(r"/u/([0-9]+)/albums/([0-9]+)/delete", AlbumDeleteHandler),

            #上传相片,相片列表,单个相片显示页面,相片删除,朋友圈-唐永剑,贾超,姚彬,徐怡阳,张光伟,李佳袁
            url(r"/photos/new", PhotosUploadHandler, name="PhotosUpload"),
            url(r"/u/([0-9]+)/albums/([0-9]+)", PhotosListHandler),
            url(r"/u/([0-9]+)/albums/([0-9]+)/([0-9]+)", PhotoHandler),
            url(r"/u/([0-9]+)/albums/([0-9]+)/([0-9]+)/delete",
                PhotoDeleteHandler),
            url(r"/feed/*", FeedHandler, name="feed"),
            url(r"/myform", MyFormHandler, name="myform")
        ]
        settings = dict(
            website_title=u"剑哥相册",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            ui_modules={
                "Navbar": uimodules.Navbar,
                "Bottom": uimodules.Bottom
            },
            xsrf_cookies=False,
            #cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
            cookie_secret="1234567892015neuee",
            login_url="/login",
            debug=True,
        )
        super(Application, self).__init__(handlers, **settings)
        # Have one global connection to the blog DB across all handlers
        self.db = torndb.Connection(host=options.mysql_host,
                                    database=options.mysql_database,
                                    user=options.mysql_user,
                                    password=options.mysql_password)

        self.maybe_create_tables()
示例#18
0
    def __init__(self):
        handlers = HandlersURL
        settings = MainSetting
        tornado.web.Application.__init__(self, handlers, **settings)

        # Have one global connection to DB across all handlers
        self.db = torndb.Connection(
            host=options.mysql_host, database=options.mysql_database,
            user=options.mysql_user, password=options.mysql_password,
            time_zone='+8:00',charset='utf8')

        ping_db = lambda: self.db.query("select now()")
        #def print_test():
        #    print "Hello Test"
        # 每3分钟执行一次数据库查询,防止mysql gone away,时间间隔要小于msyql的wait_timeout时长
        tornado.ioloop.PeriodicCallback(ping_db,3 * 60 * 1000).start()
示例#19
0
 def __init__(self):
     handlers = [
         (r"/", IndexHandler),
         (r"/view", InsertHandler),
     ]
     settings = dict(template_path=os.path.join(os.path.dirname(__file__),
                                                "templates"),
                     static_path=os.path.join(os.path.dirname(__file__),
                                              "statics"),
                     debug=True,
                     autoescape=None)
     super(Application, self).__init__(handlers, **settings)
     self.db = torndb.Connection(host="127.0.0.1",
                                 database="itcast",
                                 user="******",
                                 password="******")
示例#20
0
 def __init__(self):
     handlers = [
         (r"/", IndexHandler),
     ]
     settings = dict(
         blog_title=u"My guestbook",
         template_path=os.path.join(os.path.dirname(__file__), "templates"),
         static_path=os.path.join(os.path.dirname(__file__), "static"),
         xsrf_cookies=True,
         cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
         debug=True,
     )
     tornado.web.Application.__init__(self, handlers, **settings)
     self.db = torndb.Connection(
         host=options.mysql_host, database=options.mysql_database,
         user=options.mysql_user, password=options.mysql_password)
示例#21
0
 def __init__(self):
     handlers = [
         (r"/", IndexHandler),
     ]
     settings = dict(
         title="liebao_ads",
         template_path=os.path.join(os.path.dirname(__file__), "templates"),
         static_path=os.path.join(os.path.dirname(__file__), "static"),
         login_url="/login",
         debug=True,
     )
     super(Application, self).__init__(handlers, **settings)
     self.db = torndb.Connection(host=options.mysql_host,
                                 database=options.mysql_database,
                                 user=options.mysql_user,
                                 password=options.mysql_password)
示例#22
0
def database(fun, sql):
	try:
		db = torndb.Connection(host=settings["host"],
			database=settings['database'],
			user=settings["user"],
			password=settings["password"],
			time_zone=settings["timezone"])
		if fun == 0:
			return db.query(sql)
		else:
			db.execute(sql)
			return None
	except Exception as e:
		print sql
		print e
		print "-----------Connect Error Try Again..."
示例#23
0
 def __init__(self):
     handlers = [
         (r"/", IndexHandler),
     ]
     settings = dict(
         template_path=os.path.join(os.path.dirname(__file__), "templates"),
         static_path=os.path.join(os.path.dirname(__file__), "statics"),
         debug=True,
         autoescape=None,
         cookie_secret="2hcicVu+TqShDpfsjMWQLZ0Mkq5NPEWSk9fi0zsSt3A=",
         xsrf_cookies=True)
     super(Application, self).__init__(handlers, **settings)
     self.db = torndb.Connection(host="127.0.0.1",
                                 database="itcast",
                                 user="******",
                                 password="******")
示例#24
0
 def __init__(self):
     handlers = [
         (r"/", IndexHandler),
         (r"/todo/new", NewHandler),
         (r"/todo/(\d+)/edit", EditHandler),
         (r"/todo/(\d+)/delete", DeleteHandler),
         (r"/todo/(\d+)/finish", FinishHandler),
     ]
     settings = dict(template_path=TEMPLATE_PATH,
                     static_path=STATIC_PATH,
                     debug=True)
     tornado.web.Application.__init__(self, handlers, **settings)
     self.db = torndb.Connection(host=options.mysql_host,
                                 database=options.mysql_database,
                                 user=options.mysql_user,
                                 password=options.mysql_password)
示例#25
0
    def __init__(self):
        handlers = [
            (r"/", app.handlers.main.MainHandler),
            (r"/auth", app.handlers.auth.AuthHandler),
            (r"/project", app.handlers.project.ProjectHandler),
        ]
        settings = dict(debug=options.debug, )
        tornado.web.Application.__init__(self, handlers, **settings)

        # Connect from MySQL
        self.db = torndb.Connection(
            options.mysql_host,
            options.mysql_database,
            options.mysql_user,
            options.mysql_password,
        )
示例#26
0
    def __init__(self):
        handlers = [(r"/", HomeHandler), (r"/home/(.*)", WebHandler),
                    (r"/get_data", GetDataHandler), (r"/add_url", URLHandler)]
        settings = dict(
            app_title=u"Recipe Planner",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            #xsrf_cookies=False,
            cookie_secret="11oETzKXQAGaYdkL5gEmGeFJJuYh7EQnp2XdTP1o/Vo=",
            login_url="/")
        tornado.web.Application.__init__(self, handlers, **settings)

        self.db = torndb.Connection(host=options.mysql_host,
                                    database=options.mysql_database,
                                    user=options.mysql_user,
                                    password=options.mysql_password)
示例#27
0
    def __init__(self, *args, **kwargs):
        super(Application, self).__init__(*args, **kwargs)

        # self.db = torndb.Connection(
        #     host = mysql_options['host'],
        #     user = mysql_options['user'],
        #     password = mysql_options['password'],
        #     database = mysql_options['database']
        # )
        self.db = torndb.Connection(**mysql_options)

        # self.redis = redis.StrictRedis(
        #     host = redis_options['host'],
        #     port = redis_options['port']
        # )
        self.redis = redis.StrictRedis(**redis_options)
def get_data_from_db():
    log.info("Getting list of providers from database")
    db = torndb.Connection(conf.get('db_configs', 'host'),
                           conf.get('db_configs', 'db'),
                           conf.get('db_configs', 'user'),
                           conf.get('db_configs', 'pass'))

    query = """SELECT id as provider_id, 
                      provider as provider_name, 
                      end_point, 
                      status 
               FROM {db}.rtb_provider
               """.format(db=conf.get('db_configs', 'db'))

    result = db.query(query)
    return result if result else None
示例#29
0
    def __init__(self):
        songs_path = os.path.join(os.path.dirname(__file__), "songs")
        handlers = [
            (r"/", home.Index),
            (r"/user/create", user.Signup),
            (r"/user/login", user.Login),
            (r"/user/logout", user.Logout),
            (r"/songs/addNew/([0-9]+)", songs.AddNewSong),
            (r"/songs/verify", songs.OnSongVerify),
            (r'/songs/(.*)', tornado.web.StaticFileHandler, {
                'path': songs_path
            }),
            (r"/radio/([0-9a-z-]+)/([0-9]+)", radio.Home),
            (r"/radio", radio.Home),
            (r"/radio/playlist", radio.Playlist),
            (r"/radio/playlist/polling", radio.PlaylistPolling),
        ]
        settings = dict(
            blog_title=u"Tornado Blog",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            songs_path=os.path.join(os.path.dirname(__file__), "songs"),
            # ui_modules={"Entry": EntryModule},
            xsrf_cookies=True,
            # autoescape=False,
            cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
            login_url="/user/login",
            debug=True,
        )
        super(Application, self).__init__(handlers, **settings)

        self.mode = options.mode

        # Have one global connection to the blog DB across all handlers
        self.db = torndb.Connection(host=options.mysql_host,
                                    database=options.mysql_database,
                                    user=options.mysql_user,
                                    password=options.mysql_password)

        self.redis = redis.StrictRedis(host=options.redis_host,
                                       port=options.redis_port,
                                       db=0)

        with open("config.json") as json_file:
            self.config = json.load(json_file)

        self.initializePlaylist()
示例#30
0
def analysisPage(info,
                 dataDir=None,
                 gzCompile=re.compile("guanzhu\s*\(\s*'\s*(\d+)\s*'"),
                 blank_to_one=re.compile("\s+")):
    """
    收集信息
    gzCompile: 获取资源号 关注
    blank_to_one: 连续空格合并
    """
    url = info['url']
    soup = info["soup"]

    all_list = []
    cid = info['id']

    nhouse_list_content = soup.find("div", class_="nhouse_list_content")
    nl_con = nhouse_list_content.find("div", class_="nl_con")
    nlc_details = nl_con.findAll("div", class_="nlc_details")
    for nlc_detail in nlc_details:
        # 楼盘名 + 链接
        nlcd_name = nlc_detail.find("div", class_="nlcd_name")
        nlcd_name_a = nlcd_name.find("a")
        lp_name = nlcd_name_a.text.strip().replace(u" ", u"")
        lp_link = nlcd_name_a.attrs['href']
        # 资源ID
        guanzhu = nlc_detail.find("div", class_="guanzhu")
        gzOnclick = guanzhu.attrs["onclick"]
        gz_rid = gzCompile.findall(gzOnclick)
        gz_rid = gz_rid[0]
        # 地址
        address = nlc_detail.find("div", "address")
        district = address.text.strip().replace(u" ", u"")
        district = blank_to_one.sub(" ", district)

        brief = (cid, lp_name, lp_link, district, gz_rid)
        all_list.append(brief)

    conn = torndb.Connection(host="192.168.1.119",
                             database="data_transfer",
                             user="******",
                             password=passwd)
    for brief in all_list:
        sqlstring = 'REPLACE INTO lp_links(`cid`, `name`, `link`, `district`, `rid`) VALUES(%s, "%s", "%s", "%s", %s)' % brief
        conn.execute(sqlstring)
    conn.close()

    return True