Skip to content

Commit 50ac21f

Browse files
committed
2 parents 853f4ff + 55cd1fa commit 50ac21f

File tree

10 files changed

+684
-2
lines changed

10 files changed

+684
-2
lines changed

chaoxi/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
+ [jupyter_notebook](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/jupyter_notebook) :Python Jupyter notebook 操作
66
+ [send_email](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/send_email) :今天,我用 Python 给武汉人民发一封邮件
77
+ [Earth_view](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/Earth_view) :如何用 Python 制作地球仪?
8+
+ [twoai_chat](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/twoai_chat) :两个机器人在一起会碰撞出怎样的的火花?
89

9-
10+
twoai_chat
1011
---
1112

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

chaoxi/twoai_chat/moli_chat.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import requests
2+
3+
send_data = {
4+
"question": '你的梦想是什么?', #构建发送的数据
5+
"api_key": "a6ec389908bcc23fceb2bbe998e3313e",
6+
"api_secret": "bsa0yv06pl1p"
7+
}
8+
api_url = 'http://i.itpk.cn/api.php'
9+
chat_content = requests.post(api_url, data=send_data) #发送请求数据
10+
print(chat_content.text)

chaoxi/twoai_chat/tuling_chat.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import requests
2+
3+
send_data = {
4+
"key": "9fd874929409453991db78f8b46a446b",
5+
"info": '我叫你一声你敢答应吗', #构建发送的数据
6+
"userid": "622952"
7+
}
8+
api_url = 'http://www.tuling123.com/openapi/api'
9+
chat_content = requests.post(api_url, data=send_data) #发送请求数据
10+
print(chat_content.text)

chaoxi/twoai_chat/twoai_chat.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import requests
2+
import time
3+
4+
question = input("请开始你们的表演:") # 输入问题开始表演
5+
6+
girl = "小姐姐"
7+
boy = "小哥哥"
8+
9+
print(boy+':'+question)
10+
11+
while True:
12+
boy_data = {
13+
"key": "9fd874929409453991db78f8b46a446b",
14+
"info": question, #构建发送的数据
15+
"userid": "622952"
16+
}
17+
boy_url = 'http://www.tuling123.com/openapi/api'
18+
boy_content = requests.post(boy_url, data=boy_data) #发送请求数据
19+
print(boy + ':' + eval(boy_content.text)["text"]) # 用eval函数处理一下图灵返回的消息
20+
question = eval(boy_content.text)["text"]
21+
22+
girl_data = {
23+
"question": question, # 构建发送的数据
24+
"api_key": "a6ec389908bcc23fceb2bbe998e3313e",
25+
"api_secret": "bsa0yv06pl1p"
26+
}
27+
girl_url = 'http://i.itpk.cn/api.php'
28+
girl_content = requests.post(girl_url, data=girl_data) # 发送请求数据
29+
print(girl + ':' + girl_content.text)
30+
time.sleep(3)

moumoubaimifan/jd/jdpc.py

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import requests
2+
import random
3+
import time
4+
import os
5+
import json
6+
7+
from PIL import Image
8+
9+
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'
10+
11+
session = requests.session()
12+
13+
14+
def show_QRcode():
15+
url = 'https://qr.m.jd.com/show'
16+
params = {
17+
'appid': 133,
18+
'size': 147,
19+
't': str(int(time.time() * 1000)),
20+
}
21+
headers = {
22+
'User-Agent': user_agent,
23+
'Referer': 'https://passport.jd.com/new/login.aspx',
24+
}
25+
resp = session.get(url=url, headers=headers, params=params)
26+
27+
QRcode_path = 'QRcode.png'
28+
with open(QRcode_path, 'wb') as f:
29+
for chunk in resp.iter_content(chunk_size=1024):
30+
f.write(chunk)
31+
32+
QRcode = Image.open(QRcode_path)
33+
QRcode.show()
34+
35+
def check_QRcode():
36+
37+
url = 'https://qr.m.jd.com/check'
38+
params = {
39+
'appid': '133',
40+
'callback': 'jQuery{}'.format(random.randint(1000000, 9999999)),
41+
'token': session.cookies.get('wlfstk_smdl'),
42+
'_': str(int(time.time() * 1000)),
43+
}
44+
headers = {
45+
'User-Agent': user_agent,
46+
'Referer': 'https://passport.jd.com/new/login.aspx?ReturnUrl=https%3A%2F%2Fwww.jd.com%2F',
47+
}
48+
resp = session.get(url=url, headers=headers, params=params)
49+
resp_json = parse_json(resp.text)
50+
51+
if 'ticket' in resp_json:
52+
print(resp_json)
53+
return resp_json['ticket']
54+
else:
55+
print(resp_json['msg'])
56+
print('请刷新JD登录二维码!')
57+
os._exit(0)
58+
59+
60+
def validation_QRcode(ticket):
61+
62+
url = 'https://passport.jd.com/uc/qrCodeTicketValidation'
63+
headers = {
64+
'User-Agent': user_agent,
65+
'Referer': 'https://passport.jd.com/new/login.aspx?ReturnUrl=https%3A%2F%2Fwww.jd.com%2F',
66+
}
67+
params={
68+
't': ticket
69+
}
70+
resp = session.get(url=url, headers=headers, params=params)
71+
print(resp.text)
72+
73+
74+
def parse_json(str):
75+
return json.loads(str[str.find('{'):str.rfind('}') + 1])
76+
77+
78+
def coupon_list():
79+
url = 'https://a.jd.com/indexAjax/getCouponListByCatalogId.html'
80+
headers = {
81+
'User-Agent': user_agent,
82+
'Referer': 'https://a.jd.com/?cateId=118',
83+
}
84+
couponList = []
85+
for i in range(1, 20):
86+
params = {
87+
'callback': 'jQuery{}'.format(random.randint(1000000, 9999999)),
88+
'catalogId': '118',
89+
'page': str(i),
90+
'pageSize': '9',
91+
'_': str(int(time.time() * 1000)),
92+
}
93+
try:
94+
resp = session.get(url=url, params=params, headers=headers)
95+
json = parse_json(resp.text)
96+
couponList.extend(json['couponList'])
97+
if json['totalNum'] == 1:
98+
continue
99+
else:
100+
break
101+
except Exception:
102+
print('出错了!')
103+
return couponList
104+
105+
106+
def get_coupon(coupon_list):
107+
url = 'https://a.jd.com/indexAjax/getCoupon.html'
108+
headers = {
109+
'User-Agent': user_agent,
110+
'Referer': 'https://a.jd.com/?cateId=118',
111+
}
112+
for coupon in coupon_list:
113+
params = {
114+
'callback': 'jQuery{}'.format(random.randint(1000000, 9999999)),
115+
'key': coupon['key'],
116+
'type': '1',
117+
'_': str(int(time.time() * 1000)),
118+
}
119+
time.sleep(1)
120+
resp = session.get(url=url, params=params, headers=headers)
121+
print(resp.text)
122+
123+
124+
125+
if __name__ == '__main__':
126+
show_QRcode()
127+
128+
time.sleep(10)
129+
130+
ticket = check_QRcode()
131+
validation_QRcode(ticket)
132+
coupon_list = coupon_list()
133+
get_coupon(coupon_list)

yeke/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
+ [py-recogLP](https://github.com/JustDoPython/python-examples/tree/master/yeke/py-recogLP) :如何用 Python 识别车牌
77
+ [py-plane](https://github.com/JustDoPython/python-examples/tree/master/yeke/py-plane) :用 Python 实现微信版飞机大战
88
+ [py-rain](https://github.com/JustDoPython/python-examples/tree/master/yeke/py-rain) :用 Python 实现黑客帝国中的数字雨落既视感
9+
+ [py-facepalm](https://github.com/JustDoPython/python-examples/tree/master/yeke/py-facepalm) :用 Python 画一个捂脸表情
10+
+ [py-tetris](https://github.com/JustDoPython/python-examples/tree/master/yeke/py-tetris) :用 Python 写个俄罗斯方块
911

1012
---
1113

1214
从小白到工程师的学习之路
1315

1416
关注公众号:python 技术,回复"python"一起学习交流
1517

16-
![](http://favorites.ren/assets/images/python.jpg)
18+
![](http://favorites.ren/assets/images/python.jpg)

yeke/py-facepalm/__init__.py

Whitespace-only changes.

yeke/py-facepalm/facepalm.py

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
import turtle
2+
3+
# 画圆弧
4+
def arc(sa, ea, x, y, r):
5+
turtle.penup()
6+
turtle.goto(x, y)
7+
turtle.setheading(0)
8+
turtle.left(sa)
9+
turtle.fd(r)
10+
turtle.pendown()
11+
turtle.left(90)
12+
turtle.circle(r, (ea - sa))
13+
return turtle.position()
14+
15+
# 画脸
16+
turtle.speed(5)
17+
turtle.setup(500, 500)
18+
turtle.pensize(5)
19+
turtle.right(90)
20+
turtle.penup()
21+
turtle.fd(100)
22+
turtle.left(90)
23+
turtle.pendown()
24+
turtle.begin_fill()
25+
turtle.pencolor("#B8860B") # head side color
26+
turtle.circle(150)
27+
turtle.fillcolor("#FFFF99") # face color
28+
turtle.end_fill()
29+
30+
# 画嘴
31+
turtle.penup()
32+
turtle.goto(77, 20)
33+
turtle.pencolor("#B8860B")
34+
turtle.goto(0, 50)
35+
turtle.right(30)
36+
turtle.fd(110)
37+
turtle.right(90)
38+
turtle.pendown()
39+
turtle.begin_fill()
40+
turtle.fillcolor("#925902") # mouth color
41+
turtle.circle(-97, 160)
42+
turtle.goto(92, -3)
43+
turtle.end_fill()
44+
turtle.penup()
45+
turtle.goto(77, -25)
46+
# 画牙齿
47+
turtle.pencolor("white")
48+
turtle.begin_fill()
49+
turtle.fillcolor("white")
50+
turtle.goto(77, -24)
51+
turtle.goto(-81, 29)
52+
turtle.goto(-70, 43)
53+
turtle.goto(77, -8)
54+
turtle.end_fill()
55+
turtle.penup()
56+
turtle.goto(0, -100)
57+
turtle.setheading(0)
58+
turtle.pendown()
59+
60+
# 画左边眼泪
61+
turtle.left(90)
62+
turtle.pensize(3)
63+
turtle.penup()
64+
turtle.fd(150)
65+
turtle.right(60)
66+
turtle.fd(-150)
67+
turtle.pendown()
68+
turtle.left(20)
69+
turtle.pencolor("#155F84")
70+
turtle.fd(150)
71+
turtle.right(180)
72+
position1 = turtle.position()
73+
turtle.begin_fill()
74+
turtle.fillcolor("#B0E0E6")
75+
turtle.fd(150)
76+
turtle.right(20)
77+
turtle.left(270)
78+
turtle.circle(-150, 18)
79+
turtle.right(52)
80+
turtle.fd(110)
81+
position2 = turtle.position()
82+
turtle.goto(-33, 90)
83+
turtle.end_fill()
84+
# 画右边眼泪
85+
turtle.penup()
86+
turtle.goto(0, 0)
87+
turtle.setheading(0)
88+
turtle.left(90)
89+
turtle.fd(50)
90+
turtle.right(150)
91+
turtle.fd(150)
92+
turtle.left(150)
93+
turtle.fd(100)
94+
turtle.pendown()
95+
turtle.begin_fill()
96+
turtle.fd(-100)
97+
turtle.fillcolor("#B0E0E6")
98+
turtle.right(60)
99+
turtle.circle(150, 15)
100+
turtle.left(45)
101+
turtle.fd(66)
102+
turtle.goto(77, 20)
103+
turtle.end_fill()
104+
# 画眼睛
105+
turtle.pensize(5)
106+
turtle.penup()
107+
turtle.pencolor("black") # eye color
108+
turtle.goto(-65, 75)
109+
turtle.setheading(0)
110+
turtle.left(27)
111+
turtle.fd(30)
112+
turtle.pendown()
113+
turtle.begin_fill()
114+
turtle.fillcolor("black") # eye color
115+
turtle.left(90)
116+
turtle.circle(30, 86)
117+
turtle.goto(position2[0], position2[1])
118+
turtle.goto(position1[0], position1[1])
119+
turtle.end_fill()
120+
121+
# 画手
122+
turtle.pencolor("#B8860B")
123+
turtle.fillcolor("#FFFF99")
124+
# 第一个手指
125+
arc(-110, 10, 110, -40, 30)
126+
turtle.begin_fill()
127+
turtle.circle(300, 35)
128+
turtle.circle(13, 120)
129+
turtle.setheading(-50)
130+
turtle.fd(20)
131+
turtle.setheading(130)
132+
# 第二个手指
133+
turtle.circle(200, 15)
134+
turtle.circle(12, 180)
135+
turtle.fd(40)
136+
turtle.setheading(137)
137+
# 第三个手指
138+
turtle.circle(200, 16)
139+
turtle.circle(12, 160)
140+
turtle.setheading(-35)
141+
turtle.fd(45)
142+
turtle.setheading(140)
143+
# 第四个手指
144+
turtle.circle(200, 13)
145+
turtle.circle(11, 160)
146+
turtle.setheading(-35)
147+
turtle.fd(40)
148+
turtle.setheading(145)
149+
# 第五个手指
150+
turtle.circle(200, 9)
151+
turtle.circle(10, 180)
152+
turtle.setheading(-31)
153+
turtle.fd(50)
154+
# 画最后手腕的部分
155+
turtle.setheading(-45)
156+
turtle.pensize(7)
157+
turtle.right(5)
158+
turtle.circle(180, 35)
159+
turtle.end_fill()
160+
turtle.begin_fill()
161+
turtle.setheading(-77)
162+
turtle.fd(50)
163+
turtle.left(-279)
164+
turtle.fd(16)
165+
turtle.circle(29, 90)
166+
turtle.end_fill()
167+
turtle.hideturtle()
168+
turtle.done()

yeke/py-tetris/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)