-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathutils.py
More file actions
49 lines (37 loc) · 1014 Bytes
/
utils.py
File metadata and controls
49 lines (37 loc) · 1014 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys
import json
import hashlib
import urllib.request
import urllib.error
def read_json(path):
data = None
try:
with open(path, "r") as f:
data = json.loads(f.read())
except FileNotFoundError:
pass
return data
def write_json(data, path, prettify=True):
with open(path, "w") as f:
f.write(pretty(data) if prettify else json.dumps(data))
def confirmation(msg):
print(msg)
choice = input("Accept? ")
choice = choice.strip().lower()
return choice == "y" or choice == "yes"
def pretty(data):
return json.dumps(data, indent=2)
def user_error(msg):
sys.exit("Error: {}".format(msg))
def email_sha256(email):
hash = hashlib.sha256()
hash.update(email.encode("utf-8"))
hash = hash.hexdigest()
data = read_json("tmp_emails.json")
if not data:
data = {}
if email in data and data[email] == hash:
return hash
data[email] = hash
write_json(data, "tmp_emails.json")
return hash