Beispiel #1
0
def update(db):
	bid = int(request.POST.get('bookmarkid',''))
	cid = int(request.POST.get('category','0'))
	title = request.POST.get('title','')
	tag = request.POST.get('tag','')
	notes = request.POST.get('notes','')

	if ulen(title) > 512: return {'error' : '你对标题也太有爱了 这么长的标题'}
	if ulen(tag) > 1024: return {'error' : '你的标签太有爱了 这么丰富的'}
	if ulen(notes) > 1024: return {'error' : '你的备注也超长的,您一定是细心的人'}

	tag = refineTag(tag)
	#检查这个书签是否存在
	db.execute('SELECT CATEGORY_ID,URL FROM URLS WHERE ID=%s',bid)
	v = db.getone()
	if not v:
		return {'noauth' : 1}
	catid,url = v
	isnewcat = (cid != int(catid))
	if isnewcat: #变更类目了
		#检查这个catid是否存在
		db.execute('SELECT 1 FROM CATEGORY WHERE ID=%s',cid)
		v = db.getone()
		if not v:
			return {'noauth' : 1}
	if isnewcat:
		db.execute('UPDATE URLS SET CATEGORY_ID=%s,TITLE=%s,TAG=%s,NOTES=%s WHERE ID=%s',(cid,title,tag,notes,bid))
	else:
		db.execute('UPDATE URLS SET TITLE=%s,TAG=%s,NOTES=%s WHERE ID=%s',(title,tag,notes,bid))
	db.commit()
	return {'ok':1}
Beispiel #2
0
def jstie(db):
    """
		新版本的Tie过程
	"""
    url = request.GET.get('url', '').strip()
    title = request.GET.get('title', '').strip()
    tag = request.GET.get('tag', '').strip()
    catid = int(request.GET.get('category', '').strip())
    notes = request.GET.get('notes', '').strip()
    isheart = request.GET.get('heart', '').strip()

    if not url or isdeny(url):
        #返回1x1的数据,表示正确,实为吞没
        response['Content-Type'] = 'image/png'
        return png_1x1

    if ulen(url) > 1024: url = ulenget(url, 1024)
    if ulen(title) > 1024: title = ulenget(title, 1024)
    if tag:
        tag = refineTag(tag)
        if ulen(tag) > 1024: tag = ulenget(tag, 1024)
    if ulen(notes) > 1024: notes = ulenget(notes, 1024)

    try:
        catid = int(catid)
        #检查这个catid是否存在
        db.execute('SELECT ID FROM CATEGORY WHERE ID=%s', catid)
        v = db.getone()
        if not v: raise Exception("invalid catid param")  #非法用户插入,选用默认的结果.
    except:
        catid = getdefaultcatid(db)

    heart = 0
    if isheart: heart = 1
    shortid = 0
    if url:
        shortid = getshorturlid(url)

    db.execute(
        'INSERT INTO URLS(IS_HEART,IS_ARCHIVED,ARCHIVED_OK,CATEGORY_ID,URL,SHORT_URL_ID,TITLE,TAG,NOTES,TIE_TIME) VALUES(%s,0,0,%s,%s,%s,%s,%s,%s,%s)',
        (heart, catid, url, shortid, title, tag, notes, nt()))
    recordid = db.insert_id()

    if needarchive(db) and archiveapiok(db) and url:
        db.execute('UPDATE URLS SET IS_ARCHIVED=2 WHERE ID=%s', recordid)

    db.commit()
    response['Content-Type'] = 'image/png'
    return png_1x1
Beispiel #3
0
def jstie(db):
	"""
		新版本的Tie过程
	"""
	url = request.GET.get('url','').strip()
	title = request.GET.get('title','').strip()
	tag = request.GET.get('tag','').strip()
	catid = int(request.GET.get('category','').strip())
	notes = request.GET.get('notes','').strip()
	isheart = request.GET.get('heart','').strip()

	if not url or isdeny(url):
		#返回1x1的数据,表示正确,实为吞没
		response['Content-Type'] = 'image/png'
		return png_1x1

	if ulen(url) > 1024: url = ulenget(url,1024)
	if ulen(title) > 1024: title=ulenget(title,1024)
	if tag:
		tag = refineTag(tag)
		if ulen(tag) > 1024: tag = ulenget(tag,1024)
	if ulen(notes) > 1024: notes= ulenget(notes,1024)

	try:
		catid = int(catid)
		#检查这个catid是否存在
		db.execute('SELECT ID FROM CATEGORY WHERE ID=%s',catid)
		v = db.getone()
		if not v: raise Exception("invalid catid param") #非法用户插入,选用默认的结果.
	except:
		catid = getdefaultcatid(db)

	heart = 0
	if isheart: heart = 1
	shortid = 0
	if url:
		shortid = getshorturlid(url)

	db.execute('INSERT INTO URLS(IS_HEART,IS_ARCHIVED,ARCHIVED_OK,CATEGORY_ID,URL,SHORT_URL_ID,TITLE,TAG,NOTES,TIE_TIME) VALUES(%s,0,0,%s,%s,%s,%s,%s,%s,%s)',(heart,catid,url,shortid,title,tag,notes,nt()))
	recordid = db.insert_id()

	if needarchive(db) and archiveapiok(db) and url:
		db.execute('UPDATE URLS SET IS_ARCHIVED=2 WHERE ID=%s',recordid)

	db.commit()
	response['Content-Type'] = 'image/png'
	return png_1x1
