diff --git a/modules.py b/modules.py index 054ce85..f0dbeb7 100644 --- a/modules.py +++ b/modules.py @@ -7,6 +7,7 @@ import requests import wikipedia import xkcd +from unit_convert import UnitConvert RAPID_API_KEY = os.environ.get('RAPID_API_KEY') @@ -87,6 +88,19 @@ def reply(bot, message, intent, entities): bot.reply_to(message, response.text) else: bot.reply_to(message, 'I could not fetch a fact for you this time. Please try again later!') + elif intent == 'unit': + from_value = entities['value'] + from_unit = entities['from_unit'] + to_unit = entities['to_unit'] + url = "https://community-neutrino-currency-conversion.p.rapidapi.com/convert" + payload = "from-type=NZD&to-type=GBP&from-value=10" + headers = { + 'x-rapidapi-host': "community-neutrino-currency-conversion.p.rapidapi.com", + 'x-rapidapi-key': "", # Get your key from https://rapidapi.com/neutrinoapi/api/convert-1 + 'content-type': "application/x-www-form-urlencoded" + } + response = requests.request("POST", url, data=payload, headers=headers) + bot.reply_to(message, response.text['result']) elif intent == 'news': response = requests.get('https://covid-19-data.p.rapidapi.com/totals', headers={ 'x-rapidapi-key': RAPID_API_KEY diff --git a/requirements.txt b/requirements.txt index d53c161..b682589 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,8 +14,9 @@ pyTelegramBotAPI==3.6.7 python-dotenv==0.12.0 requests==2.21.0 six==1.12.0 +unit-convert==1.0.0 soupsieve==2.0.1 urllib3==1.24.1 Werkzeug==0.14.1 wikipedia==1.4.0 -xkcd==2.4.2 +xkcd==2.4.2 \ No newline at end of file