2016-04-19 17:40:59 +00:00
|
|
|
"""Some functions that don't fit in any other file"""
|
2016-05-19 18:17:20 +00:00
|
|
|
from constants import mods
|
2016-06-02 19:50:10 +00:00
|
|
|
from time import gmtime, strftime
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
def stringToBool(s):
|
|
|
|
"""
|
|
|
|
Convert a string (True/true/1) to bool
|
|
|
|
|
|
|
|
s -- string/int value
|
|
|
|
return -- True/False
|
|
|
|
"""
|
|
|
|
|
|
|
|
return (s == "True" or s== "true" or s == "1" or s == 1)
|
|
|
|
|
|
|
|
|
|
|
|
def hexString(s):
|
|
|
|
"""
|
|
|
|
Output s' bytes in HEX
|
|
|
|
|
|
|
|
s -- string
|
|
|
|
return -- string with hex value
|
|
|
|
"""
|
|
|
|
|
|
|
|
return ":".join("{:02x}".format(ord(c)) for c in s)
|
2016-05-19 18:17:20 +00:00
|
|
|
|
|
|
|
def readableMods(__mods):
|
|
|
|
"""
|
|
|
|
Return a string with readable std mods.
|
|
|
|
Used to convert a mods number for oppai
|
|
|
|
|
|
|
|
__mods -- mods bitwise number
|
|
|
|
return -- readable mods string, eg HDDT
|
|
|
|
"""
|
|
|
|
r = ""
|
|
|
|
if __mods == 0:
|
|
|
|
return r
|
|
|
|
if __mods & mods.NoFail > 0:
|
|
|
|
r += "NF"
|
|
|
|
if __mods & mods.Easy > 0:
|
|
|
|
r += "EZ"
|
|
|
|
if __mods & mods.Hidden > 0:
|
|
|
|
r += "HD"
|
|
|
|
if __mods & mods.HardRock > 0:
|
|
|
|
r += "HR"
|
|
|
|
if __mods & mods.DoubleTime > 0:
|
|
|
|
r += "DT"
|
|
|
|
if __mods & mods.HalfTime > 0:
|
|
|
|
r += "HT"
|
|
|
|
if __mods & mods.Flashlight > 0:
|
|
|
|
r += "FL"
|
|
|
|
if __mods & mods.SpunOut > 0:
|
|
|
|
r += "SO"
|
|
|
|
|
|
|
|
return r
|
2016-05-28 18:26:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
def strContains(s, w):
|
|
|
|
return (' ' + w + ' ') in (' ' + s + ' ')
|
2016-06-02 19:50:10 +00:00
|
|
|
|
|
|
|
def getTimestamp():
|
|
|
|
"""
|
|
|
|
Return current time in YYYY-MM-DD HH:MM:SS format.
|
|
|
|
Used in logs.
|
|
|
|
"""
|
|
|
|
return strftime("%Y-%m-%d %H:%M:%S", gmtime())
|