Example #1
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
Example #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
Example #3
0
def submit(db):
	#1. 是否Enable,2.是否API设定好了
	if not needarchive(db) or not archiveapiok(db):
		return

	cc = getCC(db)
	db.execute('SELECT ID,URL FROM URLS WHERE IS_ARCHIVED=2')

	done = []
	for aid,url in db.getall():
		try:
			jobid = cc.snap(url)
			done.append( (aid,jobid) )
		except Exception,msg:
			if isinstance(msg,ccError):
				if msg.msgid == 100: #没有余额了
					db.execute('UPDATE SERVICES SET MSG=%s,ENABLED=0 WHERE SERVICE_ID=1',"服务余额不足,自动停用。请充值,然后启用服务!")
					db.commit()
			break
Example #4
0
def submit(db):
    #1. 是否Enable,2.是否API设定好了
    if not needarchive(db) or not archiveapiok(db):
        return

    cc = getCC(db)
    db.execute('SELECT ID,URL FROM URLS WHERE IS_ARCHIVED=2')

    done = []
    for aid, url in db.getall():
        try:
            jobid = cc.snap(url)
            done.append((aid, jobid))
        except Exception, msg:
            if isinstance(msg, ccError):
                if msg.msgid == 100:  #没有余额了
                    db.execute(
                        'UPDATE SERVICES SET MSG=%s,ENABLED=0 WHERE SERVICE_ID=1',
                        "服务余额不足,自动停用。请充值,然后启用服务!")
                    db.commit()
            break
Example #5
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
Example #6
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
Example #7
0
def my(db):
	def getparams():
		#返回catid(str),pageno
		cid = int(request.GET.get('cid','0'))
		pn = int(request.GET.get('pn','1'))
		tag = request.GET.get('tag','').lower()
		return cid,pn,tag
	def buildurl(cid,tag,pn):
		url = '/my/'
		v = []
		if cid:
			v.append('cid=%s' % cid)
		if tag:
			v.append('tag=%s' % tag)
		if pn != 0:
			v.append('pn=%s' % pn)
		if v:
			return url+'?'+'&'.join(v)
		return url
	def buildtagurl(cid,tag):
		url = '/my/'
		v = []
		if cid:
			v.append('cid=%s' % cid)
		if tag:
			v.append('tag=%s' % urllib.quote(tag))
		if v:
			return url+'?'+'&'.join(v)
		return url

	updatemsg = versionupdated(db)
	curcid,curpn,curtag = getparams() #当前的catid,当前的curpn,当前的书签.
	#---列出全部的类目信息以及书签---
	data = []
	cats = defaultdict(int) #已经被使用的Category{id:count}
	alltags = set()

	for urlid,cid,url,title,tags,notes,pt,thisarchive,isheart in getUrls(db):
		cats[cid] += 1

		for x in tags:
			alltags.add('"%s"' % x.replace('"','\\"'))

		#选择了类目的
		if curcid and curcid != cid: continue
		#选择了Tag
		if curtag and (curtag not in tags): continue

		thistags = []
		for t in tags:
			thistags.append( (t,buildtagurl(0,t)) ) #全局的Tag

		data.append( (urlid,url,title,cid,tags,notes,pt,thistags,isheart,thisarchive) )

	if not data: #没有数据
		if curcid or curtag: #可能是这个目录/Tag下没了(最后一条)
			redirect("/my/")

	categorys = [] #[ [(url,title,count)] ]  #全部有数据的Category的信息.
	allcats   = {} #全部的Category信息.
	emptycats = {} #空的Category信息

	if cats: #用户全部的有效目录信息.
		defaultcatid = 0
		for cid,title in getCategory(db):
			defaultcatid = cid

			allcats[cid]=title
			if cid not in cats: #有收藏的
				emptycats[cid]=title

		#这里按照真正的categoryid排下,免得出现不断位置排列的问题.
		v = [(count,catid) for catid,count in cats.iteritems()]
		v.sort(reverse=True)
		tmp = []
		for count,catid in v:
			if catid not in allcats: continue #有这个发生,就说明用户删除了含有收藏的收藏夹.
			tmp.append( (buildurl(catid,'',0),allcats[catid],count) )
			if len(tmp) == 6:
				categorys.append(tmp)
				tmp = []
		if tmp:
			cnt = 6 - len(tmp)
			for x in xrange(cnt):
				tmp.append( ('',0,0) )
			categorys.append(tmp)
		#--禁止删除默认收藏夹--
		if defaultcatid in emptycats:
			del emptycats[defaultcatid]
	#计算pagecount	
	pagecount = 1+(len(data)-1)/RECORD_PER_PAGE
	prevurl = buildurl(curcid,curtag,curpn-1)
	nexturl = buildurl(curcid,curtag,curpn+1)

	pages = (curpn,pagecount,prevurl,nexturl)

	s = RECORD_PER_PAGE*(curpn-1)
	bookmarks = data[s:s+RECORD_PER_PAGE]

	ret = template('my',
		categorys=categorys, #当前已经有收藏的收藏夹
		curcatinfo=(allcats.get(curcid,''),len(data)),
		allcategorys=allcats,
		emptycategorys=emptycats,
		bookmarks=bookmarks,
		pages=pages,
		updatemsg=updatemsg,
		disabled = not needarchive(db),
		tags=','.join(list(alltags)))
	return ret