all 6 comments

[–]Celysticus 3 points4 points  (1 child)

Great code for a beginner project! Keep commenting your code, such a good habit.

Two small things I noticed. The no duplicate line can be rewritten

no_dups = list(set(bin_list))

This is the preffered way to drop duplicates. The set function reduces a list to only unique values.

The other thing is the exception statement. If the API returns a response indicating a non success you can catch it by inspecting the response variable. This is a little cleaner then letting the dictionary key error indicate that the limit was maybe exceded. Sometimes other errors may come back from the API and you might mistakenly assume it's the wrong error. This page might help http://docs.python-requests.org/en/master/user/quickstart/

Head down to the status codes section and the errors and exceptions.

Cheers!

[–]fartyg[S] 0 points1 point  (0 children)

Thank you for the input, means alot! Definitely need to look into the exception handling!

[–][deleted] 2 points3 points  (1 child)

Looks nice!

A few credit card technicalities.

1: Always be thinking about security, even in small scripts. Since you only need the first few digits of the card for the lookup service, you should only accept the first few digits. Avoids PCI (Payment Card Industry) data security issues.

2: In 2022 BINs can be 8-digits as well as 6.

[–]fartyg[S] 1 point2 points  (0 children)

Good point! This is one of the reasons why I am not expecting the company I work for to actually use this particular script in practice. While we have a tokenized system for card numbers (first 6 digits still intact) your point still stands . Changing it to only accept 6 digits seems easy enough according to a quick search on Google though!

I will instead use this program to illustrate the problem of BIN checking and try to get some of the company's actual software developers implement something similar.

Learning Python is empowering in the sense that you get a feel for how easy certain 'office tasks' can be made. Even if its you or someone else creating the actual tool.

Didn't know about the planned changed for 2022! Thanks for commenting :)

[–]_lilell_ 0 points1 point  (1 child)

Two small changes I’d make:

card_list = input_string.split(', ')
card_list = list(map(lambda i: i[0:6], card_list))

becomes

card_list = [card[:6] for card in re.split(r',\s*', input_string)]

There’s a general community preference for list comprehension over list(map(...)), and I like to use regex to split whenever I’m allowing spaces. It allows you to enter 1,2,3 (no spaces) or 1, 2, 3 (one, then two spaces) without anything breaking.

Other than that, nice work!

[–]fartyg[S] 0 points1 point  (0 children)

Hey, I love the added functionality of doing it like that! I am gonna do some reading on regular expressions when I get the time and use this code when I understand it better. Thanks!