constituency.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:electioncharts 作者: mickeykedia 项目源码 文件源码
def get_constituency_result_2009(db,constituency_id):
    cursor = db.cursor()
    cursor.execute('''SELECT ca.id, ca.fullname, p.id, p.name, l.votes
      FROM last_time_results l, candidate ca, constituency co, party p 
      where l.constituency_id=co.id and l.candidate_id=ca.id 
      and l.party_id=p.id and l.candidate_id=ca.id and l.constituency_id=co.id 
      and l.constituency_id='''+ constituency_id +''' order 
      by l.votes desc;''')
    results=[]
    total_votes=0
    for row in cursor.fetchall():
        temp_map={}
        temp_map['candidate_id']=row[0]
        temp_map['candidate_name']=cgi.escape(row[1]).title()
        temp_map['party_id']=row[2]
        temp_map['party_name']=cgi.escape(row[3]).title()
        temp_map['votes']=row[4]
        total_votes=total_votes+row[4]
        results.append(temp_map)
    new_results = []
    for rec in results:
        rec['total_votes']=total_votes
        new_results.append(rec)

    return json.dumps(new_results)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号