-
-
Save JichunMa/f18411b38407f72c8323bfd5bd275467 to your computer and use it in GitHub Desktop.
抽奖~
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import requests | |
url = 'https://www.v2ex.com/api/replies/show.json?topic_id=490659' | |
# 中奖人数 | |
numberOfWinners = 4 | |
if __name__ == '__main__': | |
source = requests.get(url) | |
names_list = [] | |
for item in source.json(): | |
username = str(item['member']['username']) | |
names_list.append(str(item['member']['username'])) | |
# print("list length: " + str(len(names_list))) | |
names_set = set(names_list) | |
totalMembersCount = len(names_set) | |
print("本次参与活动人数为:{}".format(totalMembersCount)) | |
print("-" * 20) | |
for name in names_set: | |
print(name) | |
print("-" * 20) | |
luckyMembers = random.sample(list(names_set), numberOfWinners) | |
print("恭喜中奖用户:" + str(luckyMembers)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment