Skip to content

Instantly share code, notes, and snippets.

@coder-pig
Forked from Glowin/douyin.py
Last active November 27, 2019 04:16
Show Gist options
  • Save coder-pig/83833bcc5bc186e978886388c4c63e7b to your computer and use it in GitHub Desktop.
Save coder-pig/83833bcc5bc186e978886388c4c63e7b to your computer and use it in GitHub Desktop.
2019年掘金 1024 特别视频活动抽奖代码 https://juejin.im/post/5daeffcb5188257a63539bae
import os
import json
import random
path = "/Users/glow/Desktop/aa/douyin/json" # json 文件位置
files = os.listdir(path)
jueyou = {} # 存储抖音所有掘友的 ID 和留言内容 为词典
nameList = [] # 存储掘友 ID
for file in files:
if not os.path.isdir(file):
with open(path+"/"+file) as f:
js = json.load(f)
for content in js["notice_list"]:
name = content["comment"]["comment"]["user"]["nickname"]
comment = content["comment"]["comment"]["text"]
jueyou[name] = comment
nameList.append(name)
newNameList = list(set(nameList))
print("1024活动抖音参与评论数为:", len(nameList))
print("1024活动抖音参与总人数为:", len(newNameList))
for i in range(10):
lucky = random.randint(1,len(newNameList)) - 1
print("获得掘金笔记本的掘友抖音用户名是:%s 他的评论内容为:%s" % (newNameList[lucky], jueyou[newNameList[lucky]]))
newNameList.pop(lucky) # 中奖就不进入下次奖池
for i in range(10):
lucky = random.randint(1,len(newNameList)) - 1
print("获得掘金鼠标垫的掘友抖音用户名是:%s 他的评论内容为:%s" % (newNameList[lucky], jueyou[newNameList[lucky]]))
newNameList.pop(lucky) # 中奖就不进入下次奖池
for i in range(10):
lucky = random.randint(1,len(newNameList)) - 1
print("获得掘金水杯的掘友抖音用户名是:%s 他的评论内容为:%s" % (newNameList[lucky], jueyou[newNameList[lucky]]))
newNameList.pop(lucky)
for i in range(5):
lucky = random.randint(1,len(newNameList)) - 1
print("获得掘金T恤的掘友抖音用户名是:%s 他的评论内容为:%s" % (newNameList[lucky], jueyou[newNameList[lucky]]))
newNameList.pop(lucky)
for i in range(5):
lucky = random.randint(1,len(newNameList)) - 1
print("获得掘金大礼包的掘友抖音用户名是:%s 他的评论内容为:%s" % (newNameList[lucky], jueyou[newNameList[lucky]]))
newNameList.pop(lucky)
// 提取所有有效评论
var nameList = []
var commentData = {}
var domList = document.querySelectorAll(".comment-divider-line")
for( var i = 0; i < domList.length; i++) {
var userName = domList[i].querySelectorAll(".ellipsis")[0].innerText
var userComment = domList[i].querySelectorAll(".content")[0].innerText
commentData[userName] = userComment
nameList.push(userName)
}
// 数组去重
var newNameList = Array.from(new Set(nameList))
// 奖品,抽取数量
var gift = "XXX"
var count = 5
// 开始抽奖
for( var i = 0; i < count; i++ ) {
// 生成一位幸运的掘友
var lucky = Math.floor(newNameList.length * Math.random())
console.log(`获得「${gift}」的掘友是:${newNameList[lucky]},留言为:${commentData[newNameList[lucky]]}`)
// 把中奖机会让给其他掘友
newNameList.splice(lucky, 1)
}
import os
import json
import random
path = "/Users/panzimeng/Downloads/微信公众号/json" # json 文件位置
files = os.listdir(path)
jueyou = {} # 存储抖音所有掘友的 ID 和留言内容 为词典
nameList = [] # 存储掘友 ID
for file in files:
if not os.path.isdir(file):
with open(path+"/"+file) as f:
js = json.load(f)
data = json.loads(js["comment_list"])
commentArray = data["comment"]
for content in commentArray:
name = content["nick_name"]
comment = content["content"]
jueyou[name] = comment
nameList.append(name)
newNameList = list(set(nameList))
print("1024活动抖音参与评论数为:", len(nameList))
print("1024活动抖音参与总人数为:", len(newNameList))
for i in range(6):
lucky = random.randint(1,len(newNameList)) - 1
print("获得掘金笔记本的掘友用户名是:%s,留言内容为:%s" % (newNameList[lucky], jueyou[newNameList[lucky]]))
newNameList.pop(lucky) # 中奖就不进入下次奖池
for i in range(6):
lucky = random.randint(1,len(newNameList)) - 1
print("获得掘金鼠标垫的掘友用户名是:%s,留言内容为:%s" % (newNameList[lucky], jueyou[newNameList[lucky]]))
newNameList.pop(lucky) # 中奖就不进入下次奖池
for i in range(6):
lucky = random.randint(1,len(newNameList)) - 1
print("获得掘金水杯的掘友用户名是:%s,留言内容为:%s" % (newNameList[lucky], jueyou[newNameList[lucky]]))
newNameList.pop(lucky) # 中奖就不进入下次奖池
for i in range(3):
lucky = random.randint(1,len(newNameList)) - 1
print("获得掘金大礼包的掘友用户名是:%s,留言内容为:%s" % (newNameList[lucky], jueyou[newNameList[lucky]]))
newNameList.pop(lucky) # 中奖就不进入下次奖池
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment