Exemple #1
0
def is_exist_url(url):
	session=connection.init_db()
	query=session.query(Article)
	aritcle=query.filter(Article.art_url == url).scalar()
	if aritcle:
		return 1
	return 0
Exemple #2
0
def get_send_content(num, to_self=False):
	content = []
	session = connection.init_db()
	query = session.query(Article)
	get_all = num
	get_url = None
	total_count = count()
	print 'send the email count:%d'%total_count
	if total_count == 0:
		return message
	if total_count > num :
		get_url = total_count-num
	else:
		get_all = total_count
	if to_self:
		get_all = total_count
		get_url = None
	for a in query.filter(Article.is_send == False).order_by(Article.id.desc()).limit(get_all).all():
		box = []
		box.append(title%(a.id, a.art_url, a.art_title))
		box.append(a.content)
		content.append(u''.join(box))
	if get_url:
		for a in query.filter(Article.is_send == False).order_by(Article.id.desc()).offset(num).limit(get_url).all():
			box = []
			box.append(title%(a.id, a.art_url, a.art_title))
			content.append(u''.join(box))
	send_content = u''.join(content)
	return send_content
Exemple #3
0
def exit_designer(designer):
	session=connection.init_db()
	query=session.query(VoteModel.Designer)
	
	if li is None :
		return 1
	return 0
Exemple #4
0
def addVoter(username,desingn_id):
	session=connection.init_db()
	query=session.query(VoteModel.Voter)
	voter=query.filter(VoteModel.Voter.name==username).scalar()
	if voter is None:
		voter=VoteModel.Voter(name=username,design_id=desingn_id)
		session.add(voter)
		session.commit()
Exemple #5
0
def delete_design(id):
	session=connection.init_db()
	query=session.query(VoteModel.Design)
	design=query.filter(VoteModel.Design.id==id).scalar()
	if not design is None :
		print design.id 
		print design.work_name 
		session.delete(design)
		session.commit()
Exemple #6
0
def exit_design(designer_name):
	session=connection.init_db()
	query=session.query(VoteModel.Design)
	print 'i '
	for li in query.all():
		print li.work_name
		if my_security.verify_hash(li.work_name,designer_name):
			return 1
	return 0
Exemple #7
0
def clear_email(is_clean=1):
	session=connection.init_db()
	session.execute('update article set is_send=%d'%is_clean)
	session.commit()
	for i in session.query(Article).all():
		if i.is_send:
			print i.art_url+' \t'+'had send'
		else:
			print i.art_url+'\t'+'do not send'
Exemple #8
0
def save_art(art_url,art_type,content):
	art={}
	# send_mail(mailto_list,"hello",content)
	art['art_url']=art_url
	art['art_type']=art_type
	art['content']=content
	art['is_send']=False
	artic=Article(**art)
	session=connection.init_db()
	session.add(artic)
	session.commit()
Exemple #9
0
def get_designs():
	session=connection.init_db()
	query=session.query(VoteModel.Design)
	lis=[]
	for q in query.all():
		design={}
		design['id']=q.id
		design['path']=q.work_name
		design['voters']=session.query(func.count('*')).filter(VoteModel.Voter.design_id ==q.id).scalar()
		lis.append(design)
	# print lis	
	return lis
Exemple #10
0
def save_design(filename,designer):
	work=VoteModel.Design(work_name=filename)
	designer_database=None
	session=connection.init_db()
	query=session.query(VoteModel.Designer)
	li=query.filter(VoteModel.Designer.name==designer).scalar()
	if li is None:
		designer_database=VoteModel.Designer(name=designer)
		designer_database.designs.append(work)
	else:
		designer_database=li
		print designer_database.name
		print designer_database.id 
	designer_database.designs.append(work)
	session.add(work)
	session.add(designer_database)
	session.commit()
import connection

connection.init_db()


def registerUser(username, id):
    conn = connection.get_connection()
    c = conn.cursor()
    c.execute(f'SELECT * FROM USERS WHERE user_id = {id};')
    user_check_data = c.fetchall()
    if len(user_check_data) <= 0:
        c.execute(
            f'INSERT INTO USERS (user_id, username, user_sum) VALUES ({id}, "{username}", 0)')
        conn.commit()
        return True
    else:
        for row in user_check_data:
            print(row)
        return False


def addSum(sum, id):
    conn = connection.get_connection()
    c = conn.cursor()
    c.execute(f'UPDATE USERS SET user_sum={sum} WHERE user_id={id}')
    conn.commit()
    if c.rowcount > 0:
        return True
    else:
        return False
Exemple #12
0
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
# tell the handler to use this format
console.setFormatter(formatter)
# add the handler to the root logger
logging.getLogger('').addHandler(console)
 
# Now, we can log to the root logger, or any other logger. First the root...

 
def is_full_name(name):
	ord_num=name.find('@')
	if ord_num > 0:
		return 1
	else:
		return 0
session=connection.init_db()
query=session.query(Account)
for account in query:
	web_se=vote.vote_login(account.account,account.passwd)
	if web_se:
		vote.auto_vote(web_se,account)
	elif is_full_name(account.account.strip()):
		session.delete(account)
		session.commit()
		logging.warning('delete '+account.account)
	elif vote.vote_login(account.account.strip()+'@qq.com',account.passwd.strip()):
		vote.auto_vote(vote.vote_login(account.account.strip()+'@qq.com',account.passwd.strip()),account)
		ac=Account(account=account.account.strip()+'@qq.com',passwd=account.passwd.strip())
		session.add(ac)
		session.delete(account)
		session.commit()
Exemple #13
0
def clear_email(is_clean=1):
	session=connection.init_db()
	session.execute('update article set is_send=%d'%is_clean)
	session.commit()
Exemple #14
0
def count():
	session=connection.init_db()
	query=session.query(Article)
	count=session.query(func.count('*')).filter(Article.is_send==False).scalar()
	return count