feat: Gitea started showing logs in a new format, this patch accommodates it

new-time-format
Aravinth Manivannan 2022-12-31 02:24:42 +05:30
parent 8532043620
commit 542a2ab78c
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
1 changed files with 24 additions and 9 deletions

View File

@ -16,6 +16,7 @@ class TimeSpent:
name: str
comment_id: str
issue: str
task: str
repo: str
issue: str
date: str
@ -54,7 +55,10 @@ class Gitea:
else:
logs[time.nick]["mins"] = int(time.mins)
else:
logs[time.nick] = {"hours": int(time.hours), "mins": int(time.mins)}
logs[time.nick] = {
"hours": int(time.hours),
"mins": int(time.mins),
}
for nick in logs:
time = logs[nick]
@ -64,7 +68,7 @@ class Gitea:
def write_csv(self):
w = None
print('writing to times.csv')
print("writing to times.csv")
with open("times.csv", "w+", encoding="utf-8") as f:
for repo in self.times:
for issue in self.times[repo]:
@ -157,14 +161,13 @@ class Gitea:
for issue in issues:
times = []
url = issue["html_url"]
task = issue["title"]
resp = requests.get(url)
contents = resp.text
soup = BeautifulSoup(contents, "html.parser")
divs = soup.find_all("div", attrs={"class": "timeline-item event"})
for div in divs:
for a in div.find_all(
"a", attrs={"class": "author"}
):
for a in div.find_all("a", attrs={"class": "author"}):
if "added spent time" in a.parent.text:
for s in a.parent.find_all(
"span", attrs={"class": "time-since"}
@ -178,13 +181,24 @@ class Gitea:
.find_all("span")[0]
.text
)
if "day" in time:
continue
if "h" in time:
hours = int(time.split("h")[0])
if "hours" in time:
hours = int(time.split("hours")[0])
elif "hour" in time:
hours = int(time.split("hour")[0])
else:
hours = int(time.split("h")[0])
else:
hours = 0
if "min" in time:
splits = time.split("min")[0]
if "h" in splits:
if "hours" in time:
mins = int(splits.split("hours")[1])
elif "hour" in time:
mins = int(splits.split("hour")[1])
elif "h" in time:
mins = int(splits.split("h")[1])
else:
mins = int(splits)
@ -203,6 +217,7 @@ class Gitea:
hours=hours,
repo=repo,
issue=url,
task=task,
url=f"{url}#{comment_id}",
)
)
@ -210,9 +225,9 @@ class Gitea:
repo_times.append(times)
total_times[repo] = repo_times
print(f"Found {num} log events in {self.org}")
return total_times
if __name__ == "__main__":
g = Gitea(host="https://gitea.hostea.org", org="Hostea")
g = Gitea(host="https://gitea.gna.org", org="gna")