效果
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+', "