Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 18 additions & 41 deletions calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

history={}
class Date(datetime.datetime):
def __new__(s, *arg, **kwargs):
return datetime.datetime.__new__(s, *arg, **kwargs)
def __str__(s):
return s.strftime("%B").center(6+(7*3))
def __new__(cls, *arg, **kwargs):
return datetime.datetime.__new__(cls, *arg, **kwargs)
def __str__(self):
return self.strftime("%B").center(6+(7*3))
@property
def yday(s):
j=s.strftime("%d")
Expand All @@ -21,32 +21,23 @@ def yday(s):
k="\033[48;5;%dm%3d\033[0m"%(16+x if x<5 else 21, int(j),)
except KeyError:
k="%3d"%(int(j),)
pass
return show_day(k)
pass
pass
def count (n):
c=0
for _ in n:
c+=1
pass
return c
def count(n):
return sum(1 for _ in n)
def change_back(t):
res=Date.fromtimestamp(t)
return Date(res.year, res.month, res.day).timestamp()
def groupby(cb, itr):
x={}
for i in itr:
k=cb(i)
if not k in x:
if k not in x:
x[k]=[i]
else:
x[k].append(i)
pass
pass
for i, j in x.items():
yield (i, j)
pass
yield from x.items()

for i in groupby(lambda x: x, map(change_back, sys.history)):
history[int(i[0])]=len (i[1])
Expand All @@ -62,9 +53,9 @@ def sub(x):
class Year(list):
pass
class Week_Vector(list):
def __init__(s):
def __init__(self):
for _ in range(7):
s.append (" ")
self.append(" ")

def month_mem(start, end):
def _giveday ():
Expand All @@ -74,8 +65,8 @@ def _giveday ():
day=start
start+=datetime.timedelta(days=1,)
return day

return _giveday
pass
def calculate_each_and_every_month_s_max(y=None):
if not y:
y=Date.now().year
Expand All @@ -87,23 +78,20 @@ def _cal():
i+=datetime.timedelta(days=1,)
if i.month!=j.month:
yield j.month, 1, j.day
pass
if j.year!=y:
break

for month, start, end in _cal():
s=Date(y, month, start)
e=Date(y, month, end)
yield (s, month_mem(s, e))
pass
pass

def render_month(m):
def _render_month(m):
ms=[]
sarr=Week_Vector()
wd=0
yield list(map(lambda x: "%s"%(x,),
"Mon Tue Wed Thu Fri Sat Sun".split(" ")))
yield list(map(lambda x: f"{x}", "Mon Tue Wed Thu Fri Sat Sun".split(" ")))
while True:
for day in range(7):
d=m()
Expand All @@ -116,44 +104,33 @@ def _render_month(m):
sarr=Week_Vector()
wd=sta.tm_wday
sarr[sta.tm_wday]=d.yday

for i in _render_month(m):
if not i:
break
yield(" ".join(i))
pass
pass
def pack(ya):
res=[]
for month_i, month_blob in calculate_each_and_every_month_s_max(ya):
month=str(month_i)
res.append(list([month,
*render_month(month_blob)]))
pass
return res
return [
[str(month_i), *render_month(month_blob)]
for month_i, month_blob in calculate_each_and_every_month_s_max(ya)
]
def x_x(arr, j):
i=iter(arr)
try:
while True:
yield [next(i) for _ in range(j)]
pass
pass
except StopIteration:
pass
pass
def display_cal(y):
print(("%d"%(y,)).center((2+6+(7*3))*3))
for j in x_x(pack(y), 3):
for i in zip(*j):
print(" ".join(i))
print("\n")
pass
pass

try:
for i in range(2018, 2022):
display_cal(i)
pass
pass
except OverflowError:
pass
sys.exit (0)