-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmarkdead.py
53 lines (49 loc) · 1.84 KB
/
markdead.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
import csv, re, argparse, requests
GOOGLE_FORM_RE = re.compile(
r"https:\/\/docs\.google\.com\/forms\/d\/e\/[A-Za-z0-9_-]{56}\/\S+"
)
def markdead(dead: "list[str]") -> None:
data = []
with open('data.csv', newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in reader:
data.append(row)
with open('data.csv', 'w') as f:
for row in data:
if row[3] in dead:
row[5] = "no"
f.write(f"{','.join(row)}\n")
def auto():
done = set()
dead = set()
with open('data.csv', newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in reader:
if row[3] in done or not GOOGLE_FORM_RE.match(row[3]) or row[5] == "no":
continue
else:
print(row[3])
resp = requests.get(
row[3],
headers={
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0"
}
)
print(resp)
if resp.status_code in [403, 410]:
dead.add(row[3])
done.add(row[3])
markdead(list(dead))
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog = "markdead for CatPhish",
description="This program marks rows of data in CatPhish as dead"
)
command_group = parser.add_mutually_exclusive_group(required=True)
command_group.add_argument("-d", "--dead", required=False, nargs="+", help="Mark an item as dead")
command_group.add_argument("-a", "--auto", action="store_true", help="Automatically detect if items are dead")
args = parser.parse_args()
if args.dead:
markdead(args.dead)
elif args.auto:
auto()