From 5be36b0e8c1b037f8ecc10fd48e3bcfd73bad6f4 Mon Sep 17 00:00:00 2001 From: ChihYing Date: Sat, 31 Aug 2024 17:26:47 +0800 Subject: [PATCH] fix commit calendar svg parsing for number of commits --- gitfiti.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index b327a1df60..21771be2dd 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -14,6 +14,7 @@ import json import math import os +import re try: # Python 3+ from urllib.error import HTTPError, URLError @@ -296,10 +297,12 @@ def parse_contributions_calendar(contributions_calendar): """Yield daily counts extracted from the embedded contributions SVG.""" for line in contributions_calendar.splitlines(): # a valid line looks like this: - # 23 contributions on Sunday, February 26, 2023 - if 'data-date=' in line: - commit = line.split('>')[1].split()[0] # yuck + # No contributions on August 27th. + pattern = r'(\bNo\b|\d+)\s+contributions on' + match = re.search(pattern, line, re.IGNORECASE) + if match: + commit = match.group(1) if commit.isnumeric(): yield int(commit)