Created
September 2, 2021 10:19
-
-
Save nsmirosh/9ea29b786fc50fdbd113e1aaff35d5e1 to your computer and use it in GitHub Desktop.
Python program that parses the git log output and writes the formmatted output to a separate file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
first_message_index = 4 | |
step_index = 6 | |
def get_first_alphabetic_character_pos(s): | |
m = re.search(r'[a-z]', s, re.I) | |
if m is not None: | |
return m.start() | |
return 0 | |
with open('log.txt') as f: | |
lines = f.readlines() | |
desired_lines = lines[first_message_index::step_index] | |
formatted_list = list() | |
for line in desired_lines: | |
stripped = line.strip() | |
start_pos = get_first_alphabetic_character_pos(stripped) | |
without_ticket_no = stripped[start_pos::] | |
formatted_line = without_ticket_no.capitalize() | |
formatted_list.append(formatted_line) | |
formatted_list.reverse() | |
single_string = ".\n".join(formatted_list) | |
f = open("formatted.txt", "w") | |
f.write(single_string) | |
f.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment