Skip to content

Commit 979e3f7

Browse files
committed
v1.1 release
1 parent 5d73127 commit 979e3f7

File tree

10 files changed

+1900
-1500
lines changed

10 files changed

+1900
-1500
lines changed

README.md

Lines changed: 1767 additions & 1495 deletions
Large diffs are not rendered by default.

data/test_excel.xlsx

8.56 KB
Binary file not shown.

md/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
7. [文件批量压缩](文件批量压缩.md)
7171
8. [文件读写操作](文件读写操作.md)
7272
9. [字符串32位加密](字符串32位加密.md)
73+
10. [寻找前10大的文件](找出前10大的文件.md)
7374

7475

7576
#### 七、字符串、正则和爬虫
@@ -83,6 +84,7 @@
8384
8. [字符串32位加密](字符串32位加密.md)
8485
9. [反转字符串](反转字符串1.md)
8586
10. [分词并保存结果](分词并保存结果.md)
87+
11. [求字符串的字节长度](求字符串的字节长度.md)
8688

8789
#### 八、绘图
8890

md/使用calendar.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
```python
2+
from datetime import date, datetime
3+
import calendar
4+
5+
6+
def print_mydate(mydate):
7+
print(f'输入的日期:{mydate}\n')
8+
9+
year_calendar_str = calendar.calendar(mydate.year)
10+
print(f"{mydate.year}年的日历图:{year_calendar_str}\n")
11+
12+
is_leap = calendar.isleap(mydate.year)
13+
print_leap_str = "%s年是闰年" if is_leap else "%s年不是闰年\n"
14+
print(print_leap_str % mydate.year)
15+
16+
month_calendar_str = calendar.month(mydate.year, mydate.month)
17+
print(f"{mydate.year}年-{mydate.month}月的日历图:{month_calendar_str}\n")
18+
19+
weekday, days = calendar.monthrange(mydate.year, mydate.month)
20+
print(f'{mydate.year}年-{mydate.month}月的第一天是那一周的第{weekday}\n')
21+
print(f'{mydate.year}年-{mydate.month}月共有{days}\n')
22+
23+
month_first_day = date(mydate.year, mydate.month, 1)
24+
print(f"当月第一天:{month_first_day}\n")
25+
26+
month_last_day = date(mydate.year, mydate.month, days)
27+
print(f"当月最后一天:{month_last_day}\n")
28+
29+
30+
print_mydate(date.today())
31+
32+
33+
```

md/求字符串的字节长度.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ def str_byte_len(mystr):
99

1010
str_byte_len('i love python') # 13(个字节)
1111
str_byte_len('字符') # 6(个字节)
12+
```

src/convert.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ def convert(input_file):
1313
print(f'begin to convert {filename}...')
1414
process = api.convert({
1515
'inputformat': 'md',
16-
'outputformat': 'rst',
16+
'outputformat': 'pdf',
1717
'input': 'upload',
18-
'file': open('./md2/{}'.format(input_file), 'rb')
18+
'file': open('./{}'.format(input_file), 'rb')
1919
})
2020
process.wait() # wait until conversion finished
2121
# download output file
2222

2323
process.download(
24-
"./rst/tmp/{}.rst".format(filename))
24+
"./tmp/{}.pdf".format(filename))
2525
print(f"convert {filename} success")
2626

2727

28-
for input_file in os.listdir('./md2'):
28+
for input_file in os.listdir('.'):
2929
convert(input_file)
30-
time.sleep(1)
30+
# time.sleep(1)

src/datetime2_cal.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from datetime import date, datetime
2+
from time import localtime, strftime, strptime
3+
4+
5+
today_date = date.today()
6+
print(today_date) # 2019-12-22
7+
8+
today_time = datetime.today()
9+
print(today_time) # 2019-12-22 18:02:33.398894
10+
11+
local_time = localtime()
12+
print(strftime("%Y-%m-%d %H:%M:%S", local_time)) # 转化为定制的格式
13+
14+
# parse str time to struct time
15+
struct_time = strptime('2019-12-22 10:10:08', "%Y-%m-%d %H:%M:%S")
16+
print(strftime("%m-%d-%Y %H:%M:%S", struct_time)) # 转化为定制的格式

src/datetime_cal.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from datetime import date, datetime
2+
import calendar
3+
4+
5+
def print_mydate(mydate):
6+
print(f'输入的日期:{mydate}\n')
7+
8+
year_calendar_str = calendar.calendar(mydate.year)
9+
print(f"{mydate.year}年的日历图:{year_calendar_str}\n")
10+
11+
is_leap = calendar.isleap(mydate.year)
12+
print_leap_str = "%s年是闰年" if is_leap else "%s年不是闰年\n"
13+
print(print_leap_str % mydate.year)
14+
15+
month_calendar_str = calendar.month(mydate.year, mydate.month)
16+
print(f"{mydate.year}年-{mydate.month}月的日历图:{month_calendar_str}\n")
17+
18+
weekday, days = calendar.monthrange(mydate.year, mydate.month)
19+
print(f'{mydate.year}年-{mydate.month}月的第一天是那一周的第{weekday}\n')
20+
print(f'{mydate.year}年-{mydate.month}月共有{days}\n')
21+
22+
month_first_day = date(mydate.year, mydate.month, 1)
23+
print(f"当月第一天:{month_first_day}\n")
24+
25+
month_last_day = date(mydate.year, mydate.month, days)
26+
print(f"当月最后一天:{month_last_day}\n")
27+
28+
29+
print_mydate(date.today())

src/walk_dir.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# 获取目录下文件的修改时间
2+
import os
3+
from datetime import datetime
4+
print(f"当前时间:{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
5+
6+
7+
def get_modify_datetime(indir):
8+
for root, _, files in os.walk(indir): # 循环D:\works目录和子目录
9+
for file in files:
10+
absfile = os.path.join(root, file)
11+
modtime = datetime.fromtimestamp(os.path.getmtime(absfile))
12+
now = datetime.now()
13+
difftime = now-modtime
14+
if difftime.days < 20: # 条件筛选超过指定时间的文件
15+
print(f"""{absfile}
16+
修改时间[{modtime.strftime('%Y-%m-%d %H:%M:%S')}]
17+
距今[{difftime.days:3d}{difftime.seconds//3600:2d}{difftime.seconds%3600//60:2d}]"""
18+
) # 打印相关信息
19+
20+
21+
get_modify_datetime('./data')

src/xls_to_xlsx.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
3+
4+
def xls_to_xlsx(work_dir):
5+
"""
6+
传递当前目录,原来后缀名,新的后缀名后,批量重命名后缀
7+
"""
8+
old_ext, new_ext = '.xls', '.xlsx'
9+
for filename in os.listdir(work_dir):
10+
# 获取得到文件后缀
11+
split_file = os.path.splitext(filename)
12+
file_ext = split_file[1]
13+
# 定位后缀名为old_ext 的文件
14+
if old_ext == file_ext:
15+
# 修改后文件的完整名称
16+
newfile = split_file[0] + new_ext
17+
# 实现重命名操作
18+
os.rename(
19+
os.path.join(work_dir, filename),
20+
os.path.join(work_dir, newfile)
21+
)
22+
print("完成重命名")
23+
print(os.listdir(work_dir))
24+
25+
26+
xls_to_xlsx('./data')

0 commit comments

Comments
 (0)