Skip to content

Instantly share code, notes, and snippets.

@erickhun
Created August 13, 2021 09:42
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 erickhun/b0e154c68613a82101f72c4c1c9900c3 to your computer and use it in GitHub Desktop.
Save erickhun/b0e154c68613a82101f72c4c1c9900c3 to your computer and use it in GitHub Desktop.
Line messenger chat: Count number of message per month
import re
textfile = open("./line-chat.txt", 'r')
reg_date = re.compile("\w{3}\.,\s\d{1,2}\/(\d{1,2}\/\d{4})")
reg_hour = re.compile("\d{2}:\d{2}\t")
mapSenders = {}
for line in textfile:
matches_date = reg_date.findall(line)
matches_hour = reg_hour.findall(line)
if matches_date:
print(matches_date)
year = matches_date[0]
if year not in mapSenders:
print ("changing month " + year)
mapSenders[year] = 0
if matches_hour:
mapSenders[year] = mapSenders[year] + 1
for m in mapSenders:
print (str(m) + ": " + str(mapSenders[m]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment