index.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:ScheduleStorm_Server 作者: Step7750 项目源码 文件源码
def on_get(self, req, resp, uni, term):
        # The term must be a string since the threads represent them as such
        if uni in uniThreads and term in uniThreads[uni].getTerms():
            if uniThreads[uni].isScraping:
                # we don't want to return data while scraping, send error (configure nginx to send stale data if it can)
                resp.status = falcon.HTTP_500
                resp.body = json.dumps(
                    {"error": "We're currently scraping this university, please check back in a couple minutes!"}
                ).encode('utf-8')
            else:
                # Get course/subject list
                subject_list = json.dumps(uniThreads[uni].getSubjectListAll(term), sort_keys=True).encode('utf-8')

                # set the etag and body
                resp.etag = "W/" + hashlib.sha1(subject_list).hexdigest()
                resp.body = subject_list
        else:
            # Couldn't find the uni or term, send error
            resp.status = falcon.HTTP_400
            resp.body = json.dumps(
                {"error": "The specified university or term was not found"}
            ).encode('utf-8')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号