def query_feedback(self): """ :return: """ if DEVELOPMENG: self.set_secure_cookie("qq", str(2972822179)) mysql_session = make_mysql_session() qq = self.get_secure_cookie("qq") if qq is None: return {"res": 1} logger.info(str(qq) + " query feedback") try: feedbacks = mysql_session.query(FeedbackModal).filter(FeedbackModal.getPersonQQ == qq).all() except Exception as e: # logger.error(e.message) logger.error(traceback.format_exc()) mysql_session.rollback() return {"res": 1} else: result = [] for feedback in feedbacks: result.append(feedback) return {"res": 0, "data": result} finally: mysql_session.close()
def receive_feedback(self, received_feedback): """ 收到用户发送的反馈 :var cookies和session中的qq,auth_session_id :param get_content:反馈内容 :return: """ get_content = received_feedback.get_content if DEVELOPMENG: self.set_secure_cookie("qq", str(2972822179)) mysql_session = make_mysql_session() qq = self.get_secure_cookie("qq") if qq is None: return {"res": 1} logger.info(str(qq) + " send feedback") try: new_feedback = FeedbackModal(getContent=get_content, getPersonQQ=qq, getTime=int(time.time()), subType=0) mysql_session.add(new_feedback) mysql_session.commit() feedback = mysql_session.query(FeedbackModal).filter( FeedbackModal.getContent == get_content).first() except Exception as e: #logger.error(e.message) logger.error(traceback.format_exc()) mysql_session.rollback() return {"res": 1} else: return {"res": 0, "data": feedback.make_response()} finally: mysql_session.close()
def query_weather_forecast(self): """ 查询天气预报 :return: """ print("forecast") mysql_session = make_mysql_session() start_day, end_day = WeatherHandler.get_day_range() try: forecasts = mysql_session \ .query(ForecastWeather) \ .order_by(desc(ForecastWeather.last_update)) \ .filter(ForecastWeather.date_.between(start_day, end_day)) \ .limit(3).all() except Exception as e: logger.error(e) logger.error(traceback.format_exc()) mysql_session.rollback() return {"res": 1} else: resp = [] for forecast in forecasts: resp.append(forecast.make_response()) return {"res": 0, "data": resp} finally: mysql_session.close()
def undo_feedback(self, feedback_id): """ 用户提出撤销反馈 :var cookies和session中的qq,auth_session_id :param feedback_id:反馈id :return: """ if DEVELOPMENG: self.set_secure_cookie("qq", str(2972822179)) mysql_session = make_mysql_session() qq = self.get_secure_cookie("qq") if qq is None: return {"res": 1} logger.info(str(qq) + " undo feedback") try: feedback = mysql_session.query(FeedbackModal).filter( FeedbackModal.id == feedback_id).first() mysql_session.delete(feedback) mysql_session.commit() except Exception as e: # logger.error(e.message) logger.error(traceback.format_exc()) mysql_session.rollback() return {"res": 1} else: return {"res": 0} finally: mysql_session.close()
def query_course_table(self): """ 用户查询课表,返回课表上的所有课程。 :return: """ if DEVELOPMENG: self.set_secure_cookie("qq", str(2972822179)) mysql_session = make_mysql_session() try: qq = self.get_secure_cookie("qq") if qq is None: return {"res": 1} feedbacks = mysql_session.query(FeedbackModal).filter( FeedbackModal.getPersonQQ == qq).all() result = [] for feedback in feedbacks: result.append({ "id": feedback.id, "getTime": feedback.getTime, "getContent": feedback.getContent, "getPersonQQ": feedback.getPersonQQ, "state": feedback.subType, "sendPersonQQ": feedback.sendPersonQQ, "sendContent": feedback.sendContent, "sendTime": feedback.sendTime }) return {"res": 0, "feedbacks": result} except Exception as e: logger.error(traceback.format_exc()) # logger.error(e.message) return {"res": 1}
def store(self, realtime, forecasts, suggestion): session = make_mysql_session() if not session.query(RealtimeWeather).filter( RealtimeWeather.last_update == realtime.last_update).all(): session.add(realtime) logger.info("GET {0}".format(realtime.make_response())) if not session.query(ForecastWeather).filter( ForecastWeather.last_update == forecasts[0].last_update).all(): for f in forecasts: session.add(f) logger.info("GET {0}".format(f.make_response())) if not session.query(LifeSuggestion).filter( LifeSuggestion.last_update == suggestion.last_update).all(): session.add(suggestion) logger.info("GET {0}".format(suggestion.make_response())) session.commit()
def query_realtime_weather(self): """ 查询实时天气 :return: """ print("realtime") mysql_session = make_mysql_session() try: weather = mysql_session.query(RealtimeWeather).order_by( desc(RealtimeWeather.last_update)).first() except Exception as e: # logger.error(e.message) logger.error(traceback.format_exc()) mysql_session.rollback() return {"res": 1} else: return {"res": 0, "data": weather.make_response()} finally: mysql_session.close()
def query_suggestion(self): """ 查询生活指数 :return: """ print("suggestion") mysql_session = make_mysql_session() try: suggestion = mysql_session \ .query(LifeSuggestion) \ .order_by(desc(LifeSuggestion.last_update)) \ .first() except Exception as e: # logger.error(e.message) logger.error(traceback.format_exc()) mysql_session.rollback() return {"res": 1} else: return {"res": 0, "data": suggestion.make_response()} finally: mysql_session.close()
def entry(self, token): """ :param token: :return: """ print ("redirect") mysql_session = make_mysql_session() try: qq_token = mysql_session.query(QQToken).filter(QQToken.token == token).first() if qq_token is None: return elif qq_token.cardnum != 0: self.set_secure_cookie("cardnum", qq_token.cardnum, 7) self.set_secure_cookie("token", token, 7) self.set_secure_cookie("qq", str(qq_token.qq), 7) self.redirect("http://localhost:8100") except Exception as e: # logger.error(e.message) logger.error(traceback.format_exc()) return
def CardStatus(self, cardNo): try: if len(cardNo) != 9: return error_response("e4001", self.info) mysql_session = make_mysql_session() queryans = mysql_session.query(StudentModal).filter( StudentModal.cardNo == cardNo).first() if not queryans: mysql_session.close() return error_response("e4041", self.info) response = { "code": 200, "message": "OK", "data": { "type": "int", "exist": 0 }, "pagination": { "page": 1, "pagesize": 1, "total": 1 }, "relationships": { "author": self.info["author"] }, "jsonapi": { "version": self.info["version"] } } mysql_session.close() return response except Exception as e: logger.error(traceback.format_exc()) # logger.error(e.message) return error_response("e5001", self.info)
def IsRegisted(self, qq): try: mysql_session = make_mysql_session() queryans = mysql_session.query(QQToken).filter( QQToken.qq == qq).first() if not queryans: response = { "code": 200, "mesage": "OK", "data": { "type": bool, "ans": False }, "relationships": { "author": "MLT" }, "jsonapi": { "version": "1.0" } } mysql_session.close() return response response = { "code": 200, "message": "OK", "data": { "type": "bool", "ans": True }, "pagination": { "page": 0, "pagesize": 0, "total": 0 }, "relationships": { "author": "MLT" }, "jsonapi": { "version": "1.0" } } mysql_session.close() return response except Exception as e: logger.error(traceback.format_exc()) # logger.error(e.message) response = { "code": 500, "message": "Internal Server Error", "errors": { "code": 5001, "message": "MySQL Server Error" }, "relationships": { "author": "MLT" }, "jsonapi": { "version": "1.0" } } return response