Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gmanroney committed Aug 20, 2017
0 parents commit bf5cc9a
Show file tree
Hide file tree
Showing 2 changed files with 343 additions and 0 deletions.
253 changes: 253 additions & 0 deletions cardbinlist.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
Afghanistan
Aland-Islands
Albania
Algeria
American-Samoa
Andorra
Angola
Anguilla
Antarctica
Antigua-and-Barbuda
Argentina
Armenia
Aruba
Australia
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belgium
Belize
Benin
Bermuda
Bhutan
Bolivia
Bosnia-and-Herzegovina
Botswana
Bouvet-Island
Brazil
British-Indian-Ocean-Territory
Brunei-Darussalam
Bulgaria
Burkina-Faso
Burundi
Cambodia
Cameroon
Canada
Cape-Verde
Caribbean-Netherlands
Cayman-Islands
Central-African-Republic
Chad
Chile
China
Christmas-Island
Cocos-Keeling-Islands
Colombia
Comoros
Congo
Cook-Islands
Costa-Rica
Cote-d-Ivoire
Croatia
Cuba
Cura
Cyprus
Czech-Republic
Democratic-Republic-of-the-Congo
Denmark
Djibouti
Dominica
Dominican-Republic
Ecuador
Egypt
El-Salvador
Equatorial-Guinea
Eritrea
Estonia
Ethiopia
Falkland-Islands
Faroe-Islands
Fiji
Finland
France
French-Guiana
French-Polynesia
French-Southern-Territories
Gabon
Gambia
Gaza-Strip
Georgia
Germany
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe
Guam
Guatemala
Guernsey
Guinea
Guinea-Bissau
Guyana
Haiti
Heard-and-McDonald-Islands
Honduras
Hong-Kong
Hungary
Iceland
India
Indonesia
Iran
Iraq
Ireland
Isle-of-Man
Israel
Italy
Jamaica
Japan
Jersey
Jordan
Kazakhstan
Kenya
Kiribati
Kosovo
Kuwait
Kyrgyzstan
Lao-People-s-Democratic-Republic
Latvia
Lebanon
Lesotho
Liberia
Libya
Liechtenstein
Lithuania
Luxembourg
Macau
Macedonia
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall-Islands
Martinique
Mauritania
Mauritius
Mayotte
Mexico
Micronesia
Moldova
Monaco
Mongolia
Montenegro
Montserrat
Morocco
Mozambique
Myanmar
Namibia
Nauru
Nepal
Netherlands-Antilles
New-Caledonia
New-Zealand
Nicaragua
Niger
Nigeria
Niue
Norfolk-Island
North-Korea
Northern-Mariana-Islands
Norway
Oman
Pakistan
Palau
Palestinian-Territory
Panama
Papua-New-Guinea
Paraguay
Peru
Philippines
Pitcairn
Poland
Portugal
Puerto-Rico
Qatar
Reunion
Romania
Russian-Federation
Rwanda
Saint-Barth
lemy
Saint-Helena
Saint-Kitts-and-Nevis
Saint-Lucia
Saint-Martin-France
Saint-Martin-Pays-Bas
Saint-Vincent-and-the-Grenadines
Samoa
San-Marino
Sao-Tome-and-Principe
Saudi-Arabia
Senegal
Serbia
Seychelles
Sierra-Leone
Singapore
Slovakia-Slovak-Republic
Slovenia
Solomon-Islands
Somalia
South-Africa
South-Georgia-and-the-South-Sandwich-Islands
South-Korea
South-Sudan
Spain
Sri-Lanka
St.-Pierre-and-Miquelon
Sudan
Suriname
Svalbard-and-Jan-Mayen-Islands
Swaziland
Sweden
Switzerland
Syria
Taiwan
Tajikistan
Tanzania
Thailand
The-Netherlands
Timor-Leste
Togo
Tokelau
Tonga
Trinidad-and-Tobago
Tunisia
Turkey
Turkmenistan
Turks-and-Caicos-Islands
Tuvalu
Uganda
Ukraine
United-Arab-Emirates
United-Kingdom
United-States
United-States-Minor-Outlying-Islands
Uruguay
Uzbekistan
Vanuatu
Vatican
Venezuela
Vietnam
Virgin-Islands-British
Virgin-Islands-U-S.
Wallis-and-Futuna-Islands
Western-Sahara
Yemen
Zambia
Zimbabwe
90 changes: 90 additions & 0 deletions cardbinlist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/python
from bs4 import BeautifulSoup
from IPython.display import Image
import urllib
import csv
import os.path

def getCountryPageRows(ofile,country,page):

# Create file for country and generate URL
tableCount = 0
urlPage = page - 1
writer = csv.writer(ofile, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
if urlPage == 0:
urlExt=country+".html"
else:
urlExt=country+".html?page="+str(urlPage)

# Read page
r = urllib.urlopen('https://www.cardbinlist.com/bin-list-'+urlExt).read()

# Parse page using BeautifulSoup
soup = BeautifulSoup(r,"html.parser")

# Find tables in the page
tables=soup.findAll("table",attrs={"class":"full-width text-xs-left mt-1" })

# Loop through tables in the page
for table in tables:

headings = [th.get_text() for th in table.find("tr").find_all("th")]
datasets = []

for row in table.find_all("tr")[1:]:

dataset = zip(headings, (td.get_text() for td in row.find_all("td")))
datasets.append(dataset)

# If records contain bin list information write to file
for record in datasets:
if (record[0])[0] == "Bank Issuer":
IssuingBankNetwork=(record[1])[1]
IssuingBankBIN=(record[2])[1]
IssuingBank=(record[0])[1]
if len((record[0])[1]) == 0:
IssuingBank="Undefined"
row=IssuingBank,IssuingBankNetwork,IssuingBankBIN
writer.writerow(row)
tableCount = tableCount + 1

# Return count of bin records found in the page to decide
# if we have found all or not
return tableCount

def getCountry(country):

# Create file for country
pageCount=0
totalRecords=0
ofile = open('bin_'+country+'.csv', "wb")

# Loop until no more bin records found
keepGoing = True
while keepGoing:
pageCount += 1

# getCountryPageRows parses each page and gets records
tableCountFound = getCountryPageRows(ofile,country,pageCount)
totalRecords = totalRecords + tableCountFound
if tableCountFound == 0:
keepGoing = False
print "For country "+country+ " records found = ",totalRecords

# Close file when done
ofile.close()

# Read list of countries from configuration file
countries = []
my_path = os.path.abspath(os.path.dirname(__file__))
path = os.path.join(my_path, "cardbinlist.cfg")
with open(path) as file:
for line in file:
line = line.strip()
countries.append(line)

# Loop through list of countries and get bin list from cardbinlist.com site
for line in countries:
line = line.lower()
getCountry(line)

0 comments on commit bf5cc9a

Please sign in to comment.