1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| import time,datetime
#import config as config from pygit2 import Repository from pygit2 import GIT_SORT_NONE,GIT_SORT_TOPOLOGICAL, GIT_SORT_REVERSE,GIT_SORT_TIME import mysql.connector
# noinspection PyArgumentList cnx = mysql.connector.connect(user='root',password='我的密码吧告诉你',host='127.0.0.1',database='gitlog') argslog=[] cursor = cnx.cursor() cursor.execute("SELECT UNIX_TIMESTAMP(commit_date) FROM gitlog.gitlog_commits order by id desc limit 1")
dataNewtime=1357006210 for (datetimelog) in cursor: if (datetimelog[0]!=''): dataNewtime= datetimelog[0] idnum=0 for (i) in cursor: idnum=i[0]
repo = Repository('/home/chaosbom/git/ArhasMK/.git')
for commit in repo.walk(repo.head.target,GIT_SORT_TOPOLOGICAL | GIT_SORT_REVERSE):
if(commit.author.time > dataNewtime): #print (commit.author.time, dataNewtime, commit.author.time > dataNewtime, commit.author.time - dataNewtime) logtmp=[] idnum += 1 logtmp.append(idnum) logtmp.append(commit.author.name) logtmp.append(commit.message) logtmp.append('') logtmp.append(commit.tree.id.hex) logtmp.append(datetime.datetime.utcfromtimestamp(commit.author.time).strftime("%Y-%m-%d %H:%M:%S")) <!-- more --> print(logtmp) argslog.append(logtmp) #log=(commit.author.name,commit.message,commit.tree.id.hex,datetime.datetime.utcfromtimestamp(commit.author.time).strftime("%Y-%m-%d %H:%M:%S")) ##以下两句放在for循环中的时候,会增加海量的数据。是由于argslog的不断变大,递增处理。 ##但是如果直接在for循环中传递logtmp给cursor,又包参数不足的错误。此处留个大大的疑问。 add_log="INSERT INTO gitlog.gitlog_commits (id,author,message,commitsFile,nvalue,commit_date) VALUES (%s,%s,%s,%s,%s,%s)" cursor.executemany(add_log, argslog) cursor.close() cnx.commit() cnx.close()
|