zoukankan      html  css  js  c++  java
  • python抓取gitlab日志写入到库里面

    抓取gitlab提交日志信息,代码可运行。

    import gitlab

    import gitlab
    import MySQLdb
    import time
    from datetime import datetime
    from datetime import timedelta
    
    if __name__ == '__main__':
        print(1)
        url = 'http://gitlab.centaline.cn'
        token = 'pWZqajTAoyu'
        gl = gitlab.Gitlab(url, private_token=token)
        projects = gl.projects.list(all=True)
        '''
        sz = gl.projects.get(448)
        all_groups = gl.groups.list(all=True)
    
        for cm in sz.commits.list():
            print(2)
            print(cm.name)
    '''
    
        #gl.projects.list(since='2021-01-01T00:00:00Z')
        conn = MySQLdb.connect(host='ip', user='dev', passwd='123456', db='gitlab', port=3306,
                               charset='utf8')
        sql_commit = "insert into commit values(%s, %s, %s, %s, %s, %s, %s)"
        try:
            with conn.cursor() as cursor:
                for Project in projects:
                    conmmparams = []
                    in_id = str(Project.id)
                    name = Project.name
                    in_commits = []
                    commits = Project.commits.list(since='2021-11-09T00:00:00Z',)
                    # Project.commits.list(since='2021-08-01T00:00:00Z')
                    for c in commits:
                        a = [c.id, c.committer_name, c.committer_email,  c.created_at, c.message, c.project_id, name]
                        in_commits.append(a)
                        for i in range(len(in_commits)):
                            print(4)
                            param = tuple(in_commits[i])
                            conmmparams.append(param)
                    cursor.executemany(sql_commit, conmmparams)
                    conn.commit()
                    print(6)
    
        except MySQLdb.MySQLError as err:
            print(err)
            conn.rollback()
        finally:
            conn.close()
  • 相关阅读:
    hdu 1524
    hdu 1536
    转载一篇博弈博弈入门的好文章
    nim 博弈
    WPF 从Main函数启动
    C# map network drive sample
    Predicate 学习
    WPF 绑定到附加属性 绑定到只读属性
    WPF 带有watermark的文本输入框
    使用Windows服务发布WCF服务
  • 原文地址:https://www.cnblogs.com/muer/p/15562563.html
Copyright © 2011-2022 走看看