zoukankan      html  css  js  c++  java
  • 设置管理员的 蘑菇丁日报 周报、月报

    import ssl
    import json
    import urllib
    #规避警告
    context = ssl._create_unverified_context()
    # 登陆以后去访问
    from requests import Request,Session

    class Mogu():

    def get_login(self):

    login_data = {
    'loginType': 'iphone',
    'password': 'wyzy19851021',
    'phone': '18691098998'
    }
    request_data = urllib.request.Request(
    url='https://api.moguding.net:9000/session/user/v1/login',
    data=json.dumps(login_data).encode(),
    headers={'Content-Type': 'application/json; charset=UTF-8'}
    )
    try:
    #urllib.request.urlopen 模拟浏览器请求
    # json.loads() #字符串改成字典
    #.read()方法可以得到网页内容
    token = json.loads(urllib.request.urlopen(request_data, context=context).read().decode())['data']['token']
    if token:
    return {
    'code': '200',
    'info': '登录成功',
    'token': token
    }
    except Exception as e:
    if str(e) == '<urlopen error Remote end closed connection without response>':
    return {
    'code': '404',
    'info': '网络链接超时'
    }
    else:
    return {
    'code': '505',
    'info': '账号或密码错误'
    }

    # 获取学生日报(day)、周报(week)、月报(month)列表
    def GetReports(self,token):
    ids = []
    day = {"currPage": 1, "pageSize": 25, "batchId": "81925354", "classId": "",
    "teaId": "", "reportType": "day", "planId": "", "state":"","studentNumber":""}
    request_data = urllib.request.Request(
    url='https://api.moguding.net:9000/practice/paper/v1/list',
    headers={
    'Authorization': token,
    'Content-Type': 'application/json; charset=UTF-8',
    'roleKey':'depManager'
    },
    data=json.dumps(day).encode("utf-8")
    )

    try:
    request = urllib.request.urlopen(request_data, context=context).read().decode()
    print("**********",request)
    print("----------",type(request))
    for dayID in json.loads(request)['data']:
    ids.append(dayID['reportId'])
    print('正在获取批阅文件,类型: ' + "day" + ' ' + dayID['reportId'])
    return ids
    except Exception as e:
    print(e)

    def get_report(self):
    ids = []
    day = {"currPage":1,"pageSize":25,"batchId":"81925354","classId":"","teaId":"","reportType":"day","planId":"","state":"","studentNumber":""}
    url = 'https://api.moguding.net:9000/practice/paper/v1/list',
    content = self.session.post(url,data=day)
    print("content",content.text)

    if __name__ == '__main__':

    mo = Mogu()
    response = mo.get_login()
    print("登录:",response)

    token = response['token']
    mo.GetReports(token)
  • 相关阅读:
    linux脚本启动停止一个jar
    如何突破各种防火墙的防护 [转]
    linux查看端口占用
    网页标题图标添加
    Go语言的一些使用心得
    kubernetes系列之ConfigMap使用方式
    Kubernetes因限制内存配置引发的错误
    Kubernetes系列之理解K8s Service的几种模式
    kubernetes中的Pause容器如何理解?
    Kubernetes系列之Helm介绍篇
  • 原文地址:https://www.cnblogs.com/yuanjia8888/p/13503666.html
Copyright © 2011-2022 走看看