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

  • 相关阅读:
    jq02--基础函数
    jq01--概述
    js06--函数库jq与prototype
    eclipse启动时 failed to create the java virtual machine 解决办法
    将博客搬至CSDN
    eclipse.ini 修改默认编码为 UTF-8
    Elicpse使用技巧-打开选中文件文件夹或者包的当前目录
    eclipse换了高版本的maven插件后报错:org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.project
    python进行数据清理之pandas中的drop用法
    如何用Python实现常见机器学习算法-4
  • 原文地址:https://www.cnblogs.com/sunshine-long/p/12426000.html
Copyright © 2011-2022 走看看