Skip to content

Instantly share code, notes, and snippets.

@JichunMa
Created September 19, 2018 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JichunMa/f18411b38407f72c8323bfd5bd275467 to your computer and use it in GitHub Desktop.
Save JichunMa/f18411b38407f72c8323bfd5bd275467 to your computer and use it in GitHub Desktop.
抽奖~
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