Exemplo n.º 1
0
def modifyHost(hid,hostname,city,project,idc,port,addr1_ip,addr1_netmask,addr1_gateway,addr1_line,addr2_ip,addr2_netmask,addr2_gateway,addr2_line,addr3_ip,addr3_netmask,addr3_gateway,addr3_line,memory,cpu,disk,buytime,servicetime,hardwareinfo,bandwidth,uses,status,company,os,other,modifytime,modifyman):
		# Check the ip address exists?
	if addr1_ip != '':
		result = db.query("SELECT hid FROM `hosts` WHERE addr1_ip='%s' OR addr2_ip='%s' OR addr3_ip='%s'" % (addr1_ip, addr1_ip, addr1_ip))
		if result:
			return 'addr'
	if addr2_ip != '':
		result = db.query("SELECT hid FROM `hosts` WHERE addr1_ip='%s' OR addr2_ip='%s' OR addr3_ip='%s'" % (addr2_ip, addr2_ip, addr2_ip))
		if result:
			return 'addr'
	if addr3_ip != '':
		result = db.query("SELECT hid FROM `hosts` WHERE addr1_ip='%s' OR addr2_ip='%s' OR addr3_ip='%s'" % (addr3_ip, addr3_ip, addr3_ip))
		if result:
			return 'addr'
	# Check hostname exists?
	if hostname != '':
		result = db.query("SELECT hid FROM hosts WHERE hostname = '%s'" % (hostname))
		if result:
			return 'hostname'
	
	#result = db.query("SELECT hid FROM hosts WHERE hostname = '%s' AND hid != '%s'" % (hostname, hid))
	#if result:
	#	return False
	#else:
	db.update("hosts", where='hid=$hid', vars={'hid':hid}, hostname=hostname,city=city,project=project,idc=idc,port=port,addr1_ip=addr1_ip,addr1_netmask=addr1_netmask,addr1_gateway=addr1_gateway,addr1_line=addr1_line,addr2_ip=addr2_ip,addr2_netmask=addr2_netmask,addr2_gateway=addr2_gateway,addr2_line=addr2_line,addr3_ip=addr3_ip,addr3_netmask=addr3_netmask,addr3_gateway=addr3_gateway,addr3_line=addr3_line,memory=memory,cpu=cpu,disk=disk,buytime=buytime,servicetime=servicetime,hardwareinfo=hardwareinfo,bandwidth=bandwidth,uses=uses,status=status,company=company,os=os,other=other,modifytime=modifytime,modifyman=modifyman)
	return True
Exemplo n.º 2
0
def set_score_value(resource_id, score_type):
    "设置用户评分"

    #首先还要记录hotrank分值
    hotrank_addend = 0
    if score_type == "score_like":
        hotrank_addend = "+" + str(1 * hotrank_weighted)
    elif score_type == "score_bury":
        hotrank_addend = str(-1 * hotrank_weighted)
    #更新hotrank分值,更新用户"顶/踩"的数据
    sql_query = "update " + alldbname + " set " + score_type + "= " + score_type + "+1, hotrank=hotrank" + hotrank_addend + " where resource_id=" + resource_id
    db.query(sql_query)
Exemplo n.º 3
0
def restoreHistory(hid):
	content = db.query("SELECT content FROM history WHERE hid = %s" % hid)
	try:
		sql = content[0]['content']
		result = db.query("%s" % sql)
	except:
		return False

	if result:
		return True
	else:
		return False
Exemplo n.º 4
0
def _memchache_get_records(sql_query, time=5):
    "memcache缓存,time默认为5分钟"

    #hash一下,为了key键分布更均衡
    key = md5(sql_query.encode('UTF-16')).hexdigest()
    res = mc.get(key)
    if not res:
        res = db.query(sql_query).list()
        mc.set(key, res, 60 * time)  #存100分钟

    res = db.query(sql_query).list()
    return res
Exemplo n.º 5
0
def set_score_value(resource_id, score_type):
    "设置用户评分"
    
    #首先还要记录hotrank分值
    hotrank_addend = 0;
    if score_type == "score_like":
        hotrank_addend = "+" + str(1 * hotrank_weighted)
    elif score_type == "score_bury":
        hotrank_addend = str(-1 * hotrank_weighted)
    #更新hotrank分值,更新用户"顶/踩"的数据
    sql_query = "update " + alldbname +" set " + score_type + "= " + score_type + "+1, hotrank=hotrank" + hotrank_addend + " where resource_id=" + resource_id
    db.query(sql_query)
