You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
251 lines
7.7 KiB
251 lines
7.7 KiB
9 years ago
|
# -*- coding: utf-8 -*-
|
||
|
from pymongo import MongoClient
|
||
|
from pymongo import DESCENDING
|
||
|
import re
|
||
|
|
||
|
MONGO_CONF = {
|
||
|
'host': 'localhost',
|
||
|
'port': 27017,
|
||
|
}
|
||
|
|
||
|
conn = MongoClient(**MONGO_CONF)
|
||
|
db = conn.feeder
|
||
|
collection = db.flag
|
||
|
|
||
|
CURRENCY_LIST = (
|
||
|
('AFN', 'Afghan Afghani'),
|
||
|
('ALL', 'Albanian Lek'),
|
||
|
('DZD', 'Algerian Dinar'),
|
||
|
('AOA', 'Angolan Kwanza'),
|
||
|
('ARS', 'Argentine Peso'),
|
||
|
('AMD', 'Armenian Dram'),
|
||
|
('AWG', 'Aruban Florin'),
|
||
|
('AUD', 'Australian Dollar'),
|
||
|
('AZN', 'Azerbaijani Manat'),
|
||
|
('BSD', 'Bahamian Dollar'),
|
||
|
('BHD', 'Bahraini Dinar'),
|
||
|
('BDT', 'Bangladeshi Taka'),
|
||
|
('BBD', 'Barbadian Dollar'),
|
||
|
('BYR', 'Belarusian Ruble'),
|
||
|
('BZD', 'Belize Dollar'),
|
||
|
('BMD', 'Bermudan Dollar'),
|
||
|
('BTN', 'Bhutanese Ngultrum'),
|
||
|
('BTC', 'Bitcoin'),
|
||
|
('BOB', 'Bolivian Boliviano'),
|
||
|
('BAM', 'Bosnia'),
|
||
|
('BWP', 'Botswanan Pula'),
|
||
|
('BRL', 'Brazilian Real'),
|
||
|
('GBP', 'British Pound Sterling'),
|
||
|
('BND', 'Brunei Dollar'),
|
||
|
('BGN', 'Bulgarian Lev'),
|
||
|
('BIF', 'Burundian Franc'),
|
||
|
('XOF', 'CFA Franc BCEAO'),
|
||
|
('XAF', 'CFA Franc BEAC'),
|
||
|
('XPF', 'CFP Franc'),
|
||
|
('KHR', 'Cambodian Riel'),
|
||
|
('CAD', 'Canadian Dollar'),
|
||
|
('CVE', 'Cape Verdean Escudo'),
|
||
|
('KYD', 'Cayman Islands Dollar'),
|
||
|
('CLP', 'Chilean Peso'),
|
||
|
('CLF', 'Chilean Unidades de Fomento'),
|
||
|
('CNY', 'Chinese Yuan Renminbi'),
|
||
|
('COP', 'Colombian Peso'),
|
||
|
('KMF', 'Comorian Franc'),
|
||
|
('CDF', 'Congolese Franc'),
|
||
|
('CRC', 'Costa Rican Colón'),
|
||
|
('HRK', 'Croatian Kuna'),
|
||
|
('CUP', 'Cuban Peso'),
|
||
|
('CZK', 'Czech Republic Koruna'),
|
||
|
('DKK', 'Danish Krone'),
|
||
|
('DJF', 'Djiboutian Franc'),
|
||
|
('DOP', 'Dominican Peso'),
|
||
|
('XCD', 'East Caribbean Dollar'),
|
||
|
('EGP', 'Egyptian Pound'),
|
||
|
('EEK', 'Estonian Kroon'),
|
||
|
('ETB', 'Ethiopian Birr'),
|
||
|
('EUR', 'Euro'),
|
||
|
('FKP', 'Falkland Islands Pound'),
|
||
|
('FJD', 'Fijian Dollar'),
|
||
|
('GMD', 'Gambian Dalasi'),
|
||
|
('GEL', 'Georgian Lari'),
|
||
|
('GHS', 'Ghanaian Cedi'),
|
||
|
('GIP', 'Gibraltar Pound'),
|
||
|
('XAU', 'Gold'),
|
||
|
('GTQ', 'Guatemalan Quetzal'),
|
||
|
('GNF', 'Guinean Franc'),
|
||
|
('GYD', 'Guyanaese Dollar'),
|
||
|
('HTG', 'Haitian Gourde'),
|
||
|
('HNL', 'Honduran Lempira'),
|
||
|
('HKD', 'Hong Kong Dollar'),
|
||
|
('HUF', 'Hungarian Forint'),
|
||
|
('ISK', 'Icelandic Króna'),
|
||
|
('INR', 'Indian Rupee'),
|
||
|
('IDR', 'Indonesian Rupiah'),
|
||
|
('IRR', 'Iranian Rial'),
|
||
|
('IQD', 'Iraqi Dinar'),
|
||
|
('ILS', 'Israeli New Sheqel'),
|
||
|
('JMD', 'Jamaican Dollar'),
|
||
|
('JPY', 'Japanese Yen'),
|
||
|
('JEP', 'Jersey pound'),
|
||
|
('JOD', 'Jordanian Dinar'),
|
||
|
('KZT', 'Kazakhstan Tenge'),
|
||
|
('KES', 'Kenyan Shilling'),
|
||
|
('KWD', 'Kuwaiti Dinar'),
|
||
|
('KGS', 'Kyrgystani Som'),
|
||
|
('LAK', 'Laotian Kip'),
|
||
|
('LVL', 'Latvian Lats'),
|
||
|
('LBP', 'Lebanese Pound'),
|
||
|
('LSL', 'Lesotho Loti'),
|
||
|
('LRD', 'Liberian Dollar'),
|
||
|
('LYD', 'Libyan Dinar'),
|
||
|
('LTL', 'Lithuanian Litas'),
|
||
|
('MOP', 'Macanese Pataca'),
|
||
|
('MKD', 'Macedonian Denar'),
|
||
|
('MGA', 'Malagasy Ariary'),
|
||
|
('MWK', 'Malawian Kwacha'),
|
||
|
('MYR', 'Malaysian Ringgit'),
|
||
|
('MVR', 'Maldivian Rufiyaa'),
|
||
|
('MTL', 'Maltese Lira'),
|
||
|
('MRO', 'Mauritanian Ouguiya'),
|
||
|
('MUR', 'Mauritian Rupee'),
|
||
|
('MXN', 'Mexican Peso'),
|
||
|
('MDL', 'Moldovan Leu'),
|
||
|
('MNT', 'Mongolian Tugrik'),
|
||
|
('MAD', 'Moroccan Dirham'),
|
||
|
('MZN', 'Mozambican Metical'),
|
||
|
('MMK', 'Myanma Kyat'),
|
||
|
('NAD', 'Namibian Dollar'),
|
||
|
('NPR', 'Nepalese Rupee'),
|
||
|
('ANG', 'Netherlands Antillean Guilder'),
|
||
|
('TWD', 'New Taiwan Dollar'),
|
||
|
('NZD', 'New Zealand Dollar'),
|
||
|
('NIO', 'Nicaraguan Cordoba Oro'),
|
||
|
('NGN', 'Nigerian Naira'),
|
||
|
('KPW', 'North Korean Won'),
|
||
|
('NOK', 'Norwegian Krone'),
|
||
|
('OMR', 'Omani Rial'),
|
||
|
('PKR', 'Pakistani Rupee'),
|
||
|
('PAB', 'Panamanian Balboa'),
|
||
|
('PGK', 'Papua New Guinean Kina'),
|
||
|
('PYG', 'Paraguayan Guarani'),
|
||
|
('PEN', 'Peruvian Nuevo Sol'),
|
||
|
('PHP', 'Philippine Peso'),
|
||
|
('PLN', 'Polish Zloty'),
|
||
|
('QAR', 'Qatari Rial'),
|
||
|
('RON', 'Romanian Leu'),
|
||
|
('RUB', 'Russian Ruble'),
|
||
|
('RWF', 'Rwandan Franc'),
|
||
|
('SHP', 'Saint Helena Pound'),
|
||
|
('SVC', 'Salvadoran Colón'),
|
||
|
('WST', 'Samoan Tala'),
|
||
|
('SAR', 'Saudi Riyal'),
|
||
|
('RSD', 'Serbian Dinar'),
|
||
|
('SCR', 'Seychellois Rupee'),
|
||
|
('SLL', 'Sierra Leonean Leone'),
|
||
|
('XAG', 'Silver'),
|
||
|
('SGD', 'Singapore Dollar'),
|
||
|
('SBD', 'Solomon Islands Dollar'),
|
||
|
('SOS', 'Somali Shilling'),
|
||
|
('ZAR', 'South African Rand'),
|
||
|
('KRW', 'South Korean Won'),
|
||
|
('XDR', 'Special Drawing Rights'),
|
||
|
('LKR', 'Sri Lanka Rupee'),
|
||
|
('SDG', 'Sudanese Pound'),
|
||
|
('SRD', 'Surinamese Dollar'),
|
||
|
('SZL', 'Swazi Lilangeni'),
|
||
|
('SEK', 'Swedish Krona'),
|
||
|
('CHF', 'Swiss Franc'),
|
||
|
('SYP', 'Syrian Pound'),
|
||
|
('STD', 'SÃ'),
|
||
|
('TJS', 'Tajikistani Somoni'),
|
||
|
('TZS', 'Tanzanian Shilling'),
|
||
|
('THB', 'Thai Baht'),
|
||
|
('TOP', 'Tongan PaÊ'),
|
||
|
('TTD', 'Trinidad and Tobago Dollar'),
|
||
|
('TND', 'Tunisian Dinar'),
|
||
|
('TRY', 'Turkish Lira'),
|
||
|
('TMT', 'Turkmenistani New Manat'),
|
||
|
('USD', 'US Dollar'),
|
||
|
('UGX', 'Ugandan Shilling'),
|
||
|
('UAH', 'Ukrainian Hryvnia'),
|
||
|
('AED', 'United Arab Emirates Dirham'),
|
||
|
('UYU', 'Uruguayan Peso'),
|
||
|
('UZS', 'Uzbekistan Som'),
|
||
|
('VUV', 'Vanuatu Vatu'),
|
||
|
('VEF', 'Venezuelan BolÃ'),
|
||
|
('VND', 'Vietnamese Dong'),
|
||
|
('YER', 'Yemeni Rial'),
|
||
|
('ZMW', 'Zambian Kwacha'),
|
||
|
('ZMK', 'Zambian Kwacha'),
|
||
|
('ZWL', 'Zimbabwean Dollar'),
|
||
|
)
|
||
|
|
||
|
STATIC_CONV = {
|
||
|
'Tongan': 'Tonga',
|
||
|
'Ugandan': 'Uganda',
|
||
|
'Turkish': 'Turkey',
|
||
|
'Syrian': 'Syria',
|
||
|
'Swedish': 'Sweden',
|
||
|
'Serbian': 'Serbia',
|
||
|
'Polish': 'Poland',
|
||
|
'Russian': 'Russia',
|
||
|
'Norwegian': 'Norway',
|
||
|
'Mexican': 'Mexico',
|
||
|
'Laotian': 'Laos',
|
||
|
'Latvian': 'Latvia',
|
||
|
'Libyan': 'Libya',
|
||
|
'Kuwaiti': 'Kuwait',
|
||
|
'Kenyan': 'Kenya',
|
||
|
'Haitian': 'Haiti',
|
||
|
'Fijian': 'Fiji',
|
||
|
'Gambian': 'Gambia',
|
||
|
'Danish': 'Denmark',
|
||
|
'Cuban': 'Cuba',
|
||
|
'Chinese': 'China',
|
||
|
'Chilean': 'Chile',
|
||
|
'Aruban': 'Aruba',
|
||
|
'Angolan': 'Angola',
|
||
|
'Maltese': 'Malta',
|
||
|
'Iraqi': 'Iraq'
|
||
|
}
|
||
|
|
||
|
def main():
|
||
|
found = False
|
||
|
count = 0
|
||
|
for code, name in CURRENCY_LIST:
|
||
|
for n in name.split():
|
||
|
if found:
|
||
|
continue
|
||
|
if n.lower() in ('dollar', 'pound'):
|
||
|
continue
|
||
|
result = collection.find_one({'english': re.compile(n, re.IGNORECASE)})
|
||
|
if result:
|
||
|
print u'name: %s == eng: %s == mny: %s' % (name.decode('utf-8'), result['english'], result['currency'])
|
||
|
found = True
|
||
|
count += 1
|
||
|
elif n in STATIC_CONV.keys():
|
||
|
result = collection.find_one({'english': STATIC_CONV[n]})
|
||
|
if result:
|
||
|
print u'name: %s == eng: %s == mny: %s' % (name.decode('utf-8'), result['english'], result['currency'])
|
||
|
found = True
|
||
|
count += 1
|
||
|
elif code == 'ZMW':
|
||
|
result = collection.find_one({'english': 'Zambia'})
|
||
|
if result:
|
||
|
print u'name: %s == eng: %s == mny: %s' % (name.decode('utf-8'), result['english'], result['currency'])
|
||
|
found = True
|
||
|
count += 1
|
||
|
elif len(n) > 7:
|
||
|
result = collection.find_one({'english': re.compile(n[:-4], re.IGNORECASE)})
|
||
|
if result:
|
||
|
print u'name: %s == eng: %s == mny: %s' % (name.decode('utf-8'), result['english'], result['currency'])
|
||
|
found = True
|
||
|
count += 1
|
||
|
if not found:
|
||
|
print ' not found : %s' % name
|
||
|
found = False
|
||
|
print 'found %s / %s' % (count, len(CURRENCY_LIST))
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main()
|