8000 Business info by aelkheir · Pull Request #4183 · python-telegram-bot/python-telegram-bot · GitHub
[go: up one dir, main page]

Skip to content

Business info #4183

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

Merged
merged 17 commits into from
Apr 6, 2024
Merged

Conversation

aelkheir
Copy link
Member
@aelkheir aelkheir commented Apr 1, 2024

Partially closes #4179

Information about Business Accounts [Taken by @aelkheir]

Check-list for PRs

  • Added .. versionadded:: NEXT.VERSION, .. versionchanged:: NEXT.VERSION or .. deprecated:: NEXT.VERSION to the docstrings for user facing changes (for methods/class descriptions, arguments and attributes)
  • Created new or adapted existing unit tests
  • Documented code changes according to the CSI standard <https://standards.mousepawmedia.com/en/stable/csi.html>__
  • Added myself alphabetically to AUTHORS.rst (optional)
  • Added new classes & modules to the docs and all suitable __all__ s
  • Checked the Stability Policy <https://docs.python-telegram-bot.org/stability_policy.html>_ in case of deprecations or changes to documented behavior

If the PR contains API changes (otherwise, you can ignore this passage)

  • New classes:
    • Added self._id_attrs and corresponding documentation
    • __init__ accepts api_kwargs as kw-only
  • If relevant:
    • Added or updated documentation for the changed class(es) and/or method(s)

@aelkheir aelkheir marked this pull request as draft April 1, 2024 16:10
@aelkheir aelkheir changed the title Business info [WIP] Business info Apr 1, 2024
@harshil21 harshil21 mentioned this pull request Apr 2, 2024
27 tasks
@aelkheir aelkheir changed the title [WIP] Business info Business info Apr 2, 2024
@aelkheir aelkheir marked this pull request as ready for review April 2, 2024 15:21
@aelkheir
Copy link
Member Author
aelkheir commented Apr 2, 2024

Ready for review.

Copy link
Member
@harshil21 harshil21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty much perfect overall. Just left some comments mostly regarding naming/doc inconsistencies.

Also I just realized that you may need TG Premium to test opening/closing_minute related review comment so you can just ignore that if you don't have premium and i'll handle that later.

@harshil21 harshil21 added the ⚙️ bot-api affected functionality: bot-api label Apr 3, 2024
@aelkheir
Copy link
Member Author
aelkheir commented Apr 3, 2024

Thanks for the review!

With regard to opening/closing_hours utilzing python datetime, A hurdle would be that datetime.datetime and datetime.date typically expect a specific day in month while a business having an opening in (e.g.) Monday at 9 am would mean any Monday regardless of the month/week.
I also thought datetime.time, which can be an improvement except that we also lose context of which day [Sat, Mon, ...] this opening/closing belongs to.

Finally, we could make a utility BusinessOpeningHoursInterval.parse_hour that works like this

(day, hour, minute) = parse_hour(opening/closing_hours)

# where day in [0, 1, .., 6]
# hour in [0, 1, .., 24],
# minute in [0, 1, .., 60]

But also users can calculate it themselves, since it's simple math operations.
what do you think?

@harshil21
Copy link
Member
harshil21 commented Apr 4, 2024

I just tested what values are returned by the API and it's clear that those times are representing the minute of the week. Here's the results:

Monday - 00:00 - 01:05: BusinessOpeningHoursInterval(closing_minute=65, opening_minute=0)
Monday - 08:00 - 20:00: BusinessOpeningHoursInterval(closing_minute=1200, opening_minute=480)
Tuesday - 24 hours: BusinessOpeningHoursInterval(closing_minute=2879, opening_minute=1440)
Thursday - 11:30 - 20:00: BusinessOpeningHoursInterval(closing_minute=5520, opening_minute=5010)
Sunday - 00:00 - 23:58: BusinessOpeningHoursInterval(closing_minute=10078, opening_minute=8640)

I'll update the doc to further explain how those numbers are achieved.


Now the utility function - I like your idea but we can split it into two different properties - opening_time and closing_time which do return that tuple of int's representing day, hour, and minute. This means that the user won't need to supply any input parameters.

