I'm going to practice on parsing(Json format) Git commit message based on Python. I'm going to read the data from .csv file and get url. And I will save the message that I parsed from url to .csv file.
I need to import Json, csv
import csv
import json
Open file to read and write.
read_f = open('read_file.csv', 'r', encoding = 'utf-8')
write_f = open('write_file.csv', 'w' , encoding = 'utf-8')
rdr = csv.reader(read_f)
wdr = csv.writer(write_f)
add = "https://api.github.com/repos/"
linenum = 0
for line in rdr:
if linenum != 0:
repo = line[1][19:-4]
fix = line[4]
url = add + repo + "/commits/" + fix
my_file = requests.get(url, auth=('KimMilim','kmlsjm98*'))
try:
my_dict =json.loads(my_file.text)['commit']['message']
#print(my_dict)
wdr.writerow([my_dict])
except:
wdr.writerow(["-"])
linenum += 1
read_f.close()
write_f.close()