-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Date-issue whatsapp revised 1.0 #15
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good. Though I think we can clean it up a bit more.
In the if-else chain here there are many repeating elements, which I think we could eliminate. Please take a look at the inline comments below
src/chat_analyzer.py
Outdated
formatdmy = 1 | ||
formatmdy = 1 | ||
formatymd = 1 | ||
#To check that the date formats in the chat are in which format | ||
#Can also check the time format here itself... | ||
for line in f: | ||
match = re.search(WMsg, line) | ||
if match: | ||
try: | ||
datetime_object = datetime.strptime(match.groupdict()['date'], '%m/%d/%y') | ||
except: | ||
formatmdy = 0 | ||
try: | ||
datetime_object = datetime.strptime(match.groupdict()['date'], '%d/%m/%y') | ||
except: | ||
formatdmy = 0 | ||
try: | ||
datetime_object = datetime.strptime(match.groupdict()['date'], '%y/%m/%d') | ||
except: | ||
formatymd = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, instead of maintaining three identifiers for the different formats, what we can do is store the varying parameters, namely, datetime_object (already there), month, day, and year.
src/chat_analyzer.py
Outdated
if match and formatmdy: | ||
msgs.append({ | ||
'username': match.groupdict()['username'], | ||
'date': datetime.strptime(match.groupdict()['date'], '%m/%d/%y').date(), | ||
'month': match.groupdict()['month'], | ||
'day': match.groupdict()['day'], | ||
'year': match.groupdict()['year'], | ||
'month': match.groupdict()['feild1'], | ||
'day': match.groupdict()['feild2'], | ||
'year': match.groupdict()['feild3'], | ||
'time': datetime.strptime(match.groupdict()['time'], '%H:%M').time(), | ||
'hour': match.groupdict()['hour'], | ||
'minute': match.groupdict()['minute'], | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then, here, instead of having the if-else chain, we can just have the one if condition checking if there is a match or not, and if there is a match just use the parameters that were stored earlier.
Let me know if more clarification is required. |
Closes #10