Skip to content

Instantly share code, notes, and snippets.

@nsmirosh
Created September 2, 2021 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsmirosh/9ea29b786fc50fdbd113e1aaff35d5e1 to your computer and use it in GitHub Desktop.
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
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