本文整理汇总了Python中spider.Spider.authorized方法的典型用法代码示例。如果您正苦于以下问题:Python Spider.authorized方法的具体用法?Python Spider.authorized怎么用?Python Spider.authorized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spider.Spider
的用法示例。
在下文中一共展示了Spider.authorized方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from spider import Spider [as 别名]
# 或者: from spider.Spider import authorized [as 别名]
def get(self, *args, **kwargs):
query = self.get_argument("query")
student_number = self.get_argument("stu_no")
password = self.get_argument("pwd")
spider = Spider(student_number=student_number, password=password)
spider.authorized()
student_id = spider.student_id
self.set_header("Content-Type", "application/json")
try:
if query == "semester":
storage = self.redis_cls.get_semester_grade(student_id)
if storage is None:
current = spider.parse_semester_grade()
if current.code != 0:
self.write(json.dumps(dict(current._asdict())))
return
data = current.data
else:
data = storage
elif query == "pass":
storage = self.redis_cls.get_passed_grade(student_id)
if storage is None:
current = spider.parse_passed_grade()
if current.code != 0:
self.write(json.dumps(dict(current._asdict())))
return
data = current.data
else:
data = storage
elif query == "fail":
storage = self.redis_cls.get_failed_grade(student_id)
if storage is None:
current = spider.parse_failed_grade()
if current.code != 0:
self.write(json.dumps(dict(current._asdict())))
return
data = current.data
else:
data = storage
else:
raise ValueError("Query Operation Out")
self.write(gen_response(code=0x0000,
data=data,
msg="成功",
en_msg="Success"))
except Exception as err:
self.write(gen_response(code=0x0001,
msg=str(err),
en_msg="Unknown Error"))