We can also go one step further and override BusinessOpeningHoursInterval.__str__ and provide a friendly representation which returns e.g. Monday: 8am - 8pm. Thus a user can easily iterate over BusinessOpeningHours.opening_hours and just print() it to see the values.

Another idea - (this may be a little out of scope) - We can have another function

BusinessOpeningHours.convert_to_timezone(timezone: datetime.tzinfo) -> BusinessOpeningHoursInterval

Advantage is that its easier to schedule jobs and reduces potential errors.

cc @Bibo-Joshi

@harshil21
Copy link
Member

@aelkheir so @Bibo-Joshi and I discussed internally and decided to not pursue BusinessOpeningHoursInterval.__str__. As for the other two functions, you may complete them in this PR or choose to do it in another PR as it's not a priority. Let me know if you want to do them now, otherwise this PR is good to be merged.

@aelkheir
Copy link
Member Author
aelkheir commented Apr 5, 2024

not pursue BusinessOpeningHoursInterval.str.

Funnily enough i was just here to say that I don't know of a universal time representation that may fit all users, so we could let them use thetuple of ints and produce a representation to their liking.

I'll do it here and get it over with. But not untill tomorrow night hopefully :).

@aelkheir
Copy link
Member Author
aelkheir commented Apr 5, 2024

About the function convert_to_timezone, It turned out to be a but tricker, specifically because BusinessOpeningHoursInterval.{opening/closing}_minute could not not be represented as regular datetime/date/time.

A possibility i thought about was to get hours offset from BusinessOpeningHour.time_zone_name to convert_to_timezone.timezone and then do

BusinessOpeningHoursInterval(
    opening_minute=opening_minute + offset * 60,
    closing_minute=closing_minute + offset * 60
)

with special handling to keep the minutes in the range 0 - 10080

But this will require us to use pytz (?), and I see it's optional.
any thoughts @harshil21

Copy link
Member
@Bibo-Joshi Bibo-Joshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice PR, thank you very much!

Regarding convert_to_timezone & other auxiliary functionality: representing an offseted-time in form of BusinessOpeningHoursInterval doesn't make much sense to me, tbh.

What I could think of is a method BOH.get_opening_hours_for_day(dtm.date, tzinfo=None) -> tuple[tuple[dtm.datetime, dtm.datetime], …]. I.e. you provide a specific day and optionally a timezone and get as return value a sequence of the opening intervals for that day in the desired timezone. Making the user provide a timezone would also lift the requirement on our side to build the tzinfo object. We'd only have to deal with the case where the user does not pass a timezone and we'd fall back to time_zone_name. Until zoneinfo becomes usable for us (once we drop py3.8 I would personally just leave the datetime tz-naive …

Another thought that I had is BOH.is_open(dtm.datetime) -> bool, i.e. a method that would allow you to check if the business is open at that specified time. However I see that tz-dealing is more difficult again here, if we can't build a tzinfo object from time_zone_name, which brings me to believe that this should also wait until we drop py3.8

Since this functionality is very new and this is only the initial implementation on our end, I would not like to add additional dependencies for these, still rather minor, convencience methods. Once could ofc raise RuntimeError if pytz is not availbale, but that also seems like rather much effort for little gain …

@harshil21
Copy link
Member

Okay, I'm fine with waiting until we drop py 3.8 to implement these functions.

@aelkheir
Copy link
Member Author
aelkheir commented Apr 5, 2024

October (python 3.8 end of life) is not so far away. By then pytz could be droped entirely in favor of zoneinfo.

Thanks very much team for the opportunity <3

@Poolitzer
Copy link
Member

@aelkheir Thanks for the contribution!

@Bibo-Joshi Bibo-Joshi merged commit bb9bdb4 into python-telegram-bot:api-7.2 Apr 6, 2024
@aelkheir aelkheir deleted the business-info branch April 6, 2024 21:30
@github-actions github-actions bot locked and limited conversation to collaborators Apr 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
⚙️ bot-api affected functionality: bot-api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0