Esempio n. 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
Esempio n. 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
Esempio n. 3
0
def getdata(db):
	if not archiveapiok(db):
		return

	cc= getCC(db)
	db.execute('SELECT ID,JOB_ID FROM URLS WHERE IS_ARCHIVED=1 AND ARCHIVED_OK = 0')

	done = []
	for aid,jobid in db.getall():
		try:
			if cc.isfinished(jobid):
				#去获取结果了
				name = os.path.join(ARCHIVED_DIR,"%s.dat" % aid)
				cc.get2file(jobid,name)
				done.append( aid )
		except Exception,msg:
			pass
Esempio n. 4
0
def getdata(db):
    if not archiveapiok(db):
        return

    cc = getCC(db)
    db.execute(
        'SELECT ID,JOB_ID FROM URLS WHERE IS_ARCHIVED=1 AND ARCHIVED_OK = 0')

    done = []
    for aid, jobid in db.getall():
        try:
            if cc.isfinished(jobid):
                #去获取结果了
                name = os.path.join(ARCHIVED_DIR, "%s.dat" % aid)
                cc.get2file(jobid, name)
                done.append(aid)
        except Exception, msg:
            pass
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 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  ".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
Esempio n. 8
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