python操作github(github模組)

2021-10-25 07:20:36 字數 2761 閱讀 7138

# 獲取帳號下所有的repositories名字:

for repo in g.get_user().get_repos():

print(repo.name)

# 模糊查詢帶有qualys的repositories名字

#repositories = g.search_repositories(query='qualys')

#for repo in repositories:

# print(repo) # repository(full_name="$username/qualys_solution")

# 獲取組織(測試未通過)

#org = g.get_organization("$username")

# 獲取物件

repo = g.get_repo("$username/$repositoriesname") # repository(full_name="$username/qualys_solution")

# 列印物件的一些屬性

#print(dir(repo))

def formatgmtime(timestamp):

gmt_format = '%a, %d %b %y %h:%m:%s gmt'

local_time = datetime.datetime.strptime(timestamp, gmt_format) + datetime.timedelta(hours=8)

now = local_time.strftime("%y%m%d%h%m%s")

return now

# 獲取專案的tag版本標籤

for i in repo.get_tags():

#for i in repo.get_releases():

#print(dir(i))

print( i.name) # v1.0

#print( i.last_modified) # fri, 23 oct 2020 04:21:50 gmt

#print( i.raw_data)

commit = i.commit # commit(sha="7e700a25a6cb378d5c04d7cb3d616c14546d1c6b")

# print(commit.last_modified) # fri, 23 oct 2020 04:21:50 gmt

# print(commit.update()) # true

createtime = commit.stats.last_modified # # fri, 23 oct 2020 04:21:50 gmt

a = formatgmtime(createtime)

print (a) # 當前tag的時間戳 20201023122146

#print( i.etag) # w/"ee2a6ada459ea157854e6a13179b40e7"

#print( i.raw_headers)

#break

#repo.create_file("aa2/test1.txt", "test1", "test2", branch="master")

#contents = repo.get_contents("aa/fix_test.sh")

#print(contents.decoded_content.decode())

#print(dir(contents))

##contents = repo.get_contents("/opt/backend/gitfiledir/fix_test.sh", ref="test")

#repo.update_file(contents.path,

# "more tests",

# "more tests",

# contents.sha,

# branch="test")

#file_list = [

# '/opt/backend/gitfiledir/fix_test.sh'#]#

##master_ref = repo.get_git_ref('heads/master')

#master_sha = master_ref.object.sha

#base_tree = repo.get_git_tree(master_sha)##

#commit_message = 'add ****** regression analysis'

##repo.create_git_commit(commit_message, base_tree, )

#repo.push()

#

python操作字典 Python 字典操作高階

學習了 python 基本的字典操作後,學習這些高階操作,讓寫出的 更加優雅簡潔和 pythonic 與字典值有關的計算 問題想對字典的值進行相關計算,例如找出字典裡對應值最大 最小 的項。解決方案一 假設要從字典 中找出值最小的項,可以這樣做 d min zip d.values d.keys 2...

python 耗時操作 python 時間操作

import datetime import time 獲取當前時間 datetime.datetime.now 獲取當前日期 datetime.date.today 字串轉換為時間格式 t time.strptime 2009 08 08 y m d y,m,d t 0 3 datetime.da...

python 文件操作 Python文件操作

最近在網課中學習了python的文件操作,所以把老師上課講的都記錄了下來,作為筆記 開啟文件 可直接使用open函式,使用形式為1open 文件位址,操作形式 操作形式有以下幾個1 7r 唯讀模式 w 覆蓋寫模式 x 建立寫模式 a 追加寫模式 b 二進位制文件模式 t 文字文件模式 與r w x ...