-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmoney2india.py
More file actions
executable file
·149 lines (131 loc) · 4.42 KB
/
money2india.py
File metadata and controls
executable file
·149 lines (131 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#! /usr/bin/python
# Scraper that goes through all services and gets the exchange rates.
# This is cron'ed every hour.
import json
import re
import requests
import sys
from BeautifulSoup import BeautifulSoup
# begin parsers
def xoom_parser(data):
soup = BeautifulSoup(data)
return float(re.match(r'^1 USD = (.*) INR$', soup.find('em', {'class': 'fx-rate'}).string).groups()[0])
def m2i_parser(data):
soup = BeautifulSoup(data)
return float(re.match('.*USA = ([^ ]+) INR.*', ' '.join(soup.find('marquee').findAll(text = True)).replace('\n', ' ')).groups()[0])
def r2i_parser(data):
soup = BeautifulSoup(data)
return float(soup.find('span', {'class': 'exRate'}).string)
def wu_parser(data):
return float(json.loads(data)['update']['conversion']['targetCurrency']['exchange'])
def rl_parser(data):
soup = BeautifulSoup(data)
return float(re.match(r'INR ([0-9\.]+).*', soup.find('span', {'class': 'yellowHighlight'}).string).groups()[0])
#return float(re.match(r'1 USD = ([0-9\.]+).*', soup.find('span', {'class': 'yellowHighlight'}).string).groups()[0])
def tf_parser(data):
soup = BeautifulSoup(data)
return float(soup.find('span', id='lblExchangeRate').string)
def axis_parser(data):
soup = BeautifulSoup(data)
return float(re.match(r'USD 1 = Rs\. ([0-9\.]+).*', soup.find('span', id='lblCurrency').string).groups()[0])
def ifr_parser(data):
soup = BeautifulSoup(data)
return float(re.match(r'.*1 USD = ([^ ]+).*', ' '.join(soup.find('div', {'class': 'body'}).findAll(text = True)).replace('\n', ' ')).groups()[0])
def sbi_parser(data):
soup = BeautifulSoup(data)
return float(soup.findAll('td', {'class': 'content'})[1].string.strip().split(' ')[0])
def ib_parser(data):
soup = BeautifulSoup(data)
return float(soup.find('tr', {'bgcolor': '#FFFFFF'}).findAll('td', {'align': 'center'})[1].string)
def royal_parser(data):
soup = BeautifulSoup(data)
return float(soup.find('span', id = 'txtbankrate').string)
# end parsers
parsers = [
{
'name': 'Xoom',
'url': 'https://www.xoom.com/india',
'parser': xoom_parser,
'locked_in': True
},
{
'name': 'ICICI Money2India',
'url': 'http://www.icicibank.com/nri-banking/money_transfer/exchange-rate/iframe_exchange_rate.html',
'parser': m2i_parser,
'locked_in': True
},
{
'name': 'Remit2India',
'url': 'https://www.remit2india.com/sendmoneytoindia/UnitedStates/index.jsp',
'parser': r2i_parser,
'locked_in': False
},
{
'name': 'Western Union Money Transfer',
'url': 'https://www.westernunion.com/ajaxHandler/service/getDelvryOptAndCurrency/?originAmount=0.0&originCountry=US&targetCountry=IN&originCurrency=USD&senderZipCode=&_=1390937227258',
'parser': wu_parser,
'locked_in': False
},
{
'name': 'Remit Lite',
'url': 'https://www.remitlite.com/remitlite/index.jsp',
'parser': rl_parser,
'locked_in': False
},
{
'name': 'Transfast',
'url': 'https://www.transfast.com/sendmoney_IND.aspx',
'parser': tf_parser,
'locked_in': True
},
{
'name': 'Axis Remit',
'url': 'https://www.axisbank.com/WebForms/axis_remit_US/Send-Money-To-India-From-US.aspx',
'parser': axis_parser,
'locked_in': False
},
{
'name': 'Indus Fast Remit',
'url': 'https://www.indusfastremit.com/mobile/exchangeRate.do',
'parser': ifr_parser,
'locked_in': True
},
{
'name': 'SBI Remittance',
'url': 'https://www.statebank.com/RemittanceServiceIndMaster.asp',
'parser': sbi_parser,
'locked_in': False
},
{
'name': 'Indian Bank IND Remit',
'url': 'http://www.timesofmoney.com/remittance/jsp/remitExchangeRate.jsp?partnerId=INB&uiId=INB',
'parser': ib_parser,
'locked_in': False
},
{
'name': 'Royal Exchange USA',
'url': 'https://www.rupees2india.us:462/MoneyTransferUS/LoginPageBankNew.aspx',
'parser': royal_parser,
'locked_in': True
},
]
def main():
amount = None
if len(sys.argv) > 0:
try:
amount = int(sys.argv[1])
except:
pass
headers = { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36' }
for parser in parsers:
try:
rate = parser['parser'](requests.get(parser['url'], verify = False, headers = headers).text)
print parser['name'], "-", rate,
if amount:
print "-", (float(rate) * amount)
else:
print ""
except:
pass
if __name__ == "__main__":
main()