Exemplo n.º 6
0
def _memchache_get_records(sql_query, time = 5):
    "memcache缓存,time默认为5分钟"
    
    #hash一下,为了key键分布更均衡
    key = md5(sql_query.encode('UTF-16')).hexdigest()
    res = mc.get(key)
    if not res:
        res = db.query(sql_query).list()
        mc.set(key, res, 60 * time) #存100分钟

    res = db.query(sql_query).list()
    return res
Exemplo n.º 7
0
def modifyProject(pid,project,other):
	result = db.query("SELECT pid FROM project WHERE project = '%s' AND pid != '%s'" % (project,pid))
	if result:
		return False
	else:
		db.update("project", where='pid=$pid', vars={'pid': pid}, project=project ,other=other)
		return True
Exemplo n.º 8
0
def insert_city(city, other):
	result = db.query("SELECT cid FROM `city` WHERE city='%s'" % (city))	
	if result:
		return False
	else:
		db.insert('city', city=city, other=other)
		return True
Exemplo n.º 9
0
def modifyIDC(iid,idcname,city,contact,hztime,other):
	result = db.query("SELECT iid FROM idc WHERE idcname = '%s' AND iid != '%s'" % (idcname, iid))
	if result:
		return False
	else:
		db.update("idc", where='iid=$iid', vars={'iid': iid}, idcname=idcname, city=city, contact=contact, hztime=hztime,other=other)
		return True
Exemplo n.º 10
0
def insert_idc(idcname,city, contact,hztime, other):
	result = db.query("SELECT iid FROM `idc` WHERE idcname='%s'" % (idcname))
	if result:
		return False
	else:
		db.insert('idc', idcname=idcname, city=city, contact=contact,hztime=hztime, other=other)
		return True
Exemplo n.º 11
0
def modifyApply(aid,sitename,idc,project,addr_ip,sofeware,datadir,startscrite,port,mysql_conf,mysql_ip,mysql_stype,mysql_name,mysql_use,mysql_pw,dev_name,other,modifytime,modifyman):
	if addr_ip != '':
		result = db.query("SELECT aid FROM applications WHERE sitename = '%s' AND addr_ip = '%s'" % (sitename,addr_ip))
		if result:
			return False
	db.update("applications", where='aid=$aid', vars={'aid':aid}, sitename=sitename,idc=idc,project=project,addr_ip=addr_ip,sofeware=sofeware,datadir=datadir,startscrite=startscrite,port=port,mysql_conf=mysql_conf,mysql_ip=mysql_ip,mysql_stype=mysql_stype,mysql_name=mysql_name,mysql_use=mysql_use,mysql_pw=mysql_pw,dev_name=dev_name,other=other,modifytime=modifytime,modifyman=modifyman)
	return True
Exemplo n.º 12
0
def modifyCity(cid, city, other):
	result = db.query("SELECT cid FROM city WHERE city = '%s' AND cid != '%s'" % (city, cid))
	if result:
		return False	
	else:
		db.update("city", where='cid=$cid', vars={'cid': cid}, city=city, other=other)
		return True
Exemplo n.º 13
0
def get_comic_aka_name_by_id(comic_id):
    query_sql = 'select aka_name from ' + ComicResource + ' where comic_id = ' + str(comic_id)
    aka_name = db.query(query_sql)
    try:
        return aka_name[0]['aka_name']
    except:
        return "抱歉,收录漫画与ID不符"
Exemplo n.º 14
0
def get_comic_url_by_id(comic_id, vol, capture, is_local_back = 1):
    "根据传入的comic_id,vol,capture搜寻合适的URL返回"
    query_sql = ''
    if int(vol) > 0:
        query_sql = 'select url from ' + ComicURL + ','  + ComicResource + \
            ' where ' + ComicURL + '.vol=' + str(vol) + ' and ' + ComicURL + \
            '.comic_id = ' + ComicResource + '.comic_id and ' + ComicResource + '.comic_id =' + str(comic_id) + \
            ' and ' + ComicURL + '.is_local_back =' + str(is_local_back) + ' order by page ASC'
    if int(capture) > 0:
        query_sql  = 'select url from ' + ComicURL + ', '  + ComicResource + \
            ' where ' + ComicURL + '.capture=' + str(capture) + ' and ' + ComicURL + \
            '.comic_id = ' + ComicResource + '.comic_id and ' + ComicResource + '.comic_id =' + str(comic_id) + \
            ' and ' + ComicURL + '.is_local_back =' + str(is_local_back) + ' order by page ASC'
    
    db.query('update ' + ComicResource + ' set hotrank = hotrank + 1 where comic_id =' + str(comic_id))
    return _memchache_get_records(query_sql)
Exemplo n.º 15
0
def insert_project(project, other):
	result = db.query("SELECT pid FROM `project` WHERE project='%s'" % (project))
	if result:
		return False
	else:	
		db.insert('project', project=project, other=other)
		return True
Exemplo n.º 16
0
def getUserInfo(username):
	try:
		#results = db.select('users', where="username=$username")
		results = db.query("SELECT * FROM `users` WHERE username='******'" % (username))
		return results[0]
	except IndexError:
		return 0
Exemplo n.º 17
0
def hasUser(username):
	try:
		results = db.query("SELECT uid FROM `users` WHERE username='******'" % (username))
		#return results[0]
		if results:
			return 1
	except IndexError:
		return 0
Exemplo n.º 18
0
 def GET(self):
     comic_aka_name = web.input().comic_aka_name
     regurl = web.input().comicurl
     vol_no = web.input().vol
     capture_no = web.input().capture
     totalpages = web.input().totalpages
     vol_capture_name = web.input().volcapturename
     begin_page_no = web.input().beginpageno
     
     comic_id = -1
     res = db.query('select * from ' + ComicResource + ' where aka_name="' + comic_aka_name + '"').list()
     try:
         comic_id = res[0]['comic_id']
     except:
         #没有这部漫画,先插入
         db.insert(ComicResource, aka_name= comic_aka_name, hotrank = 10)
         comic_id = db.query('select * from ' + ComicResource + ' where aka_name="' + comic_aka_name + '"').list()[0]['comic_id']
     
     urllist = []
     try:
         page_url_no_length = int(regurl[regurl.find('*') + 1])
     except:
         return render.error('地址格式错误!', '/createcomicpage')
     
     for i in xrange(int(begin_page_no), int(totalpages) + int(begin_page_no)):
         strformat = "%0" + str(page_url_no_length) + "d"
         stri = strformat % (i,)
         stri = str(stri)
         striV2 = "%03d" %(i - int(begin_page_no) + 1)
         url = regurl[:regurl.find('*') - 1] + stri + regurl[regurl.find('*') + 3:]
         urlV2 = ''
         if int(vol_no) > 0:
             urlV2 = backregurl + comic_aka_name + '/vol_' + str(vol_no) + '/' + striV2  + regurl[regurl.find('*') + 3:].lower()
         elif int(capture_no) > 0:
             urlV2 = backregurl + comic_aka_name + '/capture_' + str(capture_no) + '/' + striV2 + regurl[regurl.find('*') + 3:].lower()
         urllist.append(url)
         try:
             db.insert(ComicURL.replace('V2', ''), vol = vol_no, capture = capture_no, 
                       page = i, url = url, comic_id = comic_id, quality_rank = 0, vol_capture_name = vol_capture_name)
             db.insert(ComicURL.replace('V2', '') + 'V2', vol = vol_no, capture = capture_no, 
                       page = i, url = urlV2, comic_id = comic_id, quality_rank = 0, vol_capture_name = vol_capture_name)                
         except:
             return render.error('URL已经录入,重复!', '/createcomicpage')
         
     #搞定了,返回一个OK页面
     return render.ok(urllist)
Exemplo n.º 19
0
def getcount(table, column='*', where='', group=''):
    sql = 'select count(' + column + ') as total_count from ' + table
    if where != '':
        sql += ' where ' + where
    if group != '':
        sql += ' group by ' + group
    results = db.query(sql)
    return results[0].total_count
Exemplo n.º 20
0
def get_user_cootoken(qq_name, qq_uid):
    "根据qget_user_cootokentoken,目前什么也不做,记录uid一下"
    cootoken = qq_uid
    try:
        cootoken = db.query('select * from ' + ComicUserinfo + ' where qq_uid="' + qq_uid + '"').list()[0]['cootoken']
    except:
        #数据库中没有这个用户
        db.insert(ComicUserinfo, qq_name = qq_name, qq_uid = qq_uid, cootoken = cootoken)
    return cootoken
