ay2021

0、作者不承担任何法律责任!仅供学习交流使用,严禁用于其他用途

1、info.txt

个人信息,nickname为你的微信昵称
在这里插入图片描述

2、raw.PNG

以此图片为底图制作最终图片
在这里插入图片描述

3、touxiang.jpg

微信头像
在这里插入图片描述

4、源码QNDXX.py

 1 import requests
 2 import re
 3 from PIL import Image, ImageDraw, ImageFont
 4 
 5 #  作者不承担任何法律责任!
 6 #  仅供学习交流使用,严禁用于其他用途
 7 
 8 
 9 def get_url():  # 获取最新一期大学习的url
10     html = requests.get(\'http://news.cyol.com/node_67071.htm\').text
11     url = re.findall(\'href="(.*?)" target\', html)[0]
12     return url
13 
14 
15 def get_id(url):  # 从url中提取本期的id
16     the_id = url.split(\'/\')[-2]
17     return the_id
18 
19 
20 def get_icon(the_id):  # 根据id获取本期的分享缩略图
21     addr = \'http://h5.cyol.com/special/daxuexi/%s/images/icon.jpg\' % the_id
22     icon = requests.get(addr).content
23     with open(\'icon.jpg\', \'wb\') as f:
24         f.write(icon)
25 
26 
27 def get_end(the_id):  # 根据id获取本期的完成图片
28     addr = \'http://h5.cyol.com/special/daxuexi/%s/images/end.jpg\' % the_id
29     end = requests.get(addr).content
30     with open(\'end.jpg\', \'wb\') as f:
31         f.write(end)
32 
33 
34 def get_info(file=\'info.txt\'):  # 从info文本中提取文字信息
35     with open(file, \'r\', encoding=\'utf-8\') as f:
36         info = []
37         for line in f.readlines():
38             line = line.strip(\'\n\')
39             i = line.split(\':\')
40             info.append(i)
41         info = dict(info)
42     return info
43 
44 
45 def change(raw=\'raw.png\', icon=\'icon.jpg\', touxiang=\'touxiang.jpg\'):  # 以raw为底图制作图片result
46     result = Image.open(raw)
47     icon = (Image.open(icon)).resize((80, 80), resample=0)
48     touxiang = (Image.open(touxiang)).resize((80, 80), resample=0)
49     result.paste(icon, (123, 330))
50     result.paste(touxiang, (13, 132))
51 
52     \'\'\'========================以下为加文字部分===========================\'\'\'
53     info = get_info()
54     font = ImageFont.truetype(\'C:/windows/fonts/Simhei.ttf\', size=32)
55     draw = ImageDraw.Draw(result)
56     draw.text((215, 355), info[\'share\'], fill=\'black\', font=font)  # 期数
57     draw.text((116, 135), info[\'nickname\'], fill=(87, 107, 149), font=font)  # 昵称
58     draw.text((116, 190), info[\'school\'], fill=\'black\', font=font)  # 学院
59     draw.text((116, 230), info[\'name\'], fill=\'black\', font=font)  # 姓名
60     draw.text((116, 270), info[\'stu_num\'], fill=(87, 107, 149), font=font)  # 学号
61     result.save(\'result.png\')
62 
63 
64 def run():
65     url = get_url()
66     Id = get_id(url)
67     get_icon(Id)
68     get_end(Id)
69     change()
70 
71 
72 if __name__ == \'__main__\':
73     run()

 

5、

在这里插入图片描述
在这里插入图片描述

 

分类:

技术点:

相关文章:

  • 2021-07-30
  • 2021-11-12
  • 2022-12-23
  • 2021-12-12
  • 2021-11-10
  • 2022-12-23
  • 2021-10-19
  • 2021-06-12
猜你喜欢
  • 2022-12-23
  • 2021-06-18
  • 2022-01-06
  • 2021-09-07
  • 2021-12-21
  • 2021-07-24
相关资源
相似解决方案