使用python语言实现获取当前时间,按照电子表样式打印到控制台

news/2024/11/16 21:56:32/文章来源:https://www.cnblogs.com/mxh-java/p/18549876

使用python语言实现获取当前时间,按照电子表样式打印到控制台

clock.py

  1 # 数字1
  2 from datetime import datetime
  3 
  4 # 数字0
  5 zero_line_01 = '  ---  '
  6 zero_line_02 = ' |   | '
  7 zero_line_03 = ' |   | '
  8 zero_line_04 = ' |   | '
  9 zero_line_05 = '  ___  '
 10 
 11 # 数字1
 12 one_line_01 = '   |   '
 13 one_line_02 = '   |   '
 14 one_line_03 = '   |   '
 15 one_line_04 = '   |   '
 16 one_line_05 = '   |   '
 17 
 18 # 数字2
 19 two_line_01 = '  ---  '
 20 two_line_02 = '     | '
 21 two_line_03 = '  ---  '
 22 two_line_04 = ' |     '
 23 two_line_05 = '  ---  '
 24 
 25 # 数字3
 26 three_line_01 = '  ---  '
 27 three_line_02 = '     | '
 28 three_line_03 = '  ---  '
 29 three_line_04 = '     | '
 30 three_line_05 = '  ---  '
 31 
 32 # 数字4
 33 four_line_01 = ' |   | '
 34 four_line_02 = ' |   | '
 35 four_line_03 = '  ---  '
 36 four_line_04 = '     | '
 37 four_line_05 = '     | '
 38 
 39 # 数字5
 40 five_line_01 = '  ---  '
 41 five_line_02 = ' |     '
 42 five_line_03 = '  ---  '
 43 five_line_04 = '     | '
 44 five_line_05 = '  ---  '
 45 
 46 # 数字6
 47 six_line_01 = '  ---  '
 48 six_line_02 = ' |     '
 49 six_line_03 = '  ---  '
 50 six_line_04 = ' |   | '
 51 six_line_05 = '  ---  '
 52 
 53 # 数字7
 54 seven_line_01 = '  ---  '
 55 seven_line_02 = '     | '
 56 seven_line_03 = '     | '
 57 seven_line_04 = '     | '
 58 seven_line_05 = '     | '
 59 
 60 # 数字8
 61 eight_line_01 = '  ---  '
 62 eight_line_02 = ' |   | '
 63 eight_line_03 = '  ---  '
 64 eight_line_04 = ' |   | '
 65 eight_line_05 = '  ---  '
 66 
 67 # 数字9
 68 nine_line_01 = '  ---  '
 69 nine_line_02 = ' |   | '
 70 nine_line_03 = '  ---  '
 71 nine_line_04 = '     | '
 72 nine_line_05 = '  ---  '
 73 
 74 # 分隔符
 75 separator_line_01 = '       '
 76 separator_line_02 = '   .   '
 77 separator_line_03 = '       '
 78 separator_line_04 = '   .   '
 79 separator_line_05 = '       '
 80 
 81 # 分隔符
 82 empty_line_01 = '       '
 83 empty_line_02 = '       '
 84 empty_line_03 = '       '
 85 empty_line_04 = '       '
 86 empty_line_05 = '       '
 87 
 88 # 获取当前时间字符串
 89 def get_current_time_str():
 90     return datetime.now().strftime('%Y-%m-%d %H:%M:%S')
 91 
 92 # 根据字符串返返回电子表格式内容
 93 def generate_content_by_datetime_str(datetime_str):
 94     result = {
 95         'result_line_01' : '',
 96         'result_line_02' : '',
 97         'result_line_03' : '',
 98         'result_line_04' : '',
 99         'result_line_05' : ''
100     }
101     char_list = list(datetime_str)
102     for char in char_list:
103         clock_result = generate_clock(char)
104         result['result_line_01'] += clock_result['clock_result_01']
105         result['result_line_02'] += clock_result['clock_result_02']
106         result['result_line_03'] += clock_result['clock_result_03']
107         result['result_line_04'] += clock_result['clock_result_04']
108         result['result_line_05'] += clock_result['clock_result_05']
109     return result
110 
111 # 根据当前时间返回电子表格式内容
112 def generate_content():
113     datetime_str = get_current_time_str()
114     result = {
115         'result_line_01' : '',
116         'result_line_02' : '',
117         'result_line_03' : '',
118         'result_line_04' : '',
119         'result_line_05' : ''
120     }
121     char_list = list(datetime_str)
122     for char in char_list:
123         clock_result = generate_clock(char)
124         result['result_line_01'] += clock_result['clock_result_01']
125         result['result_line_02'] += clock_result['clock_result_02']
126         result['result_line_03'] += clock_result['clock_result_03']
127         result['result_line_04'] += clock_result['clock_result_04']
128         result['result_line_05'] += clock_result['clock_result_05']
129     return result
130 
131 def generate_clock(str):
132     clock_result = {'clock_result_01' : '',
133                     'clock_result_02' : '',
134                     'clock_result_03' : '',
135                     'clock_result_04' : '',
136                     'clock_result_05' : ''}
137     if('0' == str):
138         clock_result['clock_result_01'] = zero_line_01
139         clock_result['clock_result_02'] = zero_line_02
140         clock_result['clock_result_03'] = zero_line_03
141         clock_result['clock_result_04'] = zero_line_04
142         clock_result['clock_result_05'] = zero_line_05
143     if('1' == str):
144         clock_result['clock_result_01'] = one_line_01
145         clock_result['clock_result_02'] = one_line_02
146         clock_result['clock_result_03'] = one_line_03
147         clock_result['clock_result_04'] = one_line_04
148         clock_result['clock_result_05'] = one_line_05
149     if('2' == str):
150         clock_result['clock_result_01'] = two_line_01
151         clock_result['clock_result_02'] = two_line_02
152         clock_result['clock_result_03'] = two_line_03
153         clock_result['clock_result_04'] = two_line_04
154         clock_result['clock_result_05'] = two_line_05
155     if('3' == str):
156         clock_result['clock_result_01'] = three_line_01
157         clock_result['clock_result_02'] = three_line_02
158         clock_result['clock_result_03'] = three_line_03
159         clock_result['clock_result_04'] = three_line_04
160         clock_result['clock_result_05'] = three_line_05
161     if('4' == str):
162         clock_result['clock_result_01'] = four_line_01
163         clock_result['clock_result_02'] = four_line_02
164         clock_result['clock_result_03'] = four_line_03
165         clock_result['clock_result_04'] = four_line_04
166         clock_result['clock_result_05'] = four_line_05
167     if('5' == str):
168         clock_result['clock_result_01'] = five_line_01
169         clock_result['clock_result_02'] = five_line_02
170         clock_result['clock_result_03'] = five_line_03
171         clock_result['clock_result_04'] = five_line_04
172         clock_result['clock_result_05'] = five_line_05
173     if('6' == str):
174         clock_result['clock_result_01'] = six_line_01
175         clock_result['clock_result_02'] = six_line_02
176         clock_result['clock_result_03'] = six_line_03
177         clock_result['clock_result_04'] = six_line_04
178         clock_result['clock_result_05'] = six_line_05
179     if('7' == str):
180         clock_result['clock_result_01'] = seven_line_01
181         clock_result['clock_result_02'] = seven_line_02
182         clock_result['clock_result_03'] = seven_line_03
183         clock_result['clock_result_04'] = seven_line_04
184         clock_result['clock_result_05'] = seven_line_05
185     if('8' == str):
186         clock_result['clock_result_01'] = eight_line_01
187         clock_result['clock_result_02'] = eight_line_02
188         clock_result['clock_result_03'] = eight_line_03
189         clock_result['clock_result_04'] = eight_line_04
190         clock_result['clock_result_05'] = eight_line_05
191     if('9' == str):
192         clock_result['clock_result_01'] = nine_line_01
193         clock_result['clock_result_02'] = nine_line_02
194         clock_result['clock_result_03'] = nine_line_03
195         clock_result['clock_result_04'] = nine_line_04
196         clock_result['clock_result_05'] = nine_line_05
197     if (':' == str):
198         clock_result['clock_result_01'] = separator_line_01
199         clock_result['clock_result_02'] = separator_line_02
200         clock_result['clock_result_03'] = separator_line_03
201         clock_result['clock_result_04'] = separator_line_04
202         clock_result['clock_result_05'] = separator_line_05
203     if (' ' == str):
204         clock_result['clock_result_01'] = empty_line_01
205         clock_result['clock_result_02'] = empty_line_02
206         clock_result['clock_result_03'] = empty_line_03
207         clock_result['clock_result_04'] = empty_line_04
208         clock_result['clock_result_05'] = empty_line_05
209     return clock_result

