Skip to content

Instantly share code, notes, and snippets.

@JichunMa JichunMa/mytest.py Secret
Created Sep 19, 2018

Embed
What would you like to do?
抽奖~
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
You can’t perform that action at this time.