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

Added new module: Unit conversion #68

Closed
wants to merge 8 commits into from
Closed
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
14 changes: 14 additions & 0 deletions modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import requests
import wikipedia
import xkcd
from unit_convert import UnitConvert

RAPID_API_KEY = os.environ.get('RAPID_API_KEY')

Expand Down Expand Up @@ -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': "<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
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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