test.py

 1 import clock
 2 
 3 # 测试时钟方法
 4 # clock_result = clock.generate_content_by_datetime_str('1997-05-29 00:00:00')
 5 # print(clock_result['result_line_01'])
 6 # print(clock_result['result_line_02'])
 7 # print(clock_result['result_line_03'])
 8 # print(clock_result['result_line_04'])
 9 # print(clock_result['result_line_05'])
10 
11 while True:
12     clock_result = clock.generate_content()
13     print(clock_result['result_line_01'])
14     print(clock_result['result_line_02'])
15     print(clock_result['result_line_03'])
16     print(clock_result['result_line_04'])
17     print(clock_result['result_line_05'])
18     print("")
19     time.sleep(1)

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/834809.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

gofiber: 模板:判断if条件

一,代码: 1,controller func (dc *ArticleController) GetArticle(c *fiber.Ctx) error {// 处理获取文章的逻辑article := new(Article)article.Id = 1article.Title = "三国演义金圣叹批本"article.Author = "罗贯中"user:=c.Query("user")m…

starrycan的pwn随笔——ELF文件和延迟绑定机制

一.ELF文件结构 0x01什么是ELF文件 1.linux环境中,二进制可持性文件的类型是ELF(Executable and LinkableFormat)文件。类似windows下的exe 2.elf文件的格式比较简单,我们需要了解的就是elf文件中的各个节、段等概念 3.程序elf的基本信息存在于elf的头部信息中,这些信息包括…

达梦数据库DM管理工具如何浏览数据,用条件筛选数据

前言 大家好,我是小徐啊。达梦数据库是我们一款常用的国产数据库,我之前一直在使用它。用起来和mysql和postgresql比起来,还是差不多的。而且它自带了数据库连接工具DM管理工具,使我们很方便的连接它。 今天,小徐就来介绍下如何用DM管理工具浏览数据,并且用条件去筛选数据…

标注图片怎么导出VOC格式和COCO格式

图片怎么标注参考 https://www.cnblogs.com/minseo/p/18549804下载 从github下载代码,或压缩包# git clone https://github.com/LabelMe/labelme转换 示例文件在以下路径# labelme-main\examples\instance_segmentation目录以及各个目录的用途如下打过标签的图片和json文件放以…

vscode Markdown文件如何使代码超出屏幕可视区域不换行

在编写Markdown文件的表格时,单元格内过长的内容会使得行超出可视区域,Markdown处理方式为单行用多行表示,如下图所示:这样会破坏表格的可读性,利用快捷键Alt+Z,可变为如下形式:使得表格每列对齐以增加可读性

20222325 2024-2025-1 《网络与系统攻防技术》实验六实验报告

1.实验内容 本实践目标是掌握metasploit的用法。 指导书参考Rapid7官网的指导教程。 https://docs.rapid7.com/metasploit/metasploitable-2-exploitability-guide/ 下载官方靶机Metasploitable2,完成下面实验内容。 (1)前期渗透 ①主机发现(可用Aux中的arp_sweep,search一…

[Linux]gdb基本使用

gdb基本使用 前提 gcc/g++编译出的程序默认是realease版本,要使用gdb调试,首先要在编译的时候加上-g选项。使用readelf -S [程序名]查看可执行文件的节区信息。使用gdb [程序名]:开始调试。q:退出调试。list/l [行号]:从给定的位置显示程序的源代码,每次十行。break/b [行…

美团商家联系电话采集软件团购外卖信息批量提取器

定义目标:明确需要采集的数据,如商家名称、地址、评分、销量等。 分析页面结构:通过浏览器的开发者工具,分析美团团购或外卖页面的HTML结构,找出包含所需数据的标签。 模拟用户请求:使用requests库模拟用户访问美团页面,可能需要处理登录、反爬虫机制(如Cookies、Heade…

# 团队作业4——项目冲刺-6

团队作业4——项目冲刺-6信息项 内容课程名称 广工计院计科34班软工作业要求位置 作业要求作业目标 在七天敏捷冲刺中,完成工大严选开发,记录每日进展和问题,更新燃尽图、签入代码,并发布集合日志总结成果GitHub链接 GitHub一、团队简介队名:小飞棍队团队成员:姓名 学号罗…

20222427 2024-2025-1 《网络与系统攻防技术》实验五实验报告

1.实验内容 1.1 本周内容总结使用了Metasploit框架,其是一个功能强大的渗透测试框架。在使用的过程当中,Metasploit 提供了种类繁多的攻击模块,涵盖了远程代码执行、服务拒绝、提权等多种攻击方式,支持对多种操作系统和应用程序进行测试。除了漏洞利用,它还具备强大的后渗…

20222306 2024-2025-1《网络与系统攻防技术》实验六实验报告

1.实验内容 1.1内容回顾总结 这周都重点在于Metasploit工具的使用,我深入了解了对其功能和使用流程。Metasploit 是一个功能强大的渗透测试框架,广泛应用于网络安全领域。它为安全专家、渗透测试人员和红队提供了一个全面的工具集,支持漏洞利用、攻击模拟和安全评估。Metaspl…

关于HDFS路径文件夹名称的问题

问题发现 ​ 最开始的需求:修改/origin_data/gmall/db目录下所有以inc结尾的文件夹里的文件夹(名称为2024-11-15)修改为2020-6-14 问gpt写了个脚本: #!/bin/bash# 遍历 /origin_data/gmall/db 下所有以 "inc" 结尾的文件夹 for dir in $(hdfs dfs -ls /origin_da…