2014-08-06 09:43:40 +00:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
# -*-coding:UTF-8 -*
|
2014-08-14 15:55:18 +00:00
|
|
|
import pprint
|
|
|
|
import time
|
|
|
|
from packages import Paste
|
2014-08-06 09:43:40 +00:00
|
|
|
from packages import lib_refine
|
|
|
|
from pubsublogger import publisher
|
|
|
|
|
2014-08-20 13:14:57 +00:00
|
|
|
import Helper
|
2014-08-06 09:43:40 +00:00
|
|
|
|
2014-08-20 13:14:57 +00:00
|
|
|
if __name__ == "__main__":
|
2014-08-22 15:35:40 +00:00
|
|
|
publisher.port = 6380
|
2014-08-20 13:14:57 +00:00
|
|
|
publisher.channel = "Script"
|
2014-08-06 09:43:40 +00:00
|
|
|
|
2014-08-20 13:14:57 +00:00
|
|
|
config_section = 'PubSub_Categ'
|
|
|
|
config_channel = 'channel_0'
|
|
|
|
subscriber_name = 'cards'
|
2014-08-14 15:55:18 +00:00
|
|
|
|
2014-08-20 13:14:57 +00:00
|
|
|
h = Helper.Redis_Queues(config_section, config_channel, subscriber_name)
|
2014-08-06 09:43:40 +00:00
|
|
|
|
|
|
|
# FUNCTIONS #
|
|
|
|
publisher.info("Creditcard script subscribed to channel creditcard_categ")
|
|
|
|
|
2014-08-20 13:14:57 +00:00
|
|
|
message = h.redis_rpop()
|
2014-08-06 09:43:40 +00:00
|
|
|
prec_filename = None
|
|
|
|
|
|
|
|
creditcard_regex = "4[0-9]{12}(?:[0-9]{3})?"
|
|
|
|
|
2014-08-14 15:55:18 +00:00
|
|
|
# mastercard_regex = "5[1-5]\d{2}([\ \-]?)\d{4}\1\d{4}\1\d{4}"
|
|
|
|
# visa_regex = "4\d{3}([\ \-]?)\d{4}\1\d{4}\1\d{4}"
|
2014-08-20 13:14:57 +00:00
|
|
|
# discover_regex = "6(?:011\d\d|5\d{4}|4[4-9]\d{3}|22(?:1(?:2[6-9]|
|
|
|
|
# [3-9]\d)|[2-8]\d\d|9(?:[01]\d|2[0-5])))\d{10}"
|
2014-08-14 15:55:18 +00:00
|
|
|
# jcb_regex = "35(?:2[89]|[3-8]\d)([\ \-]?)\d{4}\1\d{4}\1\d{4}"
|
|
|
|
# amex_regex = "3[47]\d\d([\ \-]?)\d{6}\1\d{5}"
|
|
|
|
# chinaUP_regex = "62[0-5]\d{13,16}"
|
|
|
|
# maestro_regex = "(?:5[0678]\d\d|6304|6390|67\d\d)\d{8,15}"
|
2014-08-06 09:43:40 +00:00
|
|
|
|
|
|
|
while True:
|
2014-08-14 15:55:18 +00:00
|
|
|
if message is not None:
|
|
|
|
channel, filename, word, score = message.split()
|
2014-08-06 09:43:40 +00:00
|
|
|
|
2014-08-14 15:55:18 +00:00
|
|
|
if prec_filename is None or filename != prec_filename:
|
|
|
|
creditcard_set = set([])
|
|
|
|
PST = Paste.Paste(filename)
|
2014-08-06 09:43:40 +00:00
|
|
|
|
|
|
|
for x in PST.get_regex(creditcard_regex):
|
|
|
|
if lib_refine.is_luhn_valid(x):
|
2014-08-14 15:55:18 +00:00
|
|
|
creditcard_set.add(x)
|
2014-08-06 09:43:40 +00:00
|
|
|
|
2014-08-14 15:55:18 +00:00
|
|
|
PST.__setattr__(channel, creditcard_set)
|
2014-08-21 10:22:07 +00:00
|
|
|
PST.save_attribute_redis(channel, creditcard_set)
|
2014-08-06 09:43:40 +00:00
|
|
|
|
2014-08-14 15:55:18 +00:00
|
|
|
pprint.pprint(creditcard_set)
|
2014-08-20 13:14:57 +00:00
|
|
|
to_print = 'CreditCard;{};{};{};'.format(
|
|
|
|
PST.p_source, PST.p_date, PST.p_name)
|
2014-08-14 15:55:18 +00:00
|
|
|
if (len(creditcard_set) > 0):
|
2014-08-20 13:14:57 +00:00
|
|
|
publisher.critical('{}Checked {} valid number(s)'.format(
|
|
|
|
to_print, len(creditcard_set)))
|
2014-08-06 09:43:40 +00:00
|
|
|
else:
|
2014-08-14 15:55:18 +00:00
|
|
|
publisher.info('{}CreditCard related'.format(to_print))
|
2014-08-06 09:43:40 +00:00
|
|
|
|
|
|
|
prec_filename = filename
|
|
|
|
|
|
|
|
else:
|
2014-08-20 13:14:57 +00:00
|
|
|
if h.redis_queue_shutdown():
|
2014-08-06 09:43:40 +00:00
|
|
|
print "Shutdown Flag Up: Terminating"
|
|
|
|
publisher.warning("Shutdown Flag Up: Terminating.")
|
|
|
|
break
|
|
|
|
publisher.debug("Script creditcard is idling 1m")
|
|
|
|
time.sleep(60)
|
|
|
|
|
2014-08-20 13:14:57 +00:00
|
|
|
message = h.redis_rpop()
|