-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiterator.py
105 lines (95 loc) · 2.58 KB
/
iterator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import requests
import time
import itertools
SLEEP = 0.5
saved = []
def get(url):
response = requests.get(url, timeout = 5)
#print(response, url.split('/')[-1].split('.')[0])
time.sleep(SLEEP)
return response.status_code != 404
def trial(url, ans):
while True:
try:
if get(url+ans):
return url+ans
return
except Exception:
print('failed to connect on '+str(ans))
def normalize(x):
return x.replace(" ","").lower()
def nopunct(x):
return x.replace(",","").replace(";","").replace("'","").replace(":","").replace(".","").replace('-','')
def concat(x):
s = ''
for i in x:
s += i
return s
def load_dict(x):
alphabet = "abcdefghijklmnopqrstuvwxyz"
num = "0123456789"
f = None
if x == 'enable': # ~174000 words
f = open('enable2k.txt')
if x == 'ukacd': # ? words
f = open('UKACD17.txt')
if x == '2a': # ? words
f = open('web2a.txt')
if x == 'countries':
f = open('countries.txt')
if x == 'cities':
f = open('cities.txt')
if x == 'names': # 1325 names
f = open('propernames.txt')
if x == 'popular':
f = open('popular.txt')
if x == 'phrase':
f = open('phrases-wiki.txt')
if x == 'newnoun':
f = open('base_forms_en_nouns.txt')
if x == 'numbers':
return [str(k) for k in range(100000)]
if x == 'negative':
return [str(-k) for k in range(1000)]
if x == 'deci1':
return [str(k/10) for k in range(10000)]
if x == 'deci2':
return [str(k/100) for k in range(10000)]
if x == 'deci3':
return [str(k/1000) for k in range(10000)]
if x == 'letters':
return [chr(i) for i in range(97,123)]
if x == 'bin':
return ['{0:b}'.format(i) for i in range(10000)]
if x == 'two':
return itertools.product(alphabet, repeat=2)
if x == 'tla':
return itertools.product(alphabet, repeat=3)
if x == 'fla':
return itertools.product(alphabet, repeat=4)
if x == 'musical':
return itertools.product('abcdefg', repeat=7)
if x == 'vowels':
return itertools.product('aeiouy', repeat=5)
if x == 'alphanum2':
return itertools.product(alphabet+num, repeat=2)
if x == 'alphanum3':
return itertools.product(alphabet+num, repeat=3)
return f.read().split("\n")
def d2b(i):
return '{0:b}'.format(i)
def main(url):
root = "http://bit.ly/"
let = load_dict('letters')
l = ['ois'+x+'ash'+y+'n' for x in let for y in let]
print(len(l))
st = 0
begin = '' # first string to start at.
for i in l:
if i > begin:
q = i
if trial(root+url, str(q)): saved.append(url+str(q))
if st%25 == 0: print(st, saved, url+str(q))
st += 1
print(saved)
main("")