def get_recent_activities(self): dt = datetime.datetime.now() begin_time = dt.strftime('%Y-%m-%d %H:%M:%S') dt2 = dt + datetime.timedelta(days=7) end_time = dt2.strftime('%Y-%m-%d %H:%M:%S') sql = """select id, title, activity_position,start_time,stop_time,cost_male, cost_female, max_participants,dead_line, organiser, organiser_phone from activities where start_time > '%s' and start_time < '%s' order by start_time""" % (begin_time, end_time) rows = self.db_manager.fetchall(sql) activities = [] for row in rows: activity = Activity() activity.id = row[0] activity.title = to_str(row[1]) activity.activity_position = to_str(row[2]) activity.start_time = row[3] activity.stop_time = row[4] activity.cost_male = row[5] activity.cost_female = row[6] activity.max_participants = row[7] activity.dead_line = row[8] activity.organiser = to_str(row[9]) activity.organiser_phone = to_str(row[10]) activities.append(activity) return activities
def get_user_qq_by_card(self, card): sql = """SELECT qq FROM qq_account WHERE card = '%s'""" % card qqs = [] results = self.db_manager.fetchall(sql) for row in results: qqs.append(to_str(row[0])) return qqs
def get_arrearage_user_message(self): sql = "SELECT card, balance FROM qq_account WHERE balance < 0" results = self.db_manager.fetchall(sql) if not results or len(results) == 0: return "没有欠费用户" content = "欠费用户:\\n" for row in results: content += "用户:%s, 欠费:%d\\n" % (to_str(row[0]), row[1]) return content
def get_user_by_card(self, card): sql = """SELECT uin, qq, nick_name, gender, balance, club_level, activity_times, accumulate_points, card, comments, other_comments FROM qq_account WHERE card = '%s'""" % card users = [] results = self.db_manager.fetchall(sql) for row in results: user = QQUser() user.uin = to_str(row[0]) user.qq = to_str(row[1]) user.nick_name = to_str(row[2]) user.gender = to_str(row[3]) user.balance = row[4] user.club_level = row[5] user.activity_times = row[6] user.accumulate_points = row[7] user.card = to_str(row[8]) user.comments = to_str(row[9]) user.other_comments = to_str(row[10]) users.append(user) return users
def get_bill_details(self, user_id): sql = """SELECT account_type, account_id, account_name, operator, operate_time, balance_change, balance, comments FROM account_bill_details WHERE account_id = '%s' ORDER BY operate_time DESC LIMIT 5""" % user_id rows = self.db_manager.fetchall(sql) bills = [] for row in rows: bill = BillDetails() bill.account_type = to_str(row[0]) bill.account_id = to_str(row[1]) bill.account_name = to_str(row[2]) bill.operator = to_str(row[3]) bill.operate_time = row[4] bill.balance_change = row[5] bill.balance = to_str(row[6]) bill.comments = to_str(row[7]) bills.append(bill) return bills
def get_weather_message2(): #response = requests.get("http://api.k780.com:88/?app=weather.today&weaid=101010100&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json") #response = requests.get("http://apistore.baidu.com/microservice/weather?cityid=101010100") response = requests.get( "http://wthrcdn.etouch.cn/WeatherApi?citykey=101010100") #response = requests.get("http://wthrcdn.etouch.cn/weather_mini?citykey=101010100") #response = requests.get("http://weatherapi.market.xiaomi.com/wtr-v2/weather?cityId=101010100") #print response.content message = "" root = ET.fromstring(response.content) city = root.find("city").text message += "城市:%s\\n" % to_str(city) current_temp = root.find("wendu").text message += "当前温度:%s\\n" % current_temp wind_force = root.find("fengli").text message += "风力: %s\\n" % to_str(wind_force) wind_direction = root.find("fengxiang").text message += "风向: %s\\n" % to_str(wind_direction) humidity = root.find("shidu").text message += "湿度:%s\\n" % to_str(humidity) forecast = root.find("forecast") today = forecast[0] temp_high = today.find("high").text temp_low = today.find("low").text message += "气温:%s, %s\\n" % (to_str(temp_low), to_str(temp_high)) #message += "最高气温:%s\n" % to_str(temp_high) day_type = today.find("day").find("type").text night_type = today.find("night").find("type").text message += "白天:%s, 晚间:%s\\n" % (to_str(day_type), to_str(night_type)) environment = root.find("environment") aqi = environment.find("aqi").text pm25 = environment.find("pm25").text quality = environment.find("quality").text message += "空气指数:%s, PM2.5:%s\\n空气质量:%s\\n" % ( to_str(aqi), to_str(pm25), to_str(quality)) updatetime = root.find("updatetime").text message += "更新时间:%s\\n" % updatetime return message
def get_weather_message(): try: response = requests.get( "http://api.map.baidu.com/telematics/v3/weather?location=北京&output=json&ak=7lWN7A96VaYBaCeAxQxsWZhe" ) data = json.loads(response.text, encoding='utf-8') results = data["results"][0] city = results["currentCity"] message = "" message += "城市:%s\\n" % to_str(city) pm25 = results["pm25"] message += "空指:%s\\n" % to_str(pm25) today = results["weather_data"][0] message += "%s %s %s %s\\n" % (to_str( today["date"]), to_str(today["weather"]), to_str( today["wind"]), to_str(today["temperature"])) tomorrow = results["weather_data"][1] message += "%s %s %s %s\\n" % ( to_str(tomorrow["date"]), to_str(tomorrow["weather"]), to_str(tomorrow["wind"]), to_str(tomorrow["temperature"])) indexes = results["index"] for index in indexes: title = to_str(index["title"]) if title == "穿衣": message += "穿衣指数:%s\\n" % to_str(index["des"]) elif title == "洗车": message += "洗车指数:%s\\n" % to_str(index["des"]) elif title == "运动": message += "运动指数:%s\\n" % to_str(index["des"]) except: logging.exception("get weather info failed") return "获取天气信息失败" return message