zoukankan      html  css  js  c++  java
  • 使用python给自己的mac添加日历

    效果

    1、下载GeekTool

    下载地址:https://www.tynsoe.org/v2/geektool/

    2、打开小工具,将shell图标拖拽至屏幕。

    3、点击屏幕窗口,在Properties窗口的Command输入框中输入以下代码即可。

     代码如下:

     1 #!/usr/bin/env python
     2 import calendar
     3 import datetime
     4 import re
     5 
     6 
     7 def get_year_month(d):
     8     """
     9     :param datetime_obj: a datetime object ; for example : datetime.datetime.now()
    10     :return: a datetime object
    11     """
    12     return d.year, d.month
    13 
    14 
    15 def get_pre_datetime(datetime_obj):
    16     """
    17     :param datetime_obj: a datetime object ; for example : datetime.datetime.now()
    18     :return: a datetime object
    19     """
    20     days_count = datetime.timedelta(days=datetime_obj.day)
    21     pre_month_last_day_datetime_obj = datetime_obj - days_count
    22     return pre_month_last_day_datetime_obj
    23 
    24 
    25 def get_next_datetime(datetime_obj):
    26     """
    27     :param datetime_obj: a datetime object ; for example : datetime.datetime.now()
    28     :return: a datetime object
    29     """
    30     days_count = calendar.monthrange(datetime_obj.year, datetime_obj.month)[1]
    31     next_month_datetime = datetime_obj + datetime.timedelta(days=days_count+1) - datetime.timedelta(datetime.datetime.now().day)
    32     return next_month_datetime
    33 
    34 
    35 def day_format(datetime_obj, cal_str):
    36     """
    37     :param datetime_obj: a datetime object ; for example : datetime.datetime.now()
    38     :param d: a datetime object ; for example : datetime.datetime.now()
    39     :return: a datetime object
    40     """
    41     day = datetime_obj.day
    42     reg_num = "D{}D".format(day)
    43     reg = re.search(reg_num, cal_str).group()
    44     ret = re.sub('d+', "33[31m{}33[0m".format(day), reg)
    45     return re.sub(reg, ret, cal_str)
    46 
    47 if __name__ == '__main__':
    48     currnet_time = datetime.datetime.now()
    49 
    50     pre_year_month = get_year_month(get_pre_datetime(currnet_time))
    51     currnet_year_month = get_year_month(currnet_time)
    52     next_year_month = get_year_month(get_next_datetime(currnet_time))
    53 
    54 
    55 #    with open('/var/tmp/cal.log', 'w') as f:
    56 #        f.write(calendar.month(*pre_year_month, w=3, l=1))
    57 #        f.write(day_format(currnet_time, calendar.month(*currnet_year_month, w=3, l=1)))
    58 #        f.write(calendar.month(*next_year_month, w=3, l=1))
    59 
    60     print(calendar.month(*pre_year_month, w=3, l=1))
    61     print(day_format(currnet_time, calendar.month(*currnet_year_month, w=3, l=2)))
    62     print(calendar.month(*next_year_month, w=3, l=1))
    View Code

    4、也可以在command输入框中执行命令,例如cat file。即可在桌面显示file中的内容,可设置字体,背景颜色。

    参考来自https://www.cnblogs.com/resn/p/6665390.html

  • 相关阅读:
    SpringMVC金课-课程大纲
    Type Cannot change version of project facet Dynamic Web Module to 3.0.
    使用maven 创建web项目 + 搭建SSM框架
    多文件上传
    asp.net 连接access数据库方法
    分享代码
    DIV+CSS解决IE6,IE7,IE8,FF兼容问题(转至http://www.douban.com/note/163291324/)
    asp.net发布网站(转)
    Img垂直居中
    http://www.apkbus.com/android-6231-1.html
  • 原文地址:https://www.cnblogs.com/sunshine-long/p/12426000.html
Copyright © 2011-2022 走看看