-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal_sites.py
More file actions
27 lines (24 loc) · 804 Bytes
/
external_sites.py
File metadata and controls
27 lines (24 loc) · 804 Bytes
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
import collections
import sys
sites = collections.defaultdict(set)
for filename in sys.argv[1:]:
for line in open(filename):
i = 0
while True:
site = None
i = line.find("http://", i)
if i > -1:
i += len("http://")
for j in range(i, len(line)):
if not (line[j].isalnum() or line[j] in ".-"):
site = line[i:j].lower()
break
if site and "." in site:
sites[site].add(filename)
i = j
else:
break
for site in sorted(sites):
print("{0} is referred to in:".format(site))
for filename in sorted(sites[site], key=str.lower):
print(" {0}".format(filename))