add wiki page markdown file
This commit is contained in:
parent
6598d5033b
commit
2fbe6f773d
|
@ -1,34 +1,42 @@
|
|||
##对git日志的body进行解析
|
||||
import requests
|
||||
from requests.adapters import HTTPAdapter
|
||||
from pygitlog.gitoperation import *
|
||||
from pygitlog.mdoperation import *
|
||||
|
||||
#获取kerywords的wiki url
|
||||
def get_wikipage(keyword):
|
||||
def get_wikipage(keyword,file_name):
|
||||
i = 0
|
||||
S = requests.Session()
|
||||
S.mount('http://', HTTPAdapter(max_retries=3))
|
||||
S.mount('https://', HTTPAdapter(max_retries=3))
|
||||
URL = "https://en.wikipedia.org/w/api.php"
|
||||
PARAMS = {"action": "opensearch","namespace": "0","search": "","limit": "1","format": "json"}
|
||||
PARAMS['search'] = keyword
|
||||
if keyword == "":
|
||||
print("keyword is null")
|
||||
return ""
|
||||
else:
|
||||
print(keyword)
|
||||
R = S.get(url=URL, params=PARAMS)
|
||||
DATA = R.json()
|
||||
if len(DATA) == 0 :
|
||||
print("no search result")
|
||||
with open(file_name,mode="a+") as file:
|
||||
file.write("| " + keyword + " ")
|
||||
file.write("| no search result |\n")
|
||||
#print("no search result")
|
||||
return ""
|
||||
else:
|
||||
print("DATA=",DATA)
|
||||
#print(type(DATA))
|
||||
#print("DATA[0]=",DATA[0])
|
||||
#print(type(DATA[0]))
|
||||
#print("DATA[3]=",DATA[3])
|
||||
#print(type(DATA[3]))
|
||||
if len(DATA[3]) == 0:
|
||||
print("no match result")
|
||||
with open(file_name,mode="a+") as file:
|
||||
file.write("| " + keyword + " ")
|
||||
file.write("| no match result |\n")
|
||||
#print("no match result")
|
||||
return ""
|
||||
else:
|
||||
with open(file_name,mode="a+") as file:
|
||||
file.write("| " + keyword + " ")
|
||||
file.write("| " + DATA[3][0] + " |\n")
|
||||
return DATA[3][0]
|
||||
|
||||
#处理abbr没有keyword的特殊情况
|
||||
|
@ -74,7 +82,7 @@ def get_true_keyword(keywords,hash):
|
|||
|
||||
#获取commit的关键词,如ext4
|
||||
#逻辑:先获取oneline的描述,然后进行切分
|
||||
def get_commit_keyword(abbr,hash):
|
||||
def get_commit_keyword(abbr,hash,wiki_file_name):
|
||||
#print(abbr.split())
|
||||
keywords = ""
|
||||
for abb in abbr.split():
|
||||
|
@ -86,7 +94,7 @@ def get_commit_keyword(abbr,hash):
|
|||
keywords = "special"
|
||||
for key in keywords.split('/'):
|
||||
keyword = get_true_keyword(key,hash)
|
||||
return "[" + keyword + "](" + get_wikipage(keyword) + ")"
|
||||
return "[" + keyword + "](" + get_wikipage(keyword,wiki_file_name) + ")"
|
||||
|
||||
#获取commit的类型,如
|
||||
def get_commit_type(body):
|
||||
|
|
Loading…
Reference in New Issue