Created
August 13, 2021 09:42
-
-
Save erickhun/b0e154c68613a82101f72c4c1c9900c3 to your computer and use it in GitHub Desktop.
Line messenger chat: Count number of message per month
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 | |
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