Skip to content

Commit 4715a97

Browse files
committed
2 parents 9fab572 + a00db2e commit 4715a97

File tree

18 files changed

+914
-1
lines changed

18 files changed

+914
-1
lines changed

.DS_Store

-2 KB
Binary file not shown.

chaoxi/521_love/love.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import matplotlib.pyplot as plt
2+
import seaborn
3+
import numpy
4+
5+
# 定义方法
6+
def draw_love():
7+
#拼凑字母
8+
l = numpy.arange(0, 4, 0.01)
9+
L = 1.0 / l
10+
theta = numpy.arange(-4, 4, 0.01)
11+
o = 3.0 * numpy.cos(theta)
12+
O = 3.0 * numpy.sin(theta)
13+
v = numpy.arange(-4, 4, 0.01)
14+
V = numpy.abs(-2.0 * v)
15+
e = numpy.arange(-3, 3, 0.01)
16+
E = -1.0 * numpy.abs(numpy.sin(e))
17+
y = numpy.arange(-10, 10, 0.01)
18+
Y = numpy.log2(numpy.abs(y))
19+
u = numpy.arange(-4, 4, 0.01)
20+
U = 2.0 * u ** 2
21+
points = []
22+
23+
for heartY in numpy.linspace(-100, 100, 500):
24+
for heartX in numpy.linspace(-100, 100, 500):
25+
if ((heartX * 0.03) ** 2 + (heartY * 0.03) ** 2 - 1) ** 3 - (heartX * 0.03) ** 2 * (
26+
heartY * 0.03) ** 3 <= 0:
27+
points.append({"x": heartX, "y": heartY})
28+
# 设置直角坐标系
29+
heart_x = list(map(lambda point: point["x"], points))
30+
heart_y = list(map(lambda point: point["y"], points))
31+
32+
# 添加网格
33+
fig = plt.figure(figsize=(13, 7))
34+
ax_L = fig.add_subplot(2, 4, 1)
35+
ax_O = fig.add_subplot(2, 4, 2)
36+
ax_V = fig.add_subplot(2, 4, 3)
37+
ax_E = fig.add_subplot(2, 4, 4)
38+
ax_Y = fig.add_subplot(2, 4, 5)
39+
ax_O_2 = fig.add_subplot(2, 4, 6)
40+
ax_U = fig.add_subplot(2, 4, 7)
41+
ax_heart = fig.add_subplot(2, 4, 8)
42+
43+
# 设置坐标
44+
ax_L.plot(l, L)
45+
ax_O.plot(o, O)
46+
ax_V.plot(v, V)
47+
ax_E.plot(E, e)
48+
ax_Y.plot(y, Y)
49+
ax_Y.axis([-10.0, 10.0, -10.0, 5.0])
50+
ax_O_2.plot(o, O)
51+
52+
ax_U.plot(u, U)
53+
54+
ax_heart.scatter(heart_x, heart_y, s=10, alpha=0.5)
55+
# 设置颜色
56+
plt.plot(color='red')
57+
# 展示结果
58+
plt.show()
59+
60+
# 主函数
61+
if __name__ == '__main__':
62+
seaborn.set_style('dark')
63+
draw_love()

chaoxi/521_love/love1.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import turtle
2+
import time
3+
4+
def hart_arc():
5+
for i in range(200):
6+
turtle.right(1)
7+
turtle.forward(2)
8+
9+
10+
def move_pen_position(x, y):
11+
turtle.hideturtle() # 隐藏画笔(先)
12+
turtle.up() # 提笔
13+
turtle.goto(x, y) # 移动画笔到指定起始坐标(窗口中心为0,0)
14+
turtle.down() # 下笔
15+
turtle.showturtle() # 显示画笔
16+
17+
18+
love = input("请输入表白话语:")
19+
signature = input("请签署你的名字:")
20+
date=input("请写上日期:")
21+
22+
if love == '':
23+
love = 'I Love You'
24+
25+
turtle.setup(width=800, height=500) # 窗口(画布)大小
26+
turtle.color('red', 'pink') # 画笔颜色
27+
turtle.pensize(3) # 画笔粗细
28+
turtle.speed(1) # 描绘速度
29+
# 初始化画笔起始坐标
30+
move_pen_position(x=0, y=-180) # 移动画笔位置
31+
turtle.left(140) # 向左旋转140度
32+
33+
turtle.begin_fill() # 标记背景填充位置
34+
35+
# 画图和展示
36+
turtle.forward(224) # 向前移动画笔,长度为224
37+
# 画爱心圆弧
38+
hart_arc() # 左侧圆弧
39+
turtle.left(120) # 调整画笔角度
40+
hart_arc() # 右侧圆弧
41+
# 画心形直线( 右下方 )
42+
turtle.forward(224)
43+
44+
turtle.end_fill() # 标记背景填充结束位置
45+
46+
move_pen_position(x=70, y=160) # 移动画笔位置
47+
turtle.left(185) # 向左旋转180度
48+
turtle.circle(-110,185) # 右侧圆弧
49+
# 画心形直线( 右下方 )
50+
#turtle.left(20) # 向左旋转180度
51+
turtle.forward(50)
52+
move_pen_position(x=-180, y=-180) # 移动画笔位置
53+
turtle.left(180) # 向左旋转140度
54+
55+
# 画心形直线( 左下方 )
56+
turtle.forward(600) # 向前移动画笔,长度为224
57+
58+
# 在心形中写上表白话语
59+
move_pen_position(0,50) # 表白语位置
60+
turtle.hideturtle() # 隐藏画笔
61+
turtle.color('#CD5C5C', 'pink') # 字体颜色
62+
# font:设定字体、尺寸(电脑下存在的字体都可设置) align:中心对齐
63+
turtle.write(love, font=('Arial', 20, 'bold'), align="center")
64+
65+
# 签写署名和日期
66+
if (signature != '') & (date != ''):
67+
turtle.color('red', 'pink')
68+
time.sleep(2)
69+
move_pen_position(220, -180)
70+
turtle.hideturtle() # 隐藏画笔
71+
turtle.write(signature, font=('Arial', 20), align="center")
72+
move_pen_position(220, -220)
73+
turtle.hideturtle() # 隐藏画笔
74+
turtle.write(date, font=('Arial', 20), align="center")
75+
76+
#点击窗口关闭程序
77+
window = turtle.Screen()
78+
window.exitonclick()
79+

doudou/2021-06-30-pyautogui/app.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# coding=utf-8
2+
3+
import time
4+
import pyautogui
5+
6+
7+
# 将图片拖入轨道
8+
def drag_img_to_track():
9+
# 选中图片
10+
pyautogui.moveTo(170, 270)
11+
pyautogui.doubleClick()
12+
# 拖拽图片至轨道
13+
pyautogui.dragTo(120, 600, 1, button='left')
14+
15+
16+
# 调整视频时长
17+
def drag_img_to_3_min():
18+
# 选中轨道中的第一张图
19+
pyautogui.moveTo(125, 600)
20+
pyautogui.click()
21+
# 拖拽至第三分钟
22+
pyautogui.moveTo(135, 600)
23+
pyautogui.dragTo(700, 600, 1, button='left')
24+
25+
26+
# 删除旧的素材
27+
def delete_top_img():
28+
# 删除轨道中的第二张图片
29+
pyautogui.moveTo(300, 160)
30+
pyautogui.doubleClick()
31+
pyautogui.press("backspace")
32+
33+
# enter yes
34+
pyautogui.moveTo(650, 470)
35+
time.sleep(0.5)
36+
pyautogui.click()
37+
38+
39+
# 导出
40+
def export(name):
41+
pyautogui.moveTo(126, 600)
42+
pyautogui.click()
43+
44+
pyautogui.hotkey('command', 'e')
45+
pyautogui.write(name)
46+
time.sleep(1)
47+
pyautogui.moveTo(800, 393)
48+
pyautogui.click()
49+
time.sleep(20)
50+
pyautogui.click()
51+
52+
53+
index = 0
54+
count = 2
55+
while index < count:
56+
drag_img_to_track()
57+
drag_img_to_3_min()
58+
delete_top_img()
59+
export(str(index))
60+
time.sleep(2)
61+
index += 1
62+
print("end..." + str(index))

