pygit2/mysql.connector更新git的日志数据
2017-01-13 01:23
253 查看
由于最近拓展视野,发现了splinter和 Hp Utf 两个东西,很想去学习,基于django的自动发版系统又不能半途而非(实属自我约束,不能太没有恒心)。故而,更新日志的就不用django的web方式了,因为我尝试了很久,python本来就不熟悉,困难那是重重的,直接上python提供的mysql接口更新git的log日志。以下是代码:
在mysqlworkbench里执行了下统计:
得到:’4438’条记录
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")) 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()
在mysqlworkbench里执行了下统计:
SELECT count(author) FROM gitlog.gitlog_commits;
得到:’4438’条记录
相关文章推荐
- 为什么SQL Server数据文件和日志文件最后更新日期不准?
- MySQL学习笔记之十五 更新日志文件恢复数据
- oracel存储过程 根据excel 进行用户数据插入、角色绑定 或 用户数据更新、角色绑定或更新,并写入日志
- java解析oracle日志,获取指定日期后的更新和插入数据
- Git-更新数据
- Python+Git+FTP实现内部分发网站数据的自动更新
- 为什么SQL Server数据文件和日志文件最后更新日期不准? 推荐
- python解析git log后生成页面显示git更新日志信息
- git分布式学习日志(持续更新)
- mysql 数据更新日志
- 往数据库保存数据更新日志
- 使用git工具,在本地建立一个数据仓库,保存日常工作日志
- WPF学习日志1---DataGrid绑定与修改更新(数据List & 数据库)[部分代码有摘录其他文章]
- 二进制日志和数据更新的关系
- C#中关于通过dataGrid更新数据库
- 在同一个数据集中同时更新多表..............
- WinForm下TextBox的数据绑定和更新
- 更新日志!
- 值班日志管理系统更新记录
- 旧数据文件,旧控制文件,新日志,怎样恢复?