main.py 3.2 KB

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