Skip to content

Instantly share code, notes, and snippets.

@shawa
Created December 27, 2017 02:04
Show Gist options
  • Save shawa/fd3380ebe1aa8dfe5cf3569d9a719aee to your computer and use it in GitHub Desktop.
Save shawa/fd3380ebe1aa8dfe5cf3569d9a719aee to your computer and use it in GitHub Desktop.
get yer cool extensions while they're hot!
import sys
import requests
URL = 'https://eventphone.de/guru2/phonebook?event=34C3&s=&page=1&format=json'
patterns = {
'doubled': lambda x: x[0] == x[1] and x[2] == x[3],
'alternate': lambda x: x[0] == x[2] and x[1] == x[3],
'end ten': lambda x: x[0] == x[1] and x[3] == '0',
'middle same': lambda x: x[1] == x[2],
'three': lambda x: x[0] == x[1] == x[2] or x[1] == x[2] == x[3],
'two': lambda x: x[0] == x[1] or x[1] == x[2] or x[2] == x[3],
'ascending': lambda x: sorted(x) == x,
'descending': lambda x: reversed(sorted(x)) == x,
'boring as shit': lambda x: True
}
def parse(lines):
for line in lines:
if not set(line) < set('1 2 3 4 5 6 7 8 9 0'.split()):
# spurious
continue
try:
yield int(line)
except ValueError:
continue
def pals(xs):
for name, check in patterns.items():
print('\n' + name)
for x in xs:
if check(str(x)):
yield x
data = requests.get(URL).json()
numbers = set(parse(x['extension'] for x in data))
AVAILABLE = set(range(2100, 8999)) - numbers
for p in pals(AVAILABLE):
print(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment