Advertisement
Guest User

Untitled

a guest
Mar 11th, 2011
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1.     links = {}
  2.     cursor = DBM.cursor()
  3.     cursor.execute("select comment_link_id, link_uri, sum((1-(unix_timestamp(now())-unix_timestamp(comment_date))/43200)) as x from comments, links where link_status = 'published' and link_date > date_sub(now(), interval 24 hour) and comment_link_id = link_id and comment_date > date_sub(now(), interval 12 hour) group by comment_link_id order by x desc limit 15")
  4.     for row in cursor:
  5.         values = {}
  6.         values['uri'] = row[1]
  7.         values['c'] = row[2]
  8.         values['w'] = 0
  9.         links[row[0]] = values
  10.  
  11.     cursor.execute("select link_id, link_uri, sum((1-(unix_timestamp(now())-unix_timestamp(vote_date))/43200)) as x from votes, links where link_status = 'published' and link_date > date_sub(now(), interval 24 hour) and vote_type='links' and vote_link_id = link_id and vote_date > date_sub(now(), interval 12 hour) and vote_user_id > 0 and vote_value > 7 group by vote_link_id order by x desc limit 15")
  12.     for row in cursor:
  13.         if row[0] in links:
  14.             links[row[0]]['v'] = row[2]
  15.             links[row[0]]['w'] = links[row[0]]['v'] + 2 * links[row[0]]['c']
  16.  
  17.     cursor.close()
  18.     sorted_ids = sorted(links, cmp=lambda x,y: cmp(links[y]['w'], links[x]['w']))
  19.     for id in sorted_ids:
  20.         if links[id]['w'] > 0:
  21.             print links[id]['uri'], links[id]['w']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement