gh_pr_diff/old_crawler/pr_diff.py.old

46 lines
1.4 KiB
Python

#coding:utf-8
'''
Created on 2016年10月7日
@author: StarLee
'''
# pandas:27329, angularjs:37, rails:1334
import MySQLdb
import urllib2
#conn = MySQLdb.connect(host="localhost",user="starlee",passwd="1234",db="github_zlb",charset='utf8' )
conn = MySQLdb.connect(host="localhost",user="root",passwd="influx1234",db="github_zlb",charset='utf8' )
cursor = conn.cursor()
project_id = 1334
cursor.execute("select user_name,repo_name from project where project_id = %s",(project_id,))
url_prefix = "https://patch-diff.githubusercontent.com/raw/%s/%s/pull/"%cursor.fetchone()
cursor.execute("select value from pointers where name = %s",("%s_pr_dif"%project_id,))
history = cursor.fetchone()
if history == None:
history = 0
cursor.execute("insert into pointers(name,value) values(%s,%s)",("%s_pr_dif"%project_id,0))
conn.commit()
cursor.execute("select pr_number from five_prj_prs where prj_id=%s and pr_number>%s",(project_id,history))
prs = [item[0] for item in cursor.fetchall()]
prs = sorted(prs)
for pr in prs:
url_pr_dif = "%s%d.diff"%(url_prefix,pr)
req = urllib2.Request(url_pr_dif)
ini_html = urllib2.urlopen(req,timeout=300).read().lower().decode('utf-8')
cursor.execute("insert into pr_diff(project_id,pr_id,diff) values(%s,%s,%s)",(project_id,pr,ini_html))
cursor.execute("update pointers set value=%s where name=%s",(pr,"%s_pr_dif"%project_id))
conn.commit()