Exemplo n.º 21
0
def get_user_browsehistory(cootoken):
    """
                    根据传入的cootoken查找用户历史记录
                    格式:<storage[{'comic_id':'2', 'akaname':'海贼王', 'vol':'2', 'capture':'-1', 'browse_time':'2012-03-19'}...]>
    """
    query_str = 'select distinct(' + ComicUserbrowseHistory + r'.history) as history from ' + ComicUserbrowseHistory + ',' + ComicUserinfo + \
                    ' where ' + ComicUserbrowseHistory + r'.uid=' + ComicUserinfo + r'.uid and ' + ComicUserinfo + \
                    r'.cootoken="' + str(cootoken) + r'" order by browse_time DESC limit ' + str(user_browse_history_limit)
    return db.query(query_str).list()
Exemplo n.º 22
0
    def GET(self):

        return '此功能已关闭'
        comic_id = web.input().comic_id        
        
        res = db.query('select * from ' + ComicResource + ' where comic_id="' + comic_id + '"').list()
        comic_aka_name = res[0]['aka_name']
        vol_no, min_capture, max_capture = mirrordb.get_comic_length(int(comic_id))
        
        #如果是卷
        if vol_no > 0:
            for vol in xrange(1, vol_no + 1):
                #先获取每一卷的totalpages
                totalpages = db.query('select  count(page) as count_page from CooComicServerComicURL where comic_id=' + 
                                      str(comic_id) + ' and vol=' + str(vol) + ' group by vol')[0]['count_page']
                for i in xrange(1, int(totalpages) + 1):
                    stri = '%03d' %(i)                
                    url = backregurl + comic_aka_name + '/vol_' + str(vol) + '/' + stri + '.jpg'
                    try:
                        #这里改一下数据库
                        db.insert(ComicURL + 'V2', vol = vol, capture = -1, 
                                  page = stri, url = url, comic_id = comic_id, quality_rank = 0)
                    except:
                        return 'URL已经录入,重复!'
                
        #话
        if min_capture > 0:
            for capture in xrange(min_capture, max_capture + 1):
                #先获取每一话的totalpages
                totalpages = db.query('select  count(page) as count_page from CooComicServerComicURL where comic_id=' + 
                                      str(comic_id) + ' and capture=' + str(capture) + ' group by capture')[0]['count_page']
                for i in xrange(1, int(totalpages) + 1):
                    stri = '%03d' %(i)                
                    url = backregurl + comic_aka_name + '/capture_' + str(capture) + '/' + stri + '.jpg'
                    try:
                        #这里改一下数据库
                        db.insert(ComicURL + 'V2', vol = -1, capture = capture, 
                                  page = stri, url = url, comic_id = comic_id, quality_rank = 0)
                    except:
                        return 'URL已经录入,重复!'
            
        #搞定了,返回一个OK页面
        return 'OK'
Exemplo n.º 23
0
def set_user_browsehistory(cootoken, history):
    """
                    根据传入的cootoken设置用户历史记录
                    格式:{'comic_id':'2', 'akaname':'海贼王', 'vol':'2', 'capture':'-1'}
    """
    try:
        uid = db.query('select * from ' + ComicUserinfo + ' where cootoken="' + str(cootoken) + '"').list()[0]['uid']
        db.insert(ComicUserbrowseHistory, uid = uid, history = history).list()
    except:
        #没有这个用户
        pass
Exemplo n.º 24
0
def insert_apply(sitename,idc,project,addr_ip,sofeware,datadir,startscrite,port,mysql_conf,mysql_ip,mysql_stype,mysql_name,mysql_use,mysql_pw,dev_name,other,jointime,modifytime,modifyman):

	# Check the ip address exists?
	if addr_ip != '':
		result = db.query("SELECT aid FROM `applications` WHERE addr_ip='%s' AND sitename='%s'"  % (addr_ip,sitename))
		if result:
			return False

	# If not enter the ip address, also saved to database.
	db.insert('applications',sitename=sitename,idc=idc,project=project,addr_ip=addr_ip,sofeware=sofeware,datadir=datadir,startscrite=startscrite,port=port,mysql_conf=mysql_conf,mysql_ip=mysql_ip,mysql_stype=mysql_stype,mysql_name=mysql_name,mysql_use=mysql_use,mysql_pw=mysql_pw,dev_name=dev_name,other=other,jointime=jointime,modifytime=modifytime,modifyman=modifyman)
	return True
