12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #!/usr/bin/env python3
- import time
- import random
- from datetime import datetime
- THINGS = [
- {"name": "滚动更新系统", "good": "电脑似乎变快了不少", "bad": "更新后重启,系统再也起不来了……"},
- {"name": "报告 Bug", "good": "开发者很快修正了问题", "bad": "Bug 一直会被忽视"},
- {"name": "git bisect", "good": "三次便找到问题所在", "bad": "运气差到线性查找都比你要快"},
- {"name": "编译内核", "good": "编译一遍过", "bad": "三个小时编译出的内核无法正常使用"},
- {"name": "提交补丁", "good": "补丁会被很快合并", "bad": "开发者会觉得你的补丁不顺眼"},
- {"name": "酒后使用系统", "good": "效率倍增", "bad": "第二天发现电脑里似乎少了点东西的样子"},
- {"name": "维护服务器", "good": "拯救了接近爆满的 /,避免宕机事故", "bad": "你会不小心运行 rm -rf /var"},
- {"name": "在 IRC 上讨论问题", "good": "有机会认识同伙", "bad": "你会被喷子虐成狗"},
- {"name": "折腾单片机", "good": "新的神器诞生了", "bad": "你会焊坏电路板"},
- {"name": "阅读 SICP", "good": "你即将成为新世界的卡密", "bad": "你会大脑重残"},
- {"name": "教别人使用你的编辑器", "good": "成功布道", "bad": "你会被当成异端"},
- {"name": "合并 & 提交代码", "good": "工作成果顺利发布", "bad": "合并冲突多得甚至让你怀疑世界线发生了变更"},
- {"name": "研读man手册", "good": "意外发现有用的内容", "bad": "内容不知所云"},
- {"name": "和女神探讨技术问题", "good": "女神很喜欢你的”技术“", "bad": "女神对你不知所云"},
- ]
- THINGS.sort(key=lambda x: x["name"] + x["good"] + x["bad"])
- def set_random_seed():
- today = datetime.today()
- local_year, local_month, local_day = today.year, today.month, today.day
- local_midnight = datetime(local_year, local_month, local_day)
- unix_time = int(time.mktime(local_midnight.timetuple()))
- random.seed(unix_time)
- def random_choice():
- good = []
- bad = []
- for thing in THINGS:
- magic = random.randint(0, 1)
- if magic == 0:
- is_good = lambda x: x % 2
- else:
- is_good = lambda x: not (x % 2)
- rand = random.randint(0, 1024)
- if is_good(rand):
- good.append({"name": thing["name"], "reason": thing["good"]})
- else:
- bad.append({"name": thing["name"], "reason": thing["bad"]})
- return good, bad
- if __name__ == "__main__":
- set_random_seed()
- good, bad = random_choice()
- print("Linuxer 老黄历\n")
- print("今天是 %s" % time.strftime("%Y 年 %m 月 %d 日"))
- print("\n\n宜:")
- for i in good:
- print("* %s - %s" % (i["name"], i["reason"]))
- print("\n\n不宜:")
- for i in bad:
- print("* %s - %s" % (i["name"], i["reason"]))
|