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

Issue with parsing Birthday date #11

Closed
rupeshwar opened this issue Jul 28, 2019 · 4 comments
Closed

Issue with parsing Birthday date #11

rupeshwar opened this issue Jul 28, 2019 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@rupeshwar
Copy link

I was trying to use the script but it's failing because of the error -

ValueError: month must be in 1..12

I added a line to print birthday.month and birthday.day. The birthday month is being parsed as 13 and day as 7.
Going into that user's about page the Birthday shows as 13 July 1996.
I am from India and we use DD/MM format for dates.

If any other is info is required please let me know.

@mobeigi
Copy link
Owner

mobeigi commented Jul 28, 2019

Hmm interesting. From the ajax endpoint I believed it would always use american date format MM/DD. I live in Australia where DD/MM is also used but the MM/DD format was still being returned.

Could you add me somehow on an instant messaging platform so we can debug and fix this?

Thanks!

@mobeigi mobeigi added the bug Something isn't working label Jul 28, 2019
@mobeigi mobeigi added this to the 1.0.2 milestone Jul 28, 2019
@rupeshwar
Copy link
Author

Printing the birthday_date_str https://github.com/mobeigi/fb2cal/blob/master/src/fb2cal.py#L271
It's in DD MM format -

birthday_date_str:  15\/07
birthday_date_str:  19\/07
birthday_date_str:  20\/07

As a workaround I was able to get everything working by replacing this line https://github.com/mobeigi/fb2cal/blob/master/src/fb2cal.py#L282 with
return (int(matches[1]), int(matches[2]))
I have mailed you on e-mail id on your profile

@mobeigi
Copy link
Owner

mobeigi commented Jul 28, 2019

Interesting!

So it turns out the dates are not affected by your Facebook Region format settings for dates, times, numbers:
image

However, they are affected by the language selected for Facebook:
image

Doesn't look like I can set the locale in the ajax request.

Some approaches:

  • Change users locales to expected format, run script, then restore original value. Not ideal as Facebook's language will change if user browses Facebook at the same time.
  • Setting the month to match the expected month (due to way code is setup) and treating other value as day. Will work for DD/MM and MM/DD but not other formats.
  • Reading the locale, then mapping it to a date format type which can then be parsed. Harder but probably ideal as some formats are different. For example Korean language uses format MM. DD.

Leaning towards approach 3 to allow easy support with other locales in the future.

@mobeigi
Copy link
Owner

mobeigi commented Jul 28, 2019

Okay so I addressed this issue.
It was a little tedious due to the many different formats used in the tooltip content.

Best solution was to query an endpoint to get the users locale.
Next, I mapped locale to data formats manually.
Finally I just had to strip away all extra/junk characters from the tooltip content and parse the day, month.

It now supports all locales which support regular Hindu–Arabic numeral system characters [0-9]. Support for other numbering systems (Arabic, Persian, ..etc) were not added yet due to complexity. Furthermore, although date parsing works for a language like Korean, the day names are still in English and thus overall the solution won't work unless we have a map of day names too (or use Google API to translate day names etc). I will make another issue for these things but will otherwise mark this ticket as solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants