def main(): arg_parser = argparse.ArgumentParser() arg_parser.add_argument('start_int', type=int, help='The starting base 10 integer') arg_parser.add_argument('end_int', type=int, help='The ending base 10 integer') arg_parser.add_argument('--exclusion-file', help='A path to a file containing lines of base 10 integers to ' 'exclude from the print out') arg_parser.add_argument('--exclusion-file-62', help='A path to a file containing lines of base 62 integers to ' 'exclude from the print out') arg_parser.add_argument('--range', type=int, help='Generate a list using the range notation of the given size', default=1) arg_parser.add_argument('--legacy-alphabet', action='store_true', help='Use an alternate alphabet (not Puush alphabet)') args = arg_parser.parse_args() if args.legacy_alphabet: alphabet = ALPHABET separator = ',' else: alphabet = ALPHABET_PUUSH separator = ':' if args.range and not (1 <= args.range <= 100): raise Exception("Range should be positive and not too large") exclusion_set = set() if args.exclusion_file: with open(args.exclusion_file, 'rt') as f: for line in f: exclusion_set.add(int(line.strip())) if args.exclusion_file_62: with open(args.exclusion_file_62, 'rt') as f: for line in f: exclusion_set.add(base62_decode(line.strip(), alphabet)) l = [] for i in xrange(args.start_int, args.end_int + 1): if i not in exclusion_set: l.append(i) if i in exclusion_set or i == args.end_int or len(l) >= args.range: if len(l) == 1: print(base62_encode(l[0], alphabet)) elif l: print('{}{}{}'.format( base62_encode(l[0], alphabet), separator, base62_encode(l[-1], alphabet) )) l = []
def check_valid_id(self): id_name = base62_encode(self.max_item_id, ALPHABET_PUUSH) try: _logger.debug('Check if %s is valid', id_name) conn = httplib.HTTPConnection("puu.sh") conn.request("HEAD", '/' + id_name) res = conn.getresponse() _logger.debug('Got %d %s', res.status, res.reason) if res.status == 200: return True except Exception: _logger.exception('Error checking valid url {}'.format(id_name))
def check_valid_id(self): id_name = base62_encode(self.max_item_id, ALPHABET_PUUSH) try: _logger.debug('Check if %s is valid', id_name) conn = httplib.HTTPConnection("puu.sh") conn.request("HEAD", id_name) res = conn.getresponse() _logger.debug('Got %d %s', res.status, res.reason) if res.status == 200: return True except Exception: _logger.exception('Error checking valid url {}'.format(id_name))
def get_expanded_item_name(item_name): if ',' in item_name: alphabet = ALPHABET start_item, end_item = item_name.split(',', 1) elif ':' in item_name: alphabet = ALPHABET_PUUSH start_item, end_item = item_name.split(':', 1) else: start_item = item_name end_item = item_name alphabet = ALPHABET_PUUSH start_num = base62_decode(start_item, alphabet) end_num = base62_decode(end_item, alphabet) for num in xrange(start_num, end_num + 1): yield base62_encode(num, alphabet)