#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
msi=int(sys.argv[1])
dsi=int(sys.argv[2])
mei=int(sys.argv[3])
dei=int(sys.argv[4])
year="23"
mdays=[31,28,31, 30,31,30, 31,31,30, 31,30,31]
def gen_mon(msi,mei,dsi,dei):
print("\nnode [fontsize=20, shape=box, style=filled fillcolor=lightgreen];")
for m in range(msi, mei+1):
if m == msi:
ds=int(dsi)
else:
ds=1
if m==mei:
de=dei
if de > mdays[m-1]:
de = mdays[m-1]
else:
de=mdays[m-1]
print("\n{:>02}.{:>02}".format(year,m))
def gen_day(msi,mei,dsi,dei):
print("\nnode [fontsize=20, shape=box, style=filled fillcolor=lightgray];")
for m in range(msi, mei+1):
if m == msi:
ds=int(dsi)
else:
ds=1
if m==mei:
de=dei
if de > mdays[m-1]:
de = mdays[m-1]
else:
de=mdays[m-1]
print("\n{:>02}.{:>02}->".format(year,m))
for i in range(ds, de+1):
if i!=de:
print("{:>02}{:>02}->".format(m,i))
else:
print("{:>02}{:>02}".format(m,i))
def gen_rank_same(msi,mei,dsi,dei):
print("# rank")
print("\nnode [fontsize=20, shape=box, style=filled fillcolor=cyan];")
for m in range(msi, mei+1):
if m == msi:
ds=int(dsi)
else:
ds=1
if m==mei:
de=dei
if de > mdays[m-1]:
de = mdays[m-1]
else:
de=mdays[m-1]
print("\n#{:>02}.{:>02}".format(year,m))
septimelist=[3,6,9,12]
seasonlist=[3,6,9,12]
for i in range(ds, de+1):
if (m in seasonlist) and (i == 30):
print("{ rank=same; %02d%02d -> season_%02d%02d}" %(m,i, m,i))
elif (m in septimelist) and (i==22):
print("{ rank=same; %02d%02d -> jieqi_zhifen%02d%02d}" %(m,i, m,i))
else:
print("{ rank=same; %02d%02d }" %(m,i))
def gen_head():
print("digraph timeline {")
print('size = "7,8";')
def gen_tail():
print("}")
def _print_riji_event_label(lines):
# 遍历每一行,打印label
print("\n# event label")
for line in lines:
if len(line) < 10:
continue
# 2023-09-12 周一;Graphviz年时间线 def
ldate=line.split(' ')[0].split('-')
ldate=ldate[1]+ldate[2]
print("\n## " + ldate)
line=line[10:]
line = line.replace('\n','').replace(";", ";")
la=line.split(';')
for i in range(0, len(la)):
if len(la[i]) < 2:
continue
if i == 0: #第一个不标数字 是星期
seq=""
weekenddaylist=["周六", "周日"]
la[i]=la[i].replace(" ",'')
if la[i] in weekenddaylist:
weekendcolor="style=filled fillcolor=lightgreen"
else:
weekendcolor="style=filled fillcolor=coral"
else:
seq="{:>02d}:".format(i)
weekendcolor=""
print("d_env_"+ldate + "_" + str(i) + " [label=\"" + seq + la[i] + "\" " + weekendcolor +"];")
def _print_riji_event_ranksame(lines):
print("\n# ranks=same")
for line in lines:
if len(line) < 10:
continue
ldate=line.split(' ')[0].split('-')
ldate=ldate[1]+ldate[2]
line=line[9:]
line = line.replace('\n','').replace(";", ";")
la=line.split(';')
print("{ rank=same; " + ldate),
for i in range(0, len(la)):
if len(la[i]) < 2:
continue
print("-> d_env_" + ldate + "_" + str(i)),
print("}")
def gen_riji_event():
print("\nnode [fontsize=20, shape=box, style=filled fillcolor=lightblue];")
#读取文件riji.log到list中
file_path = "riji.log"
with open(file_path, "r") as file:
lines=file.readlines()
#linearray=lines.split('\n')
_print_riji_event_label(lines)
_print_riji_event_ranksame(lines)
def gen_total():
gen_head()
gen_mon(msi, mei, dsi, dei)
gen_day(msi, mei, dsi, dei)
gen_rank_same(msi, mei, dsi, dei)
gen_riji_event()
gen_tail()
def main():
gen_total()
main()
#python riji.py 9 1 9 31 > 1.gv