Skip to content

Instantly share code, notes, and snippets.

@rikumi
Created August 29, 2017 15:10
Show Gist options
  • Save rikumi/d1a52143f6c28ef7ae28935b70f9a032 to your computer and use it in GitHub Desktop.
Save rikumi/d1a52143f6c28ef7ae28935b70f9a032 to your computer and use it in GitHub Desktop.
import json, urllib
import tornado.web
import tornado.gen
from datetime import date, timedelta
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
class NewNewHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
@tornado.gen.engine
def post(self):
ret = { 'code': 200, 'content': '' }
try:
campus_id = self.get_argument('campusId', default='22')
date = self.get_argument('date')
building_id = self.get_argument('buildingId')
start_sequence = self.get_argument('startSequence')
end_sequence = self.get_argument('endSequence')
page = self.get_argument('page')
page_size = self.get_argument('pageSize', default='20')
client = AsyncHTTPClient()
request = HTTPRequest('http://58.192.114.179/classroom/common/getdateofweek?date=' + date)
response = yield tornado.gen.Task(client.fetch, request)
date_info = json.loads(response.body)
request = HTTPRequest('http://58.192.114.179/classroom/show/getemptyclassroomlist',
method='POST',
data=urllib.urlencode({
'pageNo': page,
'pageSize': page_size,
'campusId': campus_id,
'buildingId': building_id,
'startWeek': date_info['week'],
'endWeek': date_info['week'],
'dayOfWeek': date_info['dayOfWeek'],
'startSequence': start_sequence,
'endSequence': end_sequence,
'termId': date_info['termId']
}))
response = yield tornado.gen.Task(client.fetch, request)
ret['content'] = json.loads(response.body)
except Exception,e:
ret['code'] = 500
ret['content'] = u'系统错误'
self.write(json.dumps(ret,ensure_ascii=False, indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment