-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
73 lines (58 loc) · 1.64 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
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: UTF-8 -*-
import time
from data import *
def isSign(sign):
for _ in SIGN_NAMES :
if sign == _.lower() :
return True
return False
def isPlanet(planet):
for _ in PLANET_NAMES_LUNAR :
if planet == _.lower() :
return True
return False
def isNakshatra(nakshatra):
for _ in NAKSHATRA_NAMES :
if nakshatra == _.lower() :
return True
return False
def isDay(day):
for _ in WEEKDAYS :
if day == _.lower() :
return True
return False
def normalize(deg):
"""Adjusts deg between 0-360"""
while deg < 0.0:
deg += 360.0
while deg >= 360.0:
deg -= 360.0
return deg
# Make sure input is a number and not null
def inputNull():
input = raw_input()
if input.__len__() == 0:
input = 0
return input
# Return the opposite degree
def oppDeg(deg):
if deg < 180 :
deg += 180
else :
deg -= 180
return deg
# Return the julian day for the current system time. Unix Epoch begins on 1st Jan 1970, 00:00:00
def getJulian():
return 2440587.5 + (time.time() / 86400)
# Convert decimal float (deg.mmss) to degree string
def dec2deg(decimal):
deg = int(decimal)
min = int((decimal-deg) * 60)
sec = int((((decimal-deg) * 60) - min) * 60)
return str(deg) + '°' + str(min).zfill(2) + '\'' + str(sec).zfill(2) + '"'
# Convert seconds(int) to a time string (hh:mm:ss)
def sec2time(seconds):
sec = int(seconds % 60)
min = int((seconds - sec) % (60 * 60)) / 60
hrs = int((seconds - sec) - min) / (60 * 60)
return str(hrs).zfill(2) + 'h' + str(min).zfill(2) + 'm' + str(sec).zfill(2) + 's'