doudou/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Python技术 公众号文章代码库
2525
+ [fake-data](https://github.com/JustDoPython/python-examples/tree/master/doudou/2021-01-10-fake-data):假数据
2626
+ [mitmproxy](https://github.com/JustDoPython/python-examples/tree/master/doudou/2021-02-08-mitmproxy):中间人攻击
2727
+ [poetry](https://github.com/JustDoPython/python-examples/tree/master/doudou/2021-03-09-programmer-romance):程序员的浪漫
28-
28+
+ [pyautogui](https://github.com/JustDoPython/python-examples/tree/master/doudou/2021-06-30-pyautogui):自动制作视频
2929
---
3030

3131
从小白到工程师的学习之路。

moumoubaimifan/bilibili/bilibili.py

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
from time import sleep
2+
import requests, urllib.request, re
3+
import os, sys,json
4+
5+
headers = {
6+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
7+
'Cookie': 'SESSDATA=182cd036%2C1636985829%2C3b393%2A51',
8+
'Host': 'api.bilibili.com'
9+
}
10+
11+
12+
Str = 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF' # 准备的一串指定字符串
13+
Dict = {}
14+
15+
# 将字符串的每一个字符放入字典一一对应 , 如 f对应0 Z对应1 一次类推。
16+
for i in range(58):
17+
Dict[Str[i]] = i
18+
19+
s = [11, 10, 3, 8, 4, 6, 2, 9, 5, 7] # 必要的解密列表
20+
xor = 177451812
21+
add = 100618342136696320 # 这串数字最后要被减去或加上
22+
23+
def algorithm_enc(av):
24+
ret = av
25+
av = int(av)
26+
av = (av ^ xor) + add
27+
# 将BV号的格式(BV + 10个字符) 转化成列表方便后面的操作
28+
r = list('BV ')
29+
for i in range(10):
30+
r[s[i]] = Str[av // 58 ** i % 58]
31+
return ''.join(r)
32+
33+
def find_bid(p):
34+
bids = []
35+
r = requests.get(
36+
'https://api.bilibili.com/x/web-interface/newlist?&rid=20&type=0&pn={}&ps=50&jsonp=jsonp'.format(p))
37+
38+
data = json.loads(r.text)
39+
archives = data['data']['archives']
40+
41+
for item in archives:
42+
aid = item['aid']
43+
# r = requests.get('http://api.bilibili.com/x/web-interface/archive/stat?aid=' + str(aid), headers=headers)
44+
# bid = json.loads(r.text)['data']['bvid']
45+
bid = algorithm_enc(aid)
46+
bids.append(bid)
47+
48+
return bids
49+
50+
51+
def get_cid(bid):
52+
url = 'https://api.bilibili.com/x/player/pagelist?bvid=' + bid
53+
54+
55+
html = requests.get(url, headers=headers).json()
56+
57+
infos = []
58+
59+
data = html['data']
60+
cid_list = data
61+
for item in cid_list:
62+
cid = item['cid']
63+
title = item['part']
64+
infos.append({'bid': bid, 'cid': cid, 'title': title})
65+
return infos
66+
67+
68+
# 访问API地址
69+
def get_video_list(aid, cid, quality):
70+
url_api = 'https://api.bilibili.com/x/player/playurl?cid={}&bvid={}&qn={}'.format(cid, aid, quality)
71+
headers = {
72+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
73+
'Cookie': 'SESSDATA=182cd036%2C1636985829%2C3b393%2A51',
74+
'Host': 'api.bilibili.com'
75+
}
76+
html = requests.get(url_api, headers=headers).json()
77+
video_list = []
78+
79+
for i in html['data']['durl']:
80+
video_list.append(i['url'])
81+
return video_list
82+
83+
84+
# 下载视频
85+
86+
def schedule_cmd(blocknum, blocksize, totalsize):
87+
percent = 100.0 * blocknum * blocksize/ totalsize
88+
s = ('#' * round(percent)).ljust(100, '-')
89+
sys.stdout.write('%.2f%%' % percent + '[' + s + ']' + '\r')
90+
sys.stdout.flush()
91+
92+
# 下载视频
93+
def download(video_list, title, bid):
94+
for i in video_list:
95+
opener = urllib.request.build_opener()
96+
# 请求头
97+
opener.addheaders = [
98+
('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'),
99+
('Accept', '*/*'),
100+
('Accept-Language', 'en-US,en;q=0.5'),
101+
('Accept-Encoding', 'gzip, deflate, br'),
102+
('Range', 'bytes=0-'),
103+
('Referer', 'https://www.bilibili.com/video/'+bid),
104+
('Origin', 'https://www.bilibili.com'),
105+
('Connection', 'keep-alive'),
106+
107+
]
108+
109+
filename=os.path.join('D:\\video', r'{}_{}.mp4'.format(bid,title))
110+
111+
try:
112+
urllib.request.install_opener(opener)
113+
urllib.request.urlretrieve(url=i, filename=filename, reporthook=schedule_cmd)
114+
except:
115+
print(bid + "下载异常,文件:" + filename)
116+
117+
if __name__ == '__main__':
118+
# algorithm_enc(545821176)
119+
bids = find_bid(1)
120+
print(len(bids))
121+
for bid in bids:
122+
sleep(10)
123+
cid_list = get_cid(bid)
124+
125+
for item in cid_list:
126+
cid = item['cid']
127+
title = item['title']
128+
title = re.sub(r'[\/\\:*?"<>|]', '', title) # 替换为空的
129+
bid = item['bid']
130+
video_list = get_video_list(bid, cid, 80)
131+
132+
download(video_list, title, bid)

0 commit comments

Comments
 (0)