Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Hello, I made CurrencyIn.pm module for you. #64

Merged
merged 6 commits into from

5 participants

@Alchymista

When user type:
currency in {country}
then result is found and returned from hash table (now it is included inside module)

I know it requires some upgrades but this is my first day with Perl =)
so anyone feel free to do updates in it...

Module is based on this request:
https://duckduckhack.uservoice.com/forums/5168-plugins/suggestions/2678913-currency-in-x-tells-you-the-currency-in-x-countr

Pavel

@rpicard

Cool Goodie! You should put the hash in the Perl file though. See here for an example of that.

@Alchymista

Hello, thanks for comment.

No problem, I can put that hash inside Perl file. I am just unsure if it should be embed or loaded from external file.
Because I was thinking that those information (parsed from wikipedia) may be updated regularly (e.g. once a year =) and it is easier to do when in external file (parser is already coded in Python)
But I am open for suggestion. If it is really no problem then I can put it in the Perl file (it is easier solution anyway =).

Pavel

@rpicard

I'd just put it in the Goodie but someone else might disagree.

@Alchymista

OK, seem you thing it is better to put that hash into Perl file... so I am starting to work on it =)

@Alchymista

Hash table with countries is now included in Perl file and it works fine on my computer so hopefully someone will accept my pull request :)

@rpicard

Cool. Just a couple of other suggestions.

You might want to move the hash outside of the subroutine so it isn't re-generated every time it's called.

Also, what if the user types "currency of" instead of "currency in"? You might want to use =~ with a regex to find the country they want instead of using substr(). That way, you could just search the whole thing for a pattern like: /(in\s*.*|of\s*.*|for\s*.*)/ (probably not the right pattern to use but you get the idea) and not care about what came before it, e.g. what is the currency used in America or what currency will I need for Russia? (note: the latter case shows that you might also consider stripping the match of punctuation before checking the hash).

If you did decide to do that you'd probably want to change the trigger to any.

@Alchymista

Great, thank you for suggestions =)

I get some sleep first and will take a look on it, tomorrow.

@yegg
Owner

I think you are right -- it would be best to read in the output file so it could be updated easily at a later point. Also, you can add the python generation file right in the same share directory so it is easy to regenerate.

You should be able to read in the hash like this:

my %currency = share('currency.txt')->slurp

That would read one line in as a key, and the next as a value. Check out how the passphrase goodie for an example (though it uses an array).

@Alchymista

So far I have two issues with "my %currency = share('currency.txt')->slurp" way of reading hash file:

1) it reads values with the end of the line for keys and values. So when I search for '$currency{"slovakia"}' then no results, because I must search for "slovakia\n" with end of the line included...

2) I have problem to pass value as array when share function reads '["Euro (EUR)", "Dolar (USD)"]' then it keeps that line as string not an array =(

It will be much appreciated if anyone can help =)

Pavel

btw: 'currency.txt' at the moment looks like this:
abkhazia
["Russian ruble (RUB)"]
afghanistan
["Afghan afghani (AFN)"]
zimbabwe
["Botswana pula (BWP)","British pound (GBP)","Euro (EUR)","South African rand (ZAR)","United States dollar (USD)"]
...

@rpicard

@Alchymista In response to your second point you could make it a string where the values are separated by something like a semicolon so it looks like Zimbabwe => "Botswana pula (BWP):Euro (EUR):Dollar (USD)" and use my @arr = split(/:/, $currency{"simbabwe"}) to split it into an array.

@Getty

You should consider switch this to YAML https://metacpan.org/module/YAML

@Alchymista

Thank you @rpicard
Not sure how I could forgot about so simple solution (probably because I wanted to store it like array so much...)

@Getty ... thanks for introducing YAML module, but I am quite new to Perl (all together I spent like three days with it) so for the moment I stick with my current solution (it is working =) ...
But if you think that with YAML it will be really, really cool then feel free to take all my code or redo whole CurrencyIn module if you..
(for me this is sort of exercise because I wanted to try what it is about "to be involved in opensource" =)

@Getty

you can definitly do that yourself :) its a good mission/training :) thanks for the code! :)

@rpicard

@Alchymista I was just testing out your Goodie and have a few things for you to look into.

  • There is a new line in the response. I think chomp() might work but there is some stuff in that page about using it with slurp so you might need to use $var =~ s/\n//g; or something similar to strip the new line.
  • Maybe make the response more like a sentence, i.e. instead of saying Currency in Andorra is Euro (EUR) return The currency in Andorra is the Euro (EUR)..

It's coming along really well!

@Alchymista

Thank you for help and support :)

@rpicard

No problem! Thanks for putting so much work into it.

@nospampleasemam nospampleasemam merged commit 4d01ce2 into duckduckgo:master
@nospampleasemam

Merged :-) Thanks again for contributing to DuckDuckGo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
300 lib/DDG/Goodie/CurrencyIn.pm
@@ -3,14 +3,14 @@ package DDG::Goodie::CurrencyIn;
# TODO: At the moment it return value only if user inputs the whole country name...
# ...if user types "Salvador" instead of "El Salvador" then no results...
-# TODO: think about how often currency in countries changes - what then?
-# Parse text (parser already build) from Wikipedia and manually copy paste?
+# TODO: think about how often currency in countries changes?
+# Parser (for Wikipedia) is included in share directory...
-# In some countries there are more than one currency
-# For that reason values in hash are stored as arrays. Example:
-# %countries( "Zimbabwe"=>["A","B"], "Slovakia"=>["A"], ... )"
+# In some countries there are more than one currency.
+# For that reason values in hash are stored as arrays. (loaded from .txt as comma separated values )
+# Example: %countries( "Zimbabwe"=>["A","B"], "Slovakia"=>["A"], ... )"
-# Working examples:
+# Working examples for queries:
# What currency do I need in Egypt ?
# What currency will I need for Zimbabwe
# What is the currency used in Slovakia
@@ -19,288 +19,50 @@ package DDG::Goodie::CurrencyIn;
use DDG::Goodie;
-triggers any => 'currency'; # User typed currency...
+triggers any => 'currency'; # User typed currency...
-# Hash with all countries and currencies is now included in file
-# There is already build parser (in Python) to generate it from Wikipedia
# Countries are lowercased but input from user, too ... so those always match...
# ...country is capitalized on output...
-my %currencies = (
- "abkhazia"=>["Russian ruble (RUB)"],
- "afghanistan"=>["Afghan afghani (AFN)"],
- "akrotiri and dhekelia"=>["Euro (EUR)"],
- "albania"=>["Albanian lek (ALL)"],
- "alderney"=>["Alderney pound","British pound (GBP)","Guernsey pound"],
- "algeria"=>["Algerian dinar (DZD)"],
- "andorra"=>["Euro (EUR)"],
- "angola"=>["Angolan kwanza (AOA)"],
- "anguilla"=>["East Caribbean dollar (XCD)"],
- "antigua and barbuda"=>["East Caribbean dollar (XCD)"],
- "argentina"=>["Argentine peso (ARS)"],
- "armenia"=>["Armenian dram (AMD)"],
- "aruba"=>["Aruban florin (AWG)"],
- "ascension island"=>["Ascension pound","Saint Helena pound (SHP)"],
- "australia"=>["Australian dollar (AUD)"],
- "austria"=>["Euro (EUR)"],
- "azerbaijan"=>["Azerbaijani manat (AZN)"],
- "bahamas"=>["Bahamian dollar (BSD)"], # name on Wikipedia is like: "Bahamas, The"..?.
- "bahrain"=>["Bahraini dinar (BHD)"],
- "bangladesh"=>["Bangladeshi taka (BDT)"],
- "barbados"=>["Barbadian dollar (BBD)"],
- "belarus"=>["Belarusian ruble (BYR)"],
- "belgium"=>["Euro (EUR)"],
- "belize"=>["Belize dollar (BZD)"],
- "benin"=>["West African CFA franc (XOF)"],
- "bermuda"=>["Bermudian dollar (BMD)"],
- "bhutan"=>["Bhutanese ngultrum (BTN)","Indian rupee (INR)"],
- "bolivia"=>["Bolivian boliviano (BOB)"],
- "bonaire"=>["United States dollar (USD)"],
- "bosnia and herzegovina"=>["Bosnia and Herzegovina convertible mark (BAM)"],
- "botswana"=>["Botswana pula (BWP)"],
- "brazil"=>["Brazilian real (BRL)"],
- "british indian ocean territory"=>["United States dollar (USD)"],
- "british virgin islands"=>["British Virgin Islands dollar","United States dollar (USD)"],
- "brunei"=>["Brunei dollar (BND)","Singapore dollar (SGD)"],
- "bulgaria"=>["Bulgarian lev (BGN)"],
- "burkina faso"=>["West African CFA franc (XOF)"],
- "burma"=>["Burmese kyat (MMK)"],
- "burundi"=>["Burundian franc (BIF)"],
- "cambodia"=>["Cambodian riel (KHR)"],
- "cameroon"=>["Central African CFA franc (XAF)"],
- "canada"=>["Canadian dollar (CAD)"],
- "cape verde"=>["Cape Verdean escudo (CVE)"],
- "cayman islands"=>["Cayman Islands dollar (KYD)"],
- "central african republic"=>["Central African CFA franc (XAF)"],
- "chad"=>["Central African CFA franc (XAF)"],
- "chile"=>["Chilean peso (CLP)"],
- "china, people's republic of"=>["Chinese yuan (CNY)"],
- "cocos (keeling) islands"=>["Australian dollar (AUD)","Cocos (Keeling) Islands dollar"],
- "colombia"=>["Colombian peso (COP)"],
- "comoros"=>["Comorian franc (KMF)"],
- "congo, democratic republic of the"=>["Congolese franc (CDF)"],
- "congo, republic of the"=>["Central African CFA franc (XAF)"],
- "cook islands"=>["New Zealand dollar (NZD)","Cook Islands dollar"],
- "costa rica"=>["Costa Rican colón (CRC)"],
- "croatia"=>["Croatian kuna (HRK)"],
- "cuba"=>["Cuban convertible peso (CUC)","Cuban peso (CUP)"],
- "curaçao"=>["Netherlands Antillean guilder (ANG)"],
- "cyprus"=>["Euro (EUR)"],
- "czech republic"=>["Czech koruna (CZK)"],
- "côte d'ivoire"=>["West African CFA franc (XOF)"],
- "denmark"=>["Danish krone (DKK)"],
- "djibouti"=>["Djiboutian franc (DJF)"],
- "dominica"=>["East Caribbean dollar (XCD)"],
- "dominican republic"=>["Dominican peso (DOP)"],
- "east timor"=>["United States dollar (USD)"],
- "ecuador"=>["United States dollar (USD)"],
- "egypt"=>["Egyptian pound (EGP)"],
- "el salvador"=>["Salvadoran colón (SVC)","United States dollar (USD)"],
- "equatorial guinea"=>["Central African CFA franc (XAF)"],
- "eritrea"=>["Eritrean nakfa (ERN)"],
- "estonia"=>["Euro (EUR)"],
- "ethiopia"=>["Ethiopian birr (ETB)"],
- "falkland islands"=>["Falkland Islands pound (FKP)"],
- "faroe islands"=>["Danish krone (DKK)","Faroese króna"],
- "fiji"=>["Fijian dollar (FJD)"],
- "finland"=>["Euro (EUR)"],
- "france"=>["Euro (EUR)"],
- "french polynesia"=>["CFP franc (XPF)"],
- "gabon"=>["Central African CFA franc (XAF)"],
- "gambia, the"=>["Gambian dalasi (GMD)"],
- "georgia"=>["Georgian lari (GEL)"],
- "germany"=>["Euro (EUR)"],
- "ghana"=>["Ghana cedi (GHS)"],
- "gibraltar"=>["Gibraltar pound (GIP)"],
- "greece"=>["Euro (EUR)"],
- "grenada"=>["East Caribbean dollar (XCD)"],
- "guatemala"=>["Guatemalan quetzal (GTQ)"],
- "guernsey"=>["British pound (GBP)","Guernsey pound"],
- "guinea"=>["Guinean franc (GNF)"],
- "guinea-bissau"=>["West African CFA franc (XOF)"],
- "guyana"=>["Guyanese dollar (GYD)"],
- "haiti"=>["Haitian gourde (HTG)"],
- "honduras"=>["Honduran lempira (HNL)"],
- "hong kong"=>["Hong Kong dollar (HKD)"],
- "hungary"=>["Hungarian forint (HUF)"],
- "iceland"=>["Icelandic króna (ISK)"],
- "india"=>["Indian rupee (INR)"],
- "indonesia"=>["Indonesian rupiah (IDR)"],
- "iran"=>["Iranian rial (IRR)"],
- "iraq"=>["Iraqi dinar (IQD)"],
- "ireland"=>["Euro (EUR)"],
- "isle of man"=>["British pound (GBP)","Manx pound"],
- "israel"=>["Israeli new shekel (ILS)"],
- "italy"=>["Euro (EUR)"],
- "jamaica"=>["Jamaican dollar (JMD)"],
- "japan"=>["Japanese yen (JPY)"],
- "jersey"=>["British pound (GBP)","Jersey pound"],
- "jordan"=>["Jordanian dinar (JOD)"],
- "kazakhstan"=>["Kazakhstani tenge (KZT)"],
- "kenya"=>["Kenyan shilling (KES)"],
- "kiribati"=>["Australian dollar (AUD)","Kiribati dollar"],
- "korea, north"=>["North Korean won (KPW)"],
- "korea, south"=>["South Korean won (KRW)"],
- "kosovo"=>["Euro (EUR)"],
- "kuwait"=>["Kuwaiti dinar (KWD)"],
- "kyrgyzstan"=>["Kyrgyzstani som (KGS)"],
- "laos"=>["Lao kip (LAK)"],
- "latvia"=>["Latvian lats (LVL)"],
- "lebanon"=>["Lebanese pound (LBP)"],
- "lesotho"=>["Lesotho loti (LSL)","South African rand (ZAR)"],
- "liberia"=>["Liberian dollar (LRD)"],
- "libya"=>["Libyan dinar (LYD)"],
- "liechtenstein"=>["Swiss franc (CHF)"],
- "lithuania"=>["Lithuanian litas (LTL)"],
- "luxembourg"=>["Euro (EUR)"],
- "macau"=>["Macanese pataca (MOP)"],
- "macedonia, republic of"=>["Macedonian denar (MKD)"],
- "madagascar"=>["Malagasy ariary (MGA)"],
- "malawi"=>["Malawian kwacha (MWK)"],
- "malaysia"=>["Malaysian ringgit (MYR)"],
- "maldives"=>["Maldivian rufiyaa (MVR)"],
- "mali"=>["West African CFA franc (XOF)"],
- "malta"=>["Euro (EUR)"],
- "marshall islands"=>["United States dollar (USD)"],
- "mauritania"=>["Mauritanian ouguiya (MRO)"],
- "mauritius"=>["Mauritian rupee (MUR)"],
- "mexico"=>["Mexican peso (MXN)"],
- "micronesia"=>["Micronesian dollar","United States dollar (USD)"],
- "moldova"=>["Moldovan leu (MDL)"],
- "monaco"=>["Euro (EUR)"],
- "mongolia"=>["Mongolian tögrög (MNT)"],
- "montenegro"=>["Euro (EUR)"],
- "montserrat"=>["East Caribbean dollar (XCD)"],
- "morocco"=>["Moroccan dirham (MAD)"],
- "mozambique"=>["Mozambican metical (MZN)"],
- "nagorno-karabakh republic"=>["Armenian dram (AMD)","Nagorno-Karabakh dram"],
- "namibia"=>["Namibian dollar (NAD)","South African rand (ZAR)"],
- "nauru"=>["Australian dollar (AUD)","Nauruan dollar"],
- "nepal"=>["Nepalese rupee (NPR)"],
- "netherlands"=>["Euro (EUR)"],
- "new caledonia"=>["CFP franc (XPF)"],
- "new zealand"=>["New Zealand dollar (NZD)"],
- "nicaragua"=>["Nicaraguan córdoba (NIO)"],
- "niger"=>["West African CFA franc (XOF)"],
- "nigeria"=>["Nigerian naira (NGN)"],
- "niue"=>["New Zealand dollar (NZD)","Niuean dollar"],
- "northern cyprus"=>["Turkish lira (TRY)"],
- "norway"=>["Norwegian krone (NOK)"],
- "oman"=>["Omani rial (OMR)"],
- "pakistan"=>["Pakistani rupee (PKR)"],
- "palau"=>["Palauan dollar","United States dollar (USD)"],
- "palestine"=>["Israeli new shekel (ILS)","Jordanian dinar (JOD)"],
- "panama"=>["Panamanian balboa (PAB)","United States dollar (USD)"],
- "papua new guinea"=>["Papua New Guinean kina (PGK)"],
- "paraguay"=>["Paraguayan guaraní (PYG)"],
- "peru"=>["Peruvian nuevo sol (PEN)"],
- "philippines"=>["Philippine peso (PHP)"],
- "pitcairn islands"=>["New Zealand dollar (NZD)","Pitcairn Islands dollar"],
- "poland"=>["Polish złoty (PLN)"],
- "portugal"=>["Euro (EUR)"],
- "qatar"=>["Qatari riyal (QAR)"],
- "romania"=>["Romanian leu (RON)"],
- "russia"=>["Russian ruble (RUB)"],
- "rwanda"=>["Rwandan franc (RWF)"],
- "saba"=>["United States dollar (USD)"],
- "sahrawi republic"=>["Algerian dinar (DZD)","Mauritanian ouguiya (MRO)","Moroccan dirham (MAD)","Sahrawi peseta"],
- "saint helena"=>["Saint Helena pound (SHP)"],
- "saint kitts and nevis"=>["East Caribbean dollar (XCD)"],
- "saint lucia"=>["East Caribbean dollar (XCD)"],
- "saint vincent and the grenadines"=>["East Caribbean dollar (XCD)"],
- "samoa"=>["Samoan tālā (WST)"],
- "san marino"=>["Euro (EUR)"],
- "saudi arabia"=>["Saudi riyal (SAR)"],
- "senegal"=>["West African CFA franc (XOF)"],
- "serbia"=>["Serbian dinar (RSD)"],
- "seychelles"=>["Seychellois rupee (SCR)"],
- "sierra leone"=>["Sierra Leonean leone (SLL)"],
- "singapore"=>["Brunei dollar (BND)","Singapore dollar (SGD)"],
- "sint eustatius"=>["United States dollar (USD)"],
- "sint maarten"=>["Netherlands Antillean guilder (ANG)"],
- "slovakia"=>["Euro (EUR)"],
- "slovenia"=>["Euro (EUR)"],
- "solomon islands"=>["Solomon Islands dollar (SBD)"],
- "somalia"=>["Somali shilling (SOS)"],
- "somaliland"=>["Somaliland shilling"],
- "south africa"=>["South African rand (ZAR)"],
- "south georgia and the south sandwich islands"=>["British pound (GBP)","South Georgia and the South Sandwich Islands pound"],
- "south ossetia"=>["Russian ruble (RUB)"],
- "south sudan"=>["South Sudanese pound (SSP)"],
- "spain"=>["Euro (EUR)"],
- "sri lanka"=>["Sri Lankan rupee (LKR)"],
- "sudan"=>["Sudanese pound (SDG)"],
- "suriname"=>["Surinamese dollar (SRD)"],
- "swaziland"=>["Swazi lilangeni (SZL)"],
- "sweden"=>["Swedish krona (SEK)"],
- "switzerland"=>["Swiss franc (CHF)"],
- "syria"=>["Syrian pound (SYP)"],
- "são tomé and príncipe"=>["São Tomé and Príncipe dobra (STD)"],
- "taiwan (republic of china)"=>["New Taiwan dollar (TWD)"],
- "tajikistan"=>["Tajikistani somoni (TJS)"],
- "tanzania"=>["Tanzanian shilling (TZS)"],
- "thailand"=>["Thai baht (THB)"],
- "togo"=>["West African CFA franc (XOF)"],
- "tonga"=>["Tongan paʻanga (TOP)"],
- "transnistria"=>["Transnistrian ruble"],
- "trinidad and tobago"=>["Trinidad and Tobago dollar (TTD)"],
- "tristan da cunha"=>["Saint Helena pound (SHP)","Tristan da Cunha pound"],
- "tunisia"=>["Tunisian dinar (TND)"],
- "turkey"=>["Turkish lira (TRY)"],
- "turkmenistan"=>["Turkmenistani manat (TMT)"],
- "turks and caicos islands"=>["United States dollar (USD)"],
- "tuvalu"=>["Australian dollar (AUD)","Tuvaluan dollar"],
- "uganda"=>["Ugandan shilling (UGX)"],
- "ukraine"=>["Ukrainian hryvnia (UAH)"],
- "united arab emirates"=>["United Arab Emirates dirham (AED)"],
- "united kingdom"=>["British pound (GBP)"],
- "united states"=>["United States dollar (USD)"],
- "uruguay"=>["Uruguayan peso (UYU)"],
- "uzbekistan"=>["Uzbekistani som (UZS)"],
- "vanuatu"=>["Vanuatu vatu (VUV)"],
- "vatican city"=>["Euro (EUR)"],
- "venezuela"=>["Venezuelan bolívar (VEF)"],
- "vietnam"=>["Vietnamese đồng (VND)"],
- "wallis and futuna"=>["CFP franc (XPF)"],
- "yemen"=>["Yemeni rial (YER)"],
- "zambia"=>["Zambian kwacha (ZMK)"],
- "zimbabwe"=>["Botswana pula (BWP)","British pound (GBP)","Euro (EUR)","South African rand (ZAR)","United States dollar (USD)","Zimbabwean dollar (ZWL)"],
-);
-sub clearCountryName { # Query may end with "?". If so take it away.
+my %countries = share('currency.txt')->slurp;
+
+sub clearCountryName {
my $txt = shift;
- my $last = substr($txt, length($txt)-1, 1);
- if ($last eq "?") {
- $txt = substr($txt,0, length($txt) -1);
- }
+ $txt =~ s/^\?$|\?$//g; # Query may end with "?". If so take it away.
$txt =~ s/^\s+|\s+$//g; # Trim spaces before and after the country name
return $txt
}
handle remainder => sub {
- # If there is 'in', 'of' or 'for' keyword then get country name - after the last appearance of keyword
+
if (/^.*(?:in|of|for)\s(.*?)$/) {
-
- $country = lc($1); # Country name is result of previous regexp - make it lowercased
+ $country = lc($1); # Country name is result of previous regexp - make it lowercased
$country = clearCountryName($country); # Clear country name - white spaces, question mark..
+ $country = $country . "\n"; # At the moment share() function parsing names with "\n" so match user input..
- if (exists $currencies{$country}){
- my $count = $#{$currencies{$country}} + 1;
- my $result = "";
- my $html = "";
- my $output_country = $country; # Pass it to the output_country
- $output_country =~ s/\b(\w)/\U$1/g; # so it can by capitalized
- if ($count == 1) {
- $result .= "Currency in $output_country is ";
- $html .= "Currency in $output_country is ";
+ if (exists $countries{$country}){
+ my $string_currency = $countries{$country}; # Load currencies as string (one line from .txt)
+ my @currencies = split(',', $string_currency); # Split currencies into array
+ $country =~ s/\n//g; # Get rid of the end of the line character
+
+ my $count = $#currencies + 1; # Get number of currencies
+ my $result = ""; # Store text result
+ my $html = ""; # Store html result
+ my $output_country = $country; # Pass country name to the output_country
+ $output_country =~ s/\b(\w)/\U$1/g; # so it can by capitalized
+ if ($count == 1) { # In number of currencies == 1
+ $result .= "The currency in $output_country is the ";
+ $html .= "The urrency in $output_country is the ";
} else {
$result .= "Currencies in $output_country are: \n";
$html .= "Currencies in $output_country are:<br />";
}
# Append result with all currencies
- for $i (0.. $#{$currencies{$country}}){
- $result .= "$currencies{$country}[$i] \n";
- $html .= "$currencies{$country}[$i] <br />";
+ foreach $i (@currencies){
+ $i =~ s/\n//g; # Get rid of the end of the line character
+ $result .= "$i\n";
+ $html .= "$i <br />";
}
zci is_cached => 1;
View
21 share/goodie/currency_in/README.txt
@@ -0,0 +1,21 @@
+parser.py generates currencies.txt for 'CurrencyIn.pm' module.
+
+Currencies for each country are from:
+http://en.wikipedia.org/wiki/List_of_circulating_currencies
+
+First run: 'fetch.sh' to fetch wikipedia page used by parser,
+then run: 'parse.sh' or just 'python parse.py'
+
+
+DETAILS:
+Output is the file (currencies.txt) with list of countries and currencies with iso code in ()
+For example:
+slovakia
+Euro (EUR)
+
+If there is more than one currency used by each country then each currency is separated by comma
+For example:
+zimbabwe
+Botswana pula (BWP),British pound (GBP)
+
+Country name is lowercased for better comparison with user input. But it gets capitalized in search results.
View
476 share/goodie/currency_in/currency.txt
@@ -0,0 +1,476 @@
+abkhazia
+Russian ruble (RUB)
+afghanistan
+Afghan afghani (AFN)
+akrotiri and dhekelia
+Euro (EUR)
+albania
+Albanian lek (ALL)
+alderney
+Alderney pound,British pound (GBP),Guernsey pound
+algeria
+Algerian dinar (DZD)
+andorra
+Euro (EUR)
+angola
+Angolan kwanza (AOA)
+anguilla
+East Caribbean dollar (XCD)
+antigua and barbuda
+East Caribbean dollar (XCD)
+argentina
+Argentine peso (ARS)
+armenia
+Armenian dram (AMD)
+aruba
+Aruban florin (AWG)
+ascension island
+Ascension pound,Saint Helena pound (SHP)
+australia
+Australian dollar (AUD)
+austria
+Euro (EUR)
+azerbaijan
+Azerbaijani manat (AZN)
+bahamas
+Bahamian dollar (BSD)
+bahrain
+Bahraini dinar (BHD)
+bangladesh
+Bangladeshi taka (BDT)
+barbados
+Barbadian dollar (BBD)
+belarus
+Belarusian ruble (BYR)
+belgium
+Euro (EUR)
+belize
+Belize dollar (BZD)
+benin
+West African CFA franc (XOF)
+bermuda
+Bermudian dollar (BMD)
+bhutan
+Bhutanese ngultrum (BTN),Indian rupee (INR)
+bolivia
+Bolivian boliviano (BOB)
+bonaire
+United States dollar (USD)
+bosnia and herzegovina
+Bosnia and Herzegovina convertible mark (BAM)
+botswana
+Botswana pula (BWP)
+brazil
+Brazilian real (BRL)
+british indian ocean territory
+United States dollar (USD)
+british virgin islands
+British Virgin Islands dollar,United States dollar (USD)
+brunei
+Brunei dollar (BND),Singapore dollar (SGD)
+bulgaria
+Bulgarian lev (BGN)
+burkina faso
+West African CFA franc (XOF)
+burma
+Burmese kyat (MMK)
+burundi
+Burundian franc (BIF)
+cambodia
+Cambodian riel (KHR)
+cameroon
+Central African CFA franc (XAF)
+canada
+Canadian dollar (CAD)
+cape verde
+Cape Verdean escudo (CVE)
+cayman islands
+Cayman Islands dollar (KYD)
+central african republic
+Central African CFA franc (XAF)
+chad
+Central African CFA franc (XAF)
+chile
+Chilean peso (CLP)
+china
+Chinese yuan (CNY)
+cocos islands
+Australian dollar (AUD),Cocos (Keeling) Islands dollar
+colombia
+Colombian peso (COP)
+comoros
+Comorian franc (KMF)
+congo, democratic republic of the
+Congolese franc (CDF)
+congo, republic of the
+Central African CFA franc (XAF)
+cook islands
+New Zealand dollar (NZD),Cook Islands dollar
+costa rica
+Costa Rican colón (CRC)
+croatia
+Croatian kuna (HRK)
+cuba
+Cuban convertible peso (CUC),Cuban peso (CUP)
+curaçao
+Netherlands Antillean guilder (ANG)
+cyprus
+Euro (EUR)
+czech republic
+Czech koruna (CZK)
+côte d'ivoire
+West African CFA franc (XOF)
+denmark
+Danish krone (DKK)
+djibouti
+Djiboutian franc (DJF)
+dominica
+East Caribbean dollar (XCD)
+dominican republic
+Dominican peso (DOP)
+east timor
+United States dollar (USD)
+ecuador
+United States dollar (USD)
+egypt
+Egyptian pound (EGP)
+el salvador
+Salvadoran colón (SVC),United States dollar (USD)
+equatorial guinea
+Central African CFA franc (XAF)
+eritrea
+Eritrean nakfa (ERN)
+estonia
+Euro (EUR)
+ethiopia
+Ethiopian birr (ETB)
+falkland islands
+Falkland Islands pound (FKP)
+faroe islands
+Danish krone (DKK),Faroese króna
+fiji
+Fijian dollar (FJD)
+finland
+Euro (EUR)
+france
+Euro (EUR)
+french polynesia
+CFP franc (XPF)
+gabon
+Central African CFA franc (XAF)
+gambia, the
+Gambian dalasi (GMD)
+georgia
+Georgian lari (GEL)
+germany
+Euro (EUR)
+ghana
+Ghana cedi (GHS)
+gibraltar
+Gibraltar pound (GIP)
+greece
+Euro (EUR)
+grenada
+East Caribbean dollar (XCD)
+guatemala
+Guatemalan quetzal (GTQ)
+guernsey
+British pound (GBP),Guernsey pound
+guinea
+Guinean franc (GNF)
+guinea-bissau
+West African CFA franc (XOF)
+guyana
+Guyanese dollar (GYD)
+haiti
+Haitian gourde (HTG)
+honduras
+Honduran lempira (HNL)
+hong kong
+Hong Kong dollar (HKD)
+hungary
+Hungarian forint (HUF)
+iceland
+Icelandic króna (ISK)
+india
+Indian rupee (INR)
+indonesia
+Indonesian rupiah (IDR)
+iran
+Iranian rial (IRR)
+iraq
+Iraqi dinar (IQD)
+ireland
+Euro (EUR)
+isle of man
+British pound (GBP),Manx pound
+israel
+Israeli new shekel (ILS)
+italy
+Euro (EUR)
+jamaica
+Jamaican dollar (JMD)
+japan
+Japanese yen (JPY)
+jersey
+British pound (GBP),Jersey pound
+jordan
+Jordanian dinar (JOD)
+kazakhstan
+Kazakhstani tenge (KZT)
+kenya
+Kenyan shilling (KES)
+kiribati
+Australian dollar (AUD),Kiribati dollar
+korea, north
+North Korean won (KPW)
+korea, south
+South Korean won (KRW)
+kosovo
+Euro (EUR)
+kuwait
+Kuwaiti dinar (KWD)
+kyrgyzstan
+Kyrgyzstani som (KGS)
+laos
+Lao kip (LAK)
+latvia
+Latvian lats (LVL)
+lebanon
+Lebanese pound (LBP)
+lesotho
+Lesotho loti (LSL),South African rand (ZAR)
+liberia
+Liberian dollar (LRD)
+libya
+Libyan dinar (LYD)
+liechtenstein
+Swiss franc (CHF)
+lithuania
+Lithuanian litas (LTL)
+luxembourg
+Euro (EUR)
+macau
+Macanese pataca (MOP)
+macedonia
+Macedonian denar (MKD)
+madagascar
+Malagasy ariary (MGA)
+malawi
+Malawian kwacha (MWK)
+malaysia
+Malaysian ringgit (MYR)
+maldives
+Maldivian rufiyaa (MVR)
+mali
+West African CFA franc (XOF)
+malta
+Euro (EUR)
+marshall islands
+United States dollar (USD)
+mauritania
+Mauritanian ouguiya (MRO)
+mauritius
+Mauritian rupee (MUR)
+mexico
+Mexican peso (MXN)
+micronesia
+Micronesian dollar,United States dollar (USD)
+moldova
+Moldovan leu (MDL)
+monaco
+Euro (EUR)
+mongolia
+Mongolian tögrög (MNT)
+montenegro
+Euro (EUR)
+montserrat
+East Caribbean dollar (XCD)
+morocco
+Moroccan dirham (MAD)
+mozambique
+Mozambican metical (MZN)
+nagorno-karabakh republic
+Armenian dram (AMD),Nagorno-Karabakh dram
+namibia
+Namibian dollar (NAD),South African rand (ZAR)
+nauru
+Australian dollar (AUD),Nauruan dollar
+nepal
+Nepalese rupee (NPR)
+netherlands
+Euro (EUR)
+new caledonia
+CFP franc (XPF)
+new zealand
+New Zealand dollar (NZD)
+nicaragua
+Nicaraguan córdoba (NIO)
+niger
+West African CFA franc (XOF)
+nigeria
+Nigerian naira (NGN)
+niue
+New Zealand dollar (NZD),Niuean dollar
+northern cyprus
+Turkish lira (TRY)
+norway
+Norwegian krone (NOK)
+oman
+Omani rial (OMR)
+pakistan
+Pakistani rupee (PKR)
+palau
+Palauan dollar,United States dollar (USD)
+palestine
+Israeli new shekel (ILS),Jordanian dinar (JOD)
+panama
+Panamanian balboa (PAB),United States dollar (USD)
+papua new guinea
+Papua New Guinean kina (PGK)
+paraguay
+Paraguayan guaraní (PYG)
+peru
+Peruvian nuevo sol (PEN)
+philippines
+Philippine peso (PHP)
+pitcairn islands
+New Zealand dollar (NZD),Pitcairn Islands dollar
+poland
+Polish złoty (PLN)
+portugal
+Euro (EUR)
+qatar
+Qatari riyal (QAR)
+romania
+Romanian leu (RON)
+russia
+Russian ruble (RUB)
+rwanda
+Rwandan franc (RWF)
+saba
+United States dollar (USD)
+sahrawi republic
+Algerian dinar (DZD),Mauritanian ouguiya (MRO),Moroccan dirham (MAD),Sahrawi peseta
+saint helena
+Saint Helena pound (SHP)
+saint kitts and nevis
+East Caribbean dollar (XCD)
+saint lucia
+East Caribbean dollar (XCD)
+saint vincent and the grenadines
+East Caribbean dollar (XCD)
+samoa
+Samoan tālā (WST)
+san marino
+Euro (EUR)
+saudi arabia
+Saudi riyal (SAR)
+senegal
+West African CFA franc (XOF)
+serbia
+Serbian dinar (RSD)
+seychelles
+Seychellois rupee (SCR)
+sierra leone
+Sierra Leonean leone (SLL)
+singapore
+Brunei dollar (BND),Singapore dollar (SGD)
+sint eustatius
+United States dollar (USD)
+sint maarten
+Netherlands Antillean guilder (ANG)
+slovakia
+Euro (EUR)
+slovenia
+Euro (EUR)
+solomon islands
+Solomon Islands dollar (SBD)
+somalia
+Somali shilling (SOS)
+somaliland
+Somaliland shilling
+south africa
+South African rand (ZAR)
+south georgia and the south sandwich islands
+British pound (GBP),South Georgia and the South Sandwich Islands pound
+south ossetia
+Russian ruble (RUB)
+south sudan
+South Sudanese pound (SSP)
+spain
+Euro (EUR)
+sri lanka
+Sri Lankan rupee (LKR)
+sudan
+Sudanese pound (SDG)
+suriname
+Surinamese dollar (SRD)
+swaziland
+Swazi lilangeni (SZL)
+sweden
+Swedish krona (SEK)
+switzerland
+Swiss franc (CHF)
+syria
+Syrian pound (SYP)
+são tomé and príncipe
+São Tomé and Príncipe dobra (STD)
+taiwan (republic of china)
+New Taiwan dollar (TWD)
+tajikistan
+Tajikistani somoni (TJS)
+tanzania
+Tanzanian shilling (TZS)
+thailand
+Thai baht (THB)
+togo
+West African CFA franc (XOF)
+tonga
+Tongan paʻanga (TOP)
+transnistria
+Transnistrian ruble
+trinidad and tobago
+Trinidad and Tobago dollar (TTD)
+tristan da cunha
+Saint Helena pound (SHP),Tristan da Cunha pound
+tunisia
+Tunisian dinar (TND)
+turkey
+Turkish lira (TRY)
+turkmenistan
+Turkmenistani manat (TMT)
+turks and caicos islands
+United States dollar (USD)
+tuvalu
+Australian dollar (AUD),Tuvaluan dollar
+uganda
+Ugandan shilling (UGX)
+ukraine
+Ukrainian hryvnia (UAH)
+united arab emirates
+United Arab Emirates dirham (AED)
+united kingdom
+British pound (GBP)
+united states
+United States dollar (USD)
+uruguay
+Uruguayan peso (UYU)
+uzbekistan
+Uzbekistani som (UZS)
+vanuatu
+Vanuatu vatu (VUV)
+vatican city
+Euro (EUR)
+venezuela
+Venezuelan bolívar (VEF)
+vietnam
+Vietnamese đồng (VND)
+wallis and futuna
+CFP franc (XPF)
+yemen
+Yemeni rial (YER)
+zambia
+Zambian kwacha (ZMK)
+zimbabwe
+Botswana pula (BWP),British pound (GBP),Euro (EUR),South African rand (ZAR),United States dollar (USD),Zimbabwean dollar (ZWL)
View
3  share/goodie/currency_in/fetch.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+mkdir -p download
+wget "http://en.wikipedia.org/wiki/List_of_circulating_currencies" -O download/page.dat
View
68 share/goodie/currency_in/parse.py
@@ -0,0 +1,68 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# Released under the GPL v2 license
+# https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+
+import lxml.html
+import sys
+
+#url = "http://en.wikipedia.org/wiki/List_of_circulating_currencies"
+url = "https://secure.wikimedia.org/wikipedia/en/wiki/List_of_circulating_currencies"
+
+countries = {}; # country:[[currency, code] [currency, code],...]
+country = "" # store current country for each row
+currency = "" # store current currency for each row
+iso_code = "" # store current iso code for currency
+description = "" # store currency and iso code when saving into file
+
+def add_currency(country, currency, iso_code, countries):
+ "Add country into countries list"
+ country = country.encode("utf8")
+ if country in countries:
+ countries[country].append([currency, iso_code])
+ else:
+ countries[country] = [[currency, iso_code]]
+
+def clear_text(text):
+ "Clear text of anotations in []. When e.g. 'Ascension pound[A]' contains [A]"
+ start = text.find("[")
+ if start != -1:
+ text = text[:start]
+ return text
+
+tree = lxml.html.parse("download/page.dat").getroot()
+tables = tree.find_class("wikitable sortable")
+for table in tables:
+ for row in table.findall('tr'):
+ cells = row.findall('td')
+ if len(cells) == 6:
+ country = cells[0].text_content()
+ currency = cells[1].text_content()
+ iso_code = cells[3].text_content()
+
+ if len(cells) == 5:
+ currency = cells[0].text_content()
+ iso_code = cells[2].text_content()
+
+ currency = clear_text(currency)
+ iso_code = iso_code if iso_code != "None" else ""
+
+ if currency != "None" and currency != "":
+ add_currency(country[1:], currency, iso_code, countries)
+
+"Make output file 'currency.txt' as Perl 'hash table' ready for 'CurrencyIn.pm' module"
+output = "currency.txt"
+f= open(output, "w")
+result = []
+for country in sorted(countries):
+ description = ""
+ formated_record = []
+
+ for record in countries[country]:
+ iso_code = "" if record[1] == "" else (" (" + record[1] + ")")
+ currency = record[0]
+ formated_record.append((currency + iso_code).encode("utf8"))
+ description = ','.join(str(x) for x in formated_record)
+ f.write(country.lower() + "\n" + description + "\n")
+f.close()
View
5 share/goodie/currency_in/parse.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+# Make currency.txt:
+python parse.py
+
Something went wrong with that request. Please try again.