关注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源码相关推荐

  1. mybatis代码自动生成器_最近很火的文章自动生成器,python源码公开了(内附python代码)

    学了python,但是又不知道可以用来干嘛.开发一个计算器?太low了.开发一个网站?感觉网站涉及太多知识点,一个人搞不定.不用慌,本文介绍一个最近很火的一个文章自动生成器,它是用python写的,能 ...

  2. python小说自动生成器_最近很火的文章自动生成器,python源码公开了(内附python代码)...

    学了python,但是又不知道可以用来干嘛.开发一个计算器?太low了.开发一个网站?感觉网站涉及太多知识点,一个人搞不定.不用慌,本文介绍一个最近很火的一个文章自动生成器,它是用python写的,能 ...

  3. [Python] 【原创】[Python源码]企业支付宝自动批量转账脚本

    [Python] [原创][Python源码]企业支付宝自动批量转账脚本 -- coding: utf-8 -- import sys import time import datetime impo ...

  4. 用python的OCR实现自动拍照搜题--源码

    自动拍照搜题源码 说明: 因为有很多人要源码,所以还是贴一下好了 很久之前的一个小demo就是搞着玩玩的没什么技术含量,马上要毕业去工作了,现在也不想在动了. 虽然是叫"自动拍照搜题&quo ...

  5. python编译器源码_编译python源码

    广告关闭 回望2020,你在技术之路上,有什么收获和成长么?对于未来,你有什么期待么?云+社区年度征文,各种定制好礼等你! 尝试通过源码自己编译 python,使用的系统是 ubuntu14.04 l ...

  6. Python源码剖析[19] —— 执行引擎之一般表达式(2)

    Python源码剖析 --Python执行引擎之一般表达式(2) 本文作者: Robert Chen(search.pythoner@gmail.com ) 3.2     Simple.py 前面我 ...

  7. Python源码学习:Python类机制分析-用户自定义类

    Python源码分析 本文环境python2.5系列 参考书籍<<Python源码剖析>> 上一文,分析了Python在启动初始化时,对内置类的一个基本的初始化流程,本文就简析 ...

  8. Python源码怎么读,听听顶级爬虫工程师的建议

    图源来自Miguel Á. Padriñán 如何高效调试Python程序?Python内部的架构设计是怎样的?多业务类型的复杂系统中,Python语言的定位是? -- 以上问题,单从研究Python ...

  9. python源码学习_【Python学习】Python源码阅读(一)

    最近想读读Python源码,任何东西学习方法基本都是一样的,先从总体框架进行了解,再从自己侧重的方面逐步深入. 1. Python总体架构 左边是Python提供的大量的模块.库以及用户自定义的模块. ...

最新文章

  1. 3.推荐系统(矩阵分解)
  2. JAVA 1.2(原生数据类型 Primitive Data Type)
  3. Google App Engine使用简介
  4. XmlPullParser
  5. java 1.6 ubuntu_ubuntu配置 Java SE 1.6
  6. linux usb拔出防止抖动,Linux 下监控USB设备拔插事件
  7. 解决Windows无法加载中文(中国)-王码五笔输入法(任何输入法都行) 键盘的布局的方法...
  8. Phase2 DAY4 List泛形
  9. 台式机dp接口_常见视频接口图示及说明
  10. Hadoop学习----Hadoop介绍
  11. 宝塔 Plugin ‘InnoDB‘ registration as a STORAGE ENGINE failed 解决办法
  12. 如何选择指针中置空?NULL, nullptr, 0?
  13. 银联卡整个pdol电子钱包扣费的过程
  14. 电力系统的延时潮流 (CPF)的计算【 IEEE-14节点】(Matlab代码实现)
  15. ADM周期-阶段目标说明
  16. I4mc-deep: 利用具有化学特性的深度学习方法,对 n4- 甲基胞嘧啶位点进行智能预测
  17. IDEA 设置背景图片及透明背景
  18. 【TDA2x学习】待整理笔记
  19. 搜狗浏览器如何下载安装 安装搜狗浏览器的详细步骤
  20. 油猴插件导致bing搜索显示“cn.bing.com“重定向次数过多

热门文章

  1. 华为手机怎么找回桌面计算机,华为手机界面文件夹消失如何恢复
  2. 使用ova镜像进行edx平台的部署、配置过程
  3. 用MPI_Send和MPI_Recv实现简单集群通信函数
  4. Windows 10下载安装Java
  5. 重回童年的经典系列☀️|【炸弹人小游戏】制作过程+解析 | 收藏起来跟曾经的小伙伴一起梦回童年!
  6. Kali Linux侦听蓝牙设备
  7. isis学不到looback口的路由_干货 | ONU、机顶盒、路由器常见网络问题及处理方法...
  8. 智能水肥一体化技术应用示范项目竞争性谈判成
  9. Java计算12小时之内,时针分针秒针重合的次数
  10. 电磁兼容(EMC)入门篇之基础知识(一)