def search_for_ids(self): _logger.debug('Attempt search') api = self.api results = api.search('puu.sh', result_type='recent') id_names = [] _logger.debug('Got %d items', len(results)) for result in results: for url_obj in result.entities['urls']: url = url_obj['expanded_url'] match = re.search(r'puu.sh/([a-zA-Z0-9]{5})', url) if match: id_names.append(match.group(1)) id_ints = [base62_decode(s, ALPHABET_PUUSH) for s in id_names] id_ints = list(sorted(id_ints)) _logger.debug('Got %d item ids', len(id_ints)) if not id_ints: _logger.info('No IDs found. Quitting.') return self.max_item_id = id_ints[-1]
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)
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 = []