Exemplo n.º 25
0
def update_project(pid, project_name, project_descrip, html):
    query_str = r'''update item i, project p 
                  set i.title='%s', i.text='%s', i.html='%s', i.update_date='%s' 
                  where p.id=%s and p.name=i.title and i.pid=99''' % (project_name.replace("'", "\\'"), 
                                                                      project_descrip.replace("'", "\\'"), 
                                                                      html.replace("'", "\\'"), 
                                                                      now(), pid)
#    print query_str
    item_rlt = db.query(query_str)
    project_rlt = db.update('project', name=project_name, update_date=now(), where='id=%s' % pid)
    if item_rlt and project_rlt:
        return True
    else:
        return False
Exemplo n.º 26
0
def insert_host(hostname,city,project,idc,port,addr1_ip,addr1_netmask,addr1_gateway,addr1_line,addr2_ip,addr2_netmask,addr2_gateway,addr2_line,addr3_ip,addr3_netmask,addr3_gateway,addr3_line,memory,cpu,disk,buytime,servicetime,hardwareinfo,bandwidth,uses,status,company,os,other,jointime,modifytime,modifyman):

	# Check the ip address exists?
	if addr1_ip != '':
		result = db.query("SELECT hid FROM `hosts` WHERE addr1_ip='%s' OR addr2_ip='%s' OR addr3_ip='%s'" % (addr1_ip, addr1_ip, addr1_ip))
		if result:
			return 'addr'
	if addr2_ip != '':
		result = db.query("SELECT hid FROM `hosts` WHERE addr1_ip='%s' OR addr2_ip='%s' OR addr3_ip='%s'" % (addr2_ip, addr2_ip, addr2_ip))
		if result:
			return 'addr'
	if addr3_ip != '':
		result = db.query("SELECT hid FROM `hosts` WHERE addr1_ip='%s' OR addr2_ip='%s' OR addr3_ip='%s'" % (addr3_ip, addr3_ip, addr3_ip))
		if result:
			return 'addr'
	# Check hostname exists?
	if hostname != '':
		result = db.query("SELECT hid FROM hosts WHERE hostname = '%s'" % (hostname))
		if result:
			return 'hostname'

	# If not enter the ip address, also saved to database.
	db.insert('hosts',hostname=hostname,city=city,project=project,idc=idc,port=port,addr1_ip=addr1_ip,addr1_netmask=addr1_netmask,addr1_gateway=addr1_gateway,addr1_line=addr1_line,addr2_ip=addr2_ip,addr2_netmask=addr2_netmask,addr2_gateway=addr2_gateway,addr2_line=addr2_line,addr3_ip=addr3_ip,addr3_netmask=addr3_netmask,addr3_gateway=addr3_gateway,addr3_line=addr3_line,memory=memory,cpu=cpu,disk=disk,buytime=buytime,servicetime=servicetime,hardwareinfo=hardwareinfo,bandwidth=bandwidth,uses=uses,status=status,company=company,os=os,other=other,jointime=jointime,modifytime=modifytime,modifyman=modifyman)
	return True
Exemplo n.º 27
0
def get_extern_info(resource_info_id = -1):
    "获取资源的详细信息"
    res =  db.query('select * from ' + infodbname + ' where resource_info_id =' + str(resource_info_id)).list()
    return res
Exemplo n.º 28
0
def get_score_value(resource_id, score_type):
    "获取用户评分"
    sql_query = "select " + score_type + " from " + alldbname + " where resource_id=" + resource_id
    res =   db.query(sql_query).list()[0]
    return str(res[score_type])
Exemplo n.º 29
0
def query(query_string):
    return db.query(query_string)
Exemplo n.º 30
0
def getStatusOverView():
	result = db.query("select distinct hosts.status as sid,status.status,count(hosts.status) as total from hosts,status where hosts.status = status.sid group by hosts.status")
	return result
Exemplo n.º 31
0
def get_score_value(resource_id, score_type):
    "获取用户评分"
    sql_query = "select " + score_type + " from " + alldbname + " where resource_id=" + resource_id
    res = db.query(sql_query).list()[0]
    return str(res[score_type])
Exemplo n.º 32
0
def getHistory():
	result = db.query("SELECT * FROM history ORDER BY deltime desc")
	return result
Exemplo n.º 33
0
def get_extern_info(resource_info_id=-1):
    "获取资源的详细信息"
    res = db.query('select * from ' + infodbname +
                   ' where resource_info_id =' + str(resource_info_id)).list()
    return res
Exemplo n.º 34
0
def ChangeUserPWD(user,pwd):
	db.query("UPDATE `users` SET `password` = '%s' WHERE `username` = '%s'" %  (pwd,user))