代码拉取完成,页面将自动刷新
# -*- coding: utf-8 -*-
# @Time : 2022/4/7 21:24
# @Author : Kaicheng
import os
import urllib
import github
GH = github.Github("your_access_token")
ROOT_DIR = "D:/OSS_Projects"
repo_list = ["jruby/jruby", "netty/netty", "spring-projects/spring-framework", "bumptech/glide", "jfree/jfreechart", "apache/lucene-solr"]
def file_download(local_path, url):
if not os.path.exists(os.path.dirname(local_path)):
os.makedirs(os.path.dirname(local_path))
if not os.path.exists(local_path):
urllib.request.urlretrieve(url, local_path)
for repo_str in repo_list:
repo = GH.get_repo(repo_str)
pr_list = repo.get_pulls(state='open', sort='created')
for index in range(pr_list.totalCount):
pr = pr_list[index]
# select the appropriate PRs
java_count = 0
for f in pr.get_files():
if f.filename.endswith(".java"):
java_count += 1
if java_count < 2 or java_count > 100:
continue
print(pr.title + " " + str(pr.number))
first_commit = pr.get_commits()[0]
parent_commit = first_commit.parents[0]
pre_repo_url = f"https://github.com/{repo_str}/raw/{parent_commit.sha}"
print("parent commit repo resource url: " + pre_repo_url)
print("parent commit repo front-end url: " + pre_repo_url.replace("/raw/", "/tree/"))
for f in pr.get_files():
if not f.filename.endswith(".java"):
continue
print(f.filename)
if f.status == "removed":
local_old_path = f"{ROOT_DIR}/{repo_str}/{str(pr.number)}/old/{f.filename}"
file_download(local_old_path, f.raw_url)
elif f.status == "added":
local_new_path = f"{ROOT_DIR}/{repo_str}/{str(pr.number)}/new/{f.filename}"
file_download(local_new_path, f.raw_url)
else:
# download new version
local_new_path = f"{ROOT_DIR}/{repo_str}/{str(pr.number)}/new/{f.filename}"
file_download(local_new_path, f.raw_url)
# download old version
try:
old_raw_url = f"{pre_repo_url}/{f.filename.replace('/', '%2F')}"
local_old_path = f"{ROOT_DIR}/{repo_str}/{str(pr.number)}/old/{f.filename}"
file_download(local_old_path, old_raw_url)
except:
print()
print(f"404: {pre_repo_url}/{f.filename.replace('/', '%2F')}")
continue
print("--------------------------------------------------")
print("===================================================")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。