Simplify some code

This commit is contained in:
vvMelody
2019-12-04 14:04:03 +08:00
parent d1da167b82
commit c6d307b2bc
4 changed files with 59 additions and 67 deletions

View File

@@ -1,17 +1,11 @@
import tld
import json
def load_file(path):
with open(path, 'r') as f:
result = [line.rstrip('\n').encode('utf-8').decode('utf-8') for line in f]
return '\n'.join(result)
def host(string):
if string and '*' not in string:
try:
return tld.get_fld(string, fix_protocol=True)
except:
return False
if string and '*' not in string:
return tld.get_fld(string, fix_protocol=True, fail_silently=True)
def load_json(file):
return json.loads(load_file('./db/details.json'))
with open(file) as f:
return json.load(f)