Skip to content

Commit 8c7108d

Browse files
committed
add zfb thank list
1 parent 4076596 commit 8c7108d

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
小彭大典的持续编写离不开以下小彭友的赞助!
3838

39-
[![Thanks list](docs/img/thanks.png)](https://afdian.net/a/archibate)
39+
<a href="https://afdian.net/a/archibate"><img src="docs/img/thanks.png" alt="https://afdian.net/a/archibate" width="400px"/></a>
4040

4141
> [!NOTE]
4242
> 小彭老师的大典是免费下载的,不用赞助也可以查看哦。

docs/img/thanks.png

66.5 KB
Loading

misc/afdian.py

+36-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import namedtuple
12
import os
23
import requests
34
import time
@@ -6,6 +7,19 @@
67
from PIL import Image, ImageDraw, ImageFont
78
from io import BytesIO
89

10+
class User(namedtuple('User', ['name', 'avatar', 'all_sum_amount'])):
11+
pass
12+
13+
manual_sponsors = [
14+
User('等疾风', 'https://i0.hdslb.com/bfs/face/b658b5ca52f41e53321d04f978be6784ca6f8687.jpg', 1000.00),
15+
User('只喝白开水', 'https://i2.hdslb.com/bfs/face/821b88a24c1319d1fb51b3854884e2f829855c75.jpg', 100.00),
16+
User('*乾', '', 26.90),
17+
User('柿柿如意', '', 20.00),
18+
User('Starry', '', 100.00),
19+
User('阿哲', '', 100.00),
20+
User('Eureka', '', 20.00),
21+
]
22+
923
def afd_query(which, **params):
1024
user_id = '6256dedc1af911eebf8152540025c377'
1125
token = os.environ['AFDIAN_TOKEN']
@@ -28,34 +42,49 @@ def afd_query_sponsors():
2842
page = afd_query('query-sponsor', page=i)
2943
n = page['total_page']
3044
for user in page['list']:
31-
res.append(user)
45+
res.append(User(user['user']['name'], user['user']['avatar'], user['all_sum_amount']))
3246
if i >= n:
3347
break
3448
i += 1
3549
return res
3650

3751
def afd_gen_thank_list():
38-
sponsors = list(reversed(afd_query_sponsors()))
52+
sponsors = afd_query_sponsors()
53+
sponsors += manual_sponsors
54+
max_x = 30
3955
max_y = 30
56+
limit_y = 600
57+
max_max_y = max_y
4058
for user in sponsors:
4159
max_y += 100
60+
if max_y + 10 >= limit_y:
61+
max_max_y = max(max_max_y, max_y)
62+
max_y = 30
63+
max_x += 400
64+
max_max_y = max(max_max_y, max_y)
65+
max_max_x = max_x + 400
4266
max_y += 10
43-
img = Image.new('RGB', (800, max_y), color='#19242e')
67+
img = Image.new('RGB', (max_max_x, max_max_y), color='#19242e')
4468
x = 30
4569
y = 30
4670
for user in sponsors:
4771
draw = ImageDraw.Draw(img)
4872
font = ImageFont.truetype('/usr/share/fonts/noto-cjk/NotoSansCJK-Medium.ttc', size=20)
49-
avatar = Image.open(BytesIO(requests.get(user['user']['avatar']).content))
73+
avatar = Image.open(BytesIO(requests.get(user.avatar).content)) if user.avatar else Image.open(
74+
os.path.join(os.path.dirname(os.path.abspath(__file__)), '../docs/img/favicon.ico'))
5075
avatar = avatar.resize((80, 80))
5176
img.paste(avatar, (x, y))
52-
draw.text((x + 100, y), f'{user['user']['name']}', fill='white', font=font)
53-
draw.text((x + 100, y + 30), f'¥{user['all_sum_amount']}', fill='#aaaaaa', font=font)
54-
print(f'{user['user']['name']}{user['all_sum_amount']}')
77+
draw.text((x + 100, y), f'{user.name}', fill='white', font=font)
78+
draw.text((x + 100, y + 30), f'¥{user.all_sum_amount}', fill='#aaaaaa', font=font)
79+
print(f'{user.name}{user.all_sum_amount}')
5580
print(user)
5681
y += 100
82+
if y + 10 >= limit_y:
83+
y = 30
84+
x += 400
5785
return img
5886

5987
img = afd_gen_thank_list()
6088
file = 'docs/img/thanks.png'
6189
img.save(file)
90+
img.show()

0 commit comments

Comments
 (0)