From a350ead83d7fb543eadd4b83d0deaab5f6a5d1eb Mon Sep 17 00:00:00 2001 From: dedsec Date: Sat, 18 Jun 2022 10:53:26 +0530 Subject: [PATCH] [time] add pycountry fuzzy search --- SaitamaRobot/modules/gettime.py | 4 ++++ requirements.txt | 1 + 2 files changed, 5 insertions(+) diff --git a/SaitamaRobot/modules/gettime.py b/SaitamaRobot/modules/gettime.py index cc970ddca0..6f5f75799d 100644 --- a/SaitamaRobot/modules/gettime.py +++ b/SaitamaRobot/modules/gettime.py @@ -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 @@ -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"]) diff --git a/requirements.txt b/requirements.txt index f990c38a82..d1cd9ef497 100644 --- a/requirements.txt +++ b/requirements.txt @@ -33,3 +33,4 @@ telethon ujson wikipedia zalgo-text +pycountry