Beispiel #4
0
def getUrls(db):
    #得到全部合法URL列表
    #返回的数据列表
    #1. urlid
    #2. categoryid
    #3. url
    #4. title
    #5. tag数组
    #6. notes
    #7. posttime(字符串) 2013-01-01格式
    #8. 此条的Archive状态(int)(-1:用户无权限,0:没提交的,1:提交了正在Archiving,2:等待提交Archining,3:Archived完成了)
    #9. isheart (int)
    data = []
    iscan = needarchive(db) and archiveapiok(db)

    db.execute(
        'SELECT ID,CATEGORY_ID,URL,TITLE,TAG,NOTES,TIE_TIME,IS_HEART,IS_ARCHIVED,ARCHIVED_OK FROM URLS ORDER BY ID DESC'
    )
    for urlid, cid, url, title, tag, notes, pt, isheart, isarchive, archivedok in db.getall(
    ):
        tag = refineTag(tag).lower()
        tags = [x for x in tag.split(',') if x]

        notes = "\n  ".join(
            filter(None, re.split("\n|\r", html_escape(notes))))

        if iscan:
            thisarchive = 0  #用户开启
        else:
            thisarchive = -1  #用户未启用Archive的
        if int(archivedok) == 1:  #说明提交并完成了的
            thisarchive = 3  #可以看Archive结果了
        elif int(isarchive) in [1, 2]:  #提交了,还未成功的/正在等待提交的
            thisarchive = int(isarchive)  #running中

        data.append(
            (int(urlid), int(cid), url, title, tags, notes, pt, thisarchive,
             int(isheart)))
    return data
Beispiel #5
0
def apigetbookmark(db):
	"""
		得到某个书签的详细信息
		参数为bookmarkid
	"""
	bid = request.POST.get('bookmarkid','')
	try:
		bid = int(bid)
	except:
		return {'error' : '参数错误'}

	#检查这书签是否存在
	db.execute('SELECT CATEGORY_ID,TITLE,URL,TAG,NOTES FROM URLS WHERE ID = %s' % bid)
	v = db.getone()
	if not v:
		return {'noauth' :1}

	cid,title,url,tag,notes =v
	return {'ok':1,
			'id':bid,'cid':cid,
			'title':title,'url':url,
			'tag':refineTag(tag).lower(),
			'notes':notes}
Beispiel #6
0
 def processline(self, line):
     line = line.strip()
     if line.find('<DT><H3') == 0:  #开始一个新的Category了.
         n = self.getcatname(line)
         if not self.curcat:
             if n: self.curcat = {'title': n, 'links': []}
             else: self.curcat = {'title': '空目录名', 'links': []}
             self.cats.append(self.curcat)
         else:
             self.tags.append(n)  #增加到Tag中
     elif line == '<DL><p>':  #进入Category
         pass
     elif line == '</DL><p>':  #退出Category
         if self.tags:
             self.tags.pop()
         else:
             self.curcat = None
     elif line.find('<DT><A') == 0:  #一个Link
         if not self.curcat: return
         v = self.getlink(line)
         if not v: return
         title, href = v
         link = (title, href, refineTag(','.join(self.tags)))
         self.curcat['links'].append(link)
Beispiel #7
0
def getUrls(db):
	#得到全部合法URL列表
	#返回的数据列表
	#1. urlid
	#2. categoryid
	#3. url
	#4. title
	#5. tag数组
	#6. notes
	#7. posttime(字符串) 2013-01-01格式
	#8. 此条的Archive状态(int)(-1:用户无权限,0:没提交的,1:提交了正在Archiving,2:等待提交Archining,3:Archived完成了)
	#9. isheart (int)
	data = []
	iscan = needarchive(db) and archiveapiok(db)

	db.execute('SELECT ID,CATEGORY_ID,URL,TITLE,TAG,NOTES,TIE_TIME,IS_HEART,IS_ARCHIVED,ARCHIVED_OK FROM URLS ORDER BY ID DESC')
	for urlid,cid,url,title,tag,notes,pt,isheart,isarchive,archivedok in db.getall():
		tag = refineTag(tag).lower()
		tags = [x for x in tag.split(',') if x]
		
		notes =	"\n&nbsp;&nbsp;".join(filter(None,re.split("\n|\r",html_escape(notes))))

		if iscan:
			thisarchive = 0  #用户开启
		else:
			thisarchive = -1 #用户未启用Archive的
		if int(archivedok) == 1: #说明提交并完成了的
			thisarchive = 3 #可以看Archive结果了
		elif int(isarchive) in [1,2]: #提交了,还未成功的/正在等待提交的
			thisarchive = int(isarchive) #running中

		data.append((
			int(urlid),int(cid),
			url,title,tags,notes,pt,
			thisarchive,int(isheart) ))
	return data
Beispiel #8
0
	def processline(self,line):
		line = line.strip()
		if line.find('<DT><H3')==0: #开始一个新的Category了.
			n = self.getcatname(line)
			if not self.curcat:
				if n: self.curcat = {'title':n,'links':[]}
				else: self.curcat = {'title':'空目录名','links':[]}
				self.cats.append(self.curcat)
			else:
				self.tags.append(n) #增加到Tag中
		elif line == '<DL><p>': #进入Category
			pass
		elif line == '</DL><p>': #退出Category
			if self.tags:
				self.tags.pop()	
			else:
				self.curcat = None
		elif line.find('<DT><A') == 0: #一个Link
			if not self.curcat: return
			v = self.getlink(line)
			if not v: return
			title,href = v
			link = (title,href,refineTag(','.join(self.tags)))
			self.curcat['links'].append(link)