Skip to content

Commit 9ce71ba

Browse files
authored
Merge pull request Show-Me-the-Code#237 from A1014280203/master
almost finished
2 parents f62e9ad + 5e0c6c8 commit 9ce71ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2108
-0
lines changed

A1014280203/0/0.1.png

69.3 KB
Loading

A1014280203/0/0.png

77.8 KB
Loading

A1014280203/0/0.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from PIL import Image, ImageFont, ImageDraw
2+
3+
image = Image.open('0.png')
4+
w, h = image.size
5+
font = ImageFont.truetype('arial.ttf', 50)
6+
draw = ImageDraw.Draw(image)
7+
draw.text((4*w/5, h/5), '5', fill=(255, 10, 10), font=font)
8+
image.save('0.0.png', 'png')

A1014280203/1/1.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import base64
2+
3+
# base64编码方便使用
4+
5+
# 通过id检验优惠券是否存在,通过goods查找商品
6+
coupon = {
7+
'id': '1231',
8+
'goods': '0001',
9+
}
10+
11+
12+
def gen_coupon(id, goods):
13+
coupon['id'] = id
14+
coupon['goods'] = goods
15+
raw = '/'.join([k + ':' + v for k, v in coupon.items()])
16+
raw_64 = base64.urlsafe_b64encode(raw.encode('utf-8'))
17+
c_code = raw_64.decode()
18+
return c_code
19+
20+
21+
def save_coupon(c_code):
22+
with open('coupon.txt', 'a+') as file:
23+
file.write(c_code+'\n')
24+
25+
26+
def show_coupon(c_code):
27+
print('优惠码:', c_code)
28+
29+
30+
def parse_coupon(c_code):
31+
print('解析优惠码:', base64.urlsafe_b64decode(c_code.encode('utf-8')))
32+
33+
34+
def gen_all():
35+
for i in range(1000, 1200):
36+
c_code = gen_coupon(str(i), str(int(i/2)))
37+
save_coupon(c_code)
38+
39+
40+
if __name__ == '__main__':
41+
gen_all()

0 commit comments

Comments
 (0)