首页 / PYTHON / 某社区自动顶贴python源码
某社区自动顶贴python源码
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了某社区自动顶贴python源码,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含10582字,纯文字阅读大概需要16分钟。
内容图文
![某社区自动顶贴python源码](/upload/InfoBanner/zyjiaocheng/620/30c072e2603746bd9db991d586dfe8b0.jpg)
关注https://www.o200.cn自动化测试平台
#登录获取sessionkey 原来的已登录会失效
def get_key(phone,psw):
#密码加密
input_name = hashlib.md5()
input_name.update(psw.encode("utf-8"))
pswmd5=(input_name.hexdigest()).lower()
#设备码
c=["0","1","2","3","4","5","6","7","8","9","c","e","f","b","d"]
randcode=random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)+"-"+random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)+"-"+random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)+"-"+random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)+"-"+random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)+random.choice(c)
url="http://xxx.com/account/login/ANDROID/4.0?platform=2&gkey=000000&app_version=4.0.1.9.1&versioncode=309&market_id=tool_web&_key=&device_code=%5Bw%5D02%3A00%3A00%3A00%3A00%3A00%5Bd%5D"+randcode
header={"Content-Type":"application/x-www-form-urlencoded","User-Agent":"okhttp/3.8.1","Host":"xxx.com"}
param={"login_type":"2"}
param["account"]=phone
param["password"]=pswmd5
res=requests.post(url,data=param,headers=header)
if "avatar" in res.text:
key=re.findall(r'key":"(.+?)"',res.text)
key=key[0]
return key,randcode
else:
return "loginfail"
下面调用上面的登录方法获得到sessionkey
#执行顶贴
@csrf_exempt
def hlxrun(request):
uname=request.session.get("username","")
user_exist=bkuser.objects.filter(bkuser_name=uname)
admin_exist=bkadmin.objects.filter(bkadmin_name=uname)
if user_exist:
userinfo=bkuser.objects.get(bkuser_name=uname)
hconf=hlxconf.objects.get(hlxtoplinkuser_id=userinfo.id)
if request.method=="POST":
phone=request.POST.get("phone")
psw=request.POST.get("psw")
postid=request.POST.get("postid")
content=request.POST.get("content")
tophour=request.POST.get("tophour")
topmin=request.POST.get("topmin")
topsec=request.POST.get("topsec")
rands=request.POST.get("rands")
rande=request.POST.get("rande")
loginres=get_key(phone,psw)
#校验
hourinfo=""
minuteinfo=""
secondinfo=""
if tophour =="0":
hourinfo=0
if tophour !="0":
hourinfo=tophour
if topmin =="0":
minuteinfo=0
if topmin !="0":
minuteinfo=topmin
if topsec =="0":
secondinfo=0
if topsec !="0":
secondinfo=topsec
if phone=="":
return HttpResponse('{"topcode":"phonefail"}',content_type="application/json")
elif psw=="":
return HttpResponse('{"topcode":"pswfail"}',content_type="application/json")
elif postid=="" or (not (re.findall(r"^\d+$",str(postid)))):
return HttpResponse('{"topcode":"idfail"}',content_type="application/json")
elif content=="":
return HttpResponse('{"topcode":"contentfail"}',content_type="application/json")
elif not (re.findall(r"^\d+$",str(tophour))) or int(tophour)<0 or int(tophour)>23:
return HttpResponse('{"topcode":"hourfail"}',content_type="application/json")
elif not (re.findall(r"^\d+$",str(topmin))) or int(topmin)<0 or int(topmin)>59:
return HttpResponse('{"topcode":"minfail"}',content_type="application/json")
elif not (re.findall(r"^\d+$",str(topsec))) or int(topsec)<0 or int(topsec)>59:
return HttpResponse('{"topcode":"secfail"}',content_type="application/json")
elif int(tophour)==int(topmin)==int(topsec)==0:
return HttpResponse('{"topcode":"zerofail"}',content_type="application/json")
elif hconf.hlxtop_status==0:
return HttpResponse('{"topcode":"noAuthority"}',content_type="application/json")
elif not re.findall(r"【.+?】",str(content)):
return HttpResponse('{"topcode":"refail"}',content_type="application/json")
elif rands=="" or rande=="":
return HttpResponse('{"topcode":"randnull"}',content_type="application/json")
elif (not re.findall(r"^[0-9]\d*$",rands)) or (not re.findall(r"^[0-9]\d*$",rande)):
return HttpResponse('{"topcode":"randint"}',content_type="application/json")
elif rande<rands:
return HttpResponse('{"topcode":"randsmall"}',content_type="application/json")
elif loginres=="loginfail":
return HttpResponse('{"topcode":"loginfail"}',content_type="application/json")
else:
key=loginres[0]
devicecode=loginres[1]
topinfo=hlxtopinfo.objects.filter(hlxtopinfolinkuser_id=userinfo.id)
if topinfo:
topinfo=hlxtopinfo.objects.get(hlxtopinfolinkuser_id=userinfo.id)
topinfo.hlxtopinfo_postid=postid
topinfo.hlxtopinfo_content=content
topinfo.hlxtopinfo_hour=tophour
topinfo.hlxtopinfo_minute=topmin
topinfo.hlxtopinfo_second=topsec
topinfo.hlxtopinfo_status=1
topinfo.hlxtopinfo_sessionkey=key
topinfo.hlxtopinfo_phone=phone
topinfo.hlxtopinfo_psw=psw
topinfo.hlxtopinfo_randstart=rands
topinfo.hlxtopinfo_randend=rands
topinfo.save()
#执行定时器
sched.add_job(trigger='interval',func=hlx_top,args=[postid,content,devicecode,key,rands,rande],hours=int(hourinfo),minutes=int(minuteinfo),seconds=int(secondinfo),id="hlx_"+uname)
return HttpResponse('{"topcode":"success"}',content_type="application/json")
else:
hlxtopinfo.objects.get_or_create(hlxtopinfo_postid=postid,
hlxtopinfo_content=content,
hlxtopinfolinkuser_id=userinfo.id,
hlxtopinfo_hour=tophour,
hlxtopinfo_minute=topmin,
hlxtopinfo_second=topsec,
hlxtopinfo_status=1,
hlxtopinfo_sessionkey=key,
hlxtop_name="hlx_"+uname,
hlxtopinfo_phone=phone,
hlxtopinfo_psw=psw,
hlxtopinfo_randstart=rands,
hlxtopinfo_randend=rande
)
sched.add_job(trigger='interval',func=hlx_top,args=[postid,content,devicecode,key,rands,rande],hours=int(hourinfo),minutes=int(minuteinfo),seconds=int(secondinfo),id="hlx_"+uname)
return HttpResponse('{"topcode":"success"}',content_type="application/json")
elif admin_exist:
return redirect("/boss/")
else:
return redirect("/login/")
定时器执行顶贴任务
def hlx_top(postid,content,devicecode,key,rands,rande):
tsleep=random.randint(int(rands),int(rande))
time.sleep(tsleep)
url="http://xxx.com/comment/create/ANDROID/2.0?platform=2&gkey=000000&app_version=4.0.1.9.1&versioncode=309&market_id=tool_web&_key="+key+"&device_code=%5Bw%5D02%3A00%3A00%3A00%3A00%3A00%5Bd%5D"+devicecode
header={"Content-Type":"application/x-www-form-urlencoded","User-Agent":"okhttp/3.8.1","Host":"xxx.com"}
param={"comment_id":"0","patcha":"","images":"","remindUsers":""}
param["post_id"]=postid
contentlist=re.findall(r"【(.+?)】",content)
#随机取回复列表的值
con=random.choice(contentlist)
cont=parse.quote(con)
param["text"]=cont
test=requests.post(url,data=param,headers=header)
print(test.text)
有执行就有暂停就是kill掉任务就行
#暂停顶贴
@csrf_exempt
def hlxstop(request):
uname=request.session.get("username","")
user_exist=bkuser.objects.filter(bkuser_name=uname)
admin_exist=bkadmin.objects.filter(bkadmin_name=uname)
if user_exist:
userinfo=bkuser.objects.get(bkuser_name=uname)
if request.method=="POST":
#状态改为0
hlxinfo=hlxtopinfo.objects.get(hlxtopinfolinkuser_id=userinfo.id)
hlxinfo.hlxtopinfo_status=0
hlxinfo.save(update_fields=["hlxtopinfo_status"])
#暂停顶贴
sched.remove_job("hlx_"+uname)
return HttpResponse('{"topcode":"success"}',content_type="application/json")
elif admin_exist:
return redirect("/boss/")
else:
return redirect("/login/")
比如有到期时间的话就得实时校验是否过期
#顶贴时间过期校验
def checkhlxtop():
hlxtopall=hlxconf.objects.filter()
for topone in hlxtopall:
userinfo=bkuser.objects.get(id=topone.hlxtoplinkuser_id)
todaytime=datetime.datetime.now()
offset = datetime.timedelta(hours=8) #服务器时间少8小时
re_date = (todaytime + offset).strftime('%Y-%m-%d %H:%M:%S')
re_date=datetime.datetime.strptime(re_date,"%Y-%m-%d %H:%M:%S")
re_date=datetime.datetime.strftime(re_date,"%Y%m%d%H%M%S")
endtime=datetime.datetime.strftime(topone.hlxtop_endtime,"%Y%m%d%H%M%S")
# 权限过期
if int(re_date)>=int(endtime):
# 用户权限关闭
topone.hlxtop_status=0
topone.save(update_fields=["hlxtop_status"])
#任务权限关闭
taskone=hlxtopinfo.objects.filter(hlxtopinfolinkuser_id=topone.hlxtoplinkuser_id)
if taskone:
taskone=hlxtopinfo.objects.get(hlxtopinfolinkuser_id=topone.hlxtoplinkuser_id)
if taskone.hlxtopinfo_status==1:
taskone.hlxtopinfo_status=0
taskone.save(update_fields=["hlxtopinfo_status"])
#任务移除
sched.remove_job("hlx_"+userinfo.bkuser_name)
接口自动化https://www.o200.cn
内容总结
以上是互联网集市为您收集整理的某社区自动顶贴python源码全部内容,希望文章能够帮你解决某社区自动顶贴python源码所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。