Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

[time] add pycountry fuzzy search #433

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SaitamaRobot/modules/gettime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import List

import requests
import pycountry
from SaitamaRobot import TIME_API_KEY, dispatcher
from SaitamaRobot.modules.disable import DisableAbleCommandHandler
from telegram import ParseMode, Update
Expand Down Expand Up @@ -72,8 +73,11 @@ def gettime(update: Update, context: CallbackContext):
)

query_timezone = query.lower()
py_country = pycountry.countries.search_fuzzy(query)
if len(query_timezone) == 2:
result = generate_time(query_timezone, ["countryCode"])
elif py_country:
result = generate_time(py_country[0].alpha_2.lower(), ["countryCode"])
else:
result = generate_time(query_timezone, ["zoneName", "countryName"])

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ telethon
ujson
wikipedia
zalgo-text
SibylSystem
pycountry
SibylSystem