Skip to content
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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

sasidampuri
Copy link

Closes #10

  1. Incorporated all three date formats into one regex instead of having 3 different patterns for different types of dates and then separated according to their fields.
  2. Can also modify the time format by adding an another function likewise

Copy link
Owner

@JRavi2 JRavi2 left a 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

Comment on lines 162 to 181
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
Copy link
Owner

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.

Comment on lines 185 to 195
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'],
})
Copy link
Owner

@JRavi2 JRavi2 Dec 13, 2021

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.

@JRavi2
Copy link
Owner

JRavi2 commented Dec 13, 2021

Let me know if more clarification is required.
Also, to make new updates you don't need to open a new PR. You can just push more commits to the existing branch. That will add to the existing PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Date issue in whatsapp chat export
2 participants