mirror of
https://github.com/RussellChamp/tilde-projects.git
synced 2026-10-28 00:22:34 +00:00
black
This commit is contained in:
38 files changed
+4549
-2523
No files matched your search
+113
-57
@@ -5,12 +5,15 @@ import re
|
||||
def ping(pong):
|
||||
ircsock.send("PONG {}\n".format(pong.split(" ")[1]))
|
||||
|
||||
def sendmsg(ircsock, chan , msg):
|
||||
|
||||
def sendmsg(ircsock, chan, msg):
|
||||
ircsock.send("PRIVMSG {} :{}\r\n".format(chan, msg))
|
||||
|
||||
|
||||
def joinchan(ircsock, chan):
|
||||
ircsock.send("JOIN {}\n".format(chan))
|
||||
|
||||
|
||||
# integer number to english word conversion
|
||||
# can be used for numbers as large as 999 vigintillion
|
||||
# (vigintillion --> 10 to the power 60)
|
||||
@@ -32,7 +35,7 @@ def int2word(n):
|
||||
if q < -2:
|
||||
break
|
||||
else:
|
||||
if q >= 0:
|
||||
if q >= 0:
|
||||
n3.append(int(r[:3]))
|
||||
elif q >= -1:
|
||||
n3.append(int(r[:2]))
|
||||
@@ -40,7 +43,7 @@ def int2word(n):
|
||||
n3.append(int(r[:1]))
|
||||
r1 = r
|
||||
|
||||
#print n3 # test
|
||||
# print n3 # test
|
||||
|
||||
# break each group of 3 digits into
|
||||
# ones, tens/twenties, hundreds
|
||||
@@ -48,9 +51,9 @@ def int2word(n):
|
||||
nw = ""
|
||||
for i, x in enumerate(n3):
|
||||
b1 = x % 10
|
||||
b2 = (x % 100)//10
|
||||
b3 = (x % 1000)//100
|
||||
#print b1, b2, b3 # test
|
||||
b2 = (x % 100) // 10
|
||||
b3 = (x % 1000) // 100
|
||||
# print b1, b2, b3 # test
|
||||
if x == 0:
|
||||
continue # skip
|
||||
else:
|
||||
@@ -64,33 +67,85 @@ def int2word(n):
|
||||
if b3 > 0:
|
||||
nw = ones[b3] + "hundred " + nw
|
||||
return nw
|
||||
|
||||
|
||||
############# globals ################
|
||||
ones = ["", "one ","two ","three ","four ", "five ",
|
||||
"six ","seven ","eight ","nine "]
|
||||
tens = ["ten ","eleven ","twelve ","thirteen ", "fourteen ",
|
||||
"fifteen ","sixteen ","seventeen ","eighteen ","nineteen "]
|
||||
twenties = ["","","twenty ","thirty ","forty ",
|
||||
"fifty ","sixty ","seventy ","eighty ","ninety "]
|
||||
thousands = ["","thousand ","million ", "billion ", "trillion ",
|
||||
"quadrillion ", "quintillion ", "sextillion ", "septillion ","octillion ",
|
||||
"nonillion ", "decillion ", "undecillion ", "duodecillion ", "tredecillion ",
|
||||
"quattuordecillion ", "sexdecillion ", "septendecillion ", "octodecillion ",
|
||||
"novemdecillion ", "vigintillion "]
|
||||
ones = [
|
||||
"",
|
||||
"one ",
|
||||
"two ",
|
||||
"three ",
|
||||
"four ",
|
||||
"five ",
|
||||
"six ",
|
||||
"seven ",
|
||||
"eight ",
|
||||
"nine ",
|
||||
]
|
||||
tens = [
|
||||
"ten ",
|
||||
"eleven ",
|
||||
"twelve ",
|
||||
"thirteen ",
|
||||
"fourteen ",
|
||||
"fifteen ",
|
||||
"sixteen ",
|
||||
"seventeen ",
|
||||
"eighteen ",
|
||||
"nineteen ",
|
||||
]
|
||||
twenties = [
|
||||
"",
|
||||
"",
|
||||
"twenty ",
|
||||
"thirty ",
|
||||
"forty ",
|
||||
"fifty ",
|
||||
"sixty ",
|
||||
"seventy ",
|
||||
"eighty ",
|
||||
"ninety ",
|
||||
]
|
||||
thousands = [
|
||||
"",
|
||||
"thousand ",
|
||||
"million ",
|
||||
"billion ",
|
||||
"trillion ",
|
||||
"quadrillion ",
|
||||
"quintillion ",
|
||||
"sextillion ",
|
||||
"septillion ",
|
||||
"octillion ",
|
||||
"nonillion ",
|
||||
"decillion ",
|
||||
"undecillion ",
|
||||
"duodecillion ",
|
||||
"tredecillion ",
|
||||
"quattuordecillion ",
|
||||
"sexdecillion ",
|
||||
"septendecillion ",
|
||||
"octodecillion ",
|
||||
"novemdecillion ",
|
||||
"vigintillion ",
|
||||
]
|
||||
|
||||
|
||||
def format_message(message):
|
||||
pattern = r'^:.*\!~(.*)@.* (.*) (.*) :(.*)'
|
||||
pattern = r"^:.*\!~(.*)@.* (.*) (.*) :(.*)"
|
||||
now = int(time.time())
|
||||
matches = re.match(pattern, message)
|
||||
if not matches:
|
||||
return ''
|
||||
return ""
|
||||
|
||||
nick = matches.group(1).strip()
|
||||
command = matches.group(2).strip()
|
||||
channel = matches.group(3).strip()
|
||||
nick = matches.group(1).strip()
|
||||
command = matches.group(2).strip()
|
||||
channel = matches.group(3).strip()
|
||||
message = matches.group(4).strip()
|
||||
|
||||
return "%s\t%s\t%s\t%s\t%s" % (now, nick, command, channel, message)
|
||||
|
||||
|
||||
def get_users():
|
||||
# thanks, ~dan!
|
||||
users = []
|
||||
@@ -102,46 +157,47 @@ def get_users():
|
||||
|
||||
return users
|
||||
|
||||
|
||||
def pretty_date(time=False):
|
||||
"""
|
||||
"""
|
||||
Get a datetime object or a int() Epoch timestamp and return a
|
||||
pretty string like 'an hour ago', 'Yesterday', '3 months ago',
|
||||
'just now', etc
|
||||
"""
|
||||
from datetime import datetime
|
||||
now = datetime.now()
|
||||
if type(time) is int:
|
||||
diff = now - datetime.fromtimestamp(time)
|
||||
elif isinstance(time,datetime):
|
||||
diff = now - time
|
||||
elif not time:
|
||||
diff = now - now
|
||||
second_diff = diff.seconds
|
||||
day_diff = diff.days
|
||||
from datetime import datetime
|
||||
|
||||
if day_diff < 0:
|
||||
return ''
|
||||
now = datetime.now()
|
||||
if type(time) is int:
|
||||
diff = now - datetime.fromtimestamp(time)
|
||||
elif isinstance(time, datetime):
|
||||
diff = now - time
|
||||
elif not time:
|
||||
diff = now - now
|
||||
second_diff = diff.seconds
|
||||
day_diff = diff.days
|
||||
|
||||
if day_diff == 0:
|
||||
if second_diff < 10:
|
||||
return "just now"
|
||||
if second_diff < 60:
|
||||
return str(second_diff) + " seconds ago"
|
||||
if second_diff < 120:
|
||||
return "a minute ago"
|
||||
if second_diff < 3600:
|
||||
return str(second_diff / 60) + " minutes ago"
|
||||
if second_diff < 7200:
|
||||
return "an hour ago"
|
||||
if second_diff < 86400:
|
||||
return str(second_diff / 3600) + " hours ago"
|
||||
if day_diff == 1:
|
||||
return "Yesterday"
|
||||
if day_diff < 7:
|
||||
return str(day_diff) + " days ago"
|
||||
if day_diff < 31:
|
||||
return str(day_diff / 7) + " weeks ago"
|
||||
if day_diff < 365:
|
||||
return str(day_diff / 30) + " months ago"
|
||||
return str(day_diff / 365) + " years ago"
|
||||
if day_diff < 0:
|
||||
return ""
|
||||
|
||||
if day_diff == 0:
|
||||
if second_diff < 10:
|
||||
return "just now"
|
||||
if second_diff < 60:
|
||||
return str(second_diff) + " seconds ago"
|
||||
if second_diff < 120:
|
||||
return "a minute ago"
|
||||
if second_diff < 3600:
|
||||
return str(second_diff / 60) + " minutes ago"
|
||||
if second_diff < 7200:
|
||||
return "an hour ago"
|
||||
if second_diff < 86400:
|
||||
return str(second_diff / 3600) + " hours ago"
|
||||
if day_diff == 1:
|
||||
return "Yesterday"
|
||||
if day_diff < 7:
|
||||
return str(day_diff) + " days ago"
|
||||
if day_diff < 31:
|
||||
return str(day_diff / 7) + " weeks ago"
|
||||
if day_diff < 365:
|
||||
return str(day_diff / 30) + " months ago"
|
||||
return str(day_diff / 365) + " years ago"
|
||||
Reference in new issue
Block a user