Last active
October 10, 2018 06:39
-
-
Save piyushghai/20167529e1a0da10cfaa57faf5387039 to your computer and use it in GitHub Desktop.
Bot to fetch latest USD rates from Remitly Inc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Licensed under the Apache License, Version 2.0 (the "License"). | |
# You may not use this file except in compliance with the License. | |
# A copy of the License is located at | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# or in the "license" file accompanying this file. This file is distributed | |
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | |
# express or implied. See the License for the specific language governing | |
# permissions and limitations under the License. | |
import requests | |
import os | |
import json | |
from bs4 import BeautifulSoup | |
country = 'india' | |
url = 'https://www.remitly.com/us/en/{}/pricing'.format(country) | |
REMITLY_JSON_TAG_IDENTIFIER = '__REMITLY_LANDING_PAGE_CONTEXT__ = ' | |
def generate_notification(title, message, url): | |
t = '-title {}'.format(title) | |
m = '-message ' + message | |
action = '-open {!r}'.format(url) | |
command = 'terminal-notifier {}'.format(' '.join([m, t, action])) | |
os.system(command) | |
page = requests.get(url) | |
remitly_soup = BeautifulSoup(page.content, 'html.parser') | |
js_scripts = remitly_soup.find_all('script') | |
for tag in js_scripts: | |
if tag.text and tag.text.startswith(REMITLY_JSON_TAG_IDENTIFIER): | |
json_data = json.loads(tag.text.replace(REMITLY_JSON_TAG_IDENTIFIER, '')) | |
forex_price = json_data['context']['forex'] | |
current_econmoy = forex_price['current']['economy']['everyday'] | |
current_express = forex_price['current']['express']['everyday'] | |
title = 'Remitly\ price\ ' + u'\U0001F4B0' + '\ to\ ' + u'\u20B9' | |
message = 'Economy\ price\ :\ '+ u'\u20B9' + current_econmoy + ',\ Express\ price\ :\ ' + u'\u20B9' + current_express | |
title = title.encode('utf-8') | |
message = message.encode('utf-8') | |
generate_notification(title=title, message=message, url=url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment