-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
58 lines (40 loc) · 1.2 KB
/
utils.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
import hashlib
import os
import random
import time
def get_id():
return hashlib.md5(str(time.time()).encode('utf8')).hexdigest()
def list_paths(root):
l = []
for dirname, _, filenames in os.walk(root):
for fn in filenames:
if fn.endswith('.py') and fn != '__init__.py':
l.append(os.path.join(dirname, fn))
return l
def import_path(p):
#assert p.endswith('.py')
#m = p[:-3].replace('/', '.')
# Use importlib instead?
#iname = "%s.%s.%s" % (istub, region, xn)
#m = importlib.import_module(iname)
try:
return __import__(p, fromlist=["dummy value"]) # __import requires non-empty fromlist to import submodules (foo.bar.baz)
except:
import pdb; pdb.set_trace()
x = 5
def pounds_to_kg(pounds):
if not pounds:
return ''
if pounds == '?':
return ''
kg = int(pounds) * 0.45359237
return int(round(kg, 0))
def inches_to_cm(inches=0, feet=0):
if not inches and not feet:
return ''
if inches == '?' or feet == '?':
return ''
feet, inches = int(feet), int(inches)
real_inches = inches + (feet * 12)
cm = real_inches * 2.54
return int(round(cm, 0))