Ejemplo n.º 1
0
 def POST(self):
     coords = xutils.get_argument("coords")
     if coords != "null":
         db = xtables.get_record_table()
         db.insert(type="location", key=xauth.get_current_name(), cdate=xutils.format_date(), 
             ctime=xutils.format_datetime(), value=coords)
     return "{}"
Ejemplo n.º 2
0
def save_login_info(name, value):
    db = xtables.get_record_table()
    message = "%s-%s" % (get_real_ip(), value)
    if name != "":
        db.insert(type="login", key=name, value=message, 
            ctime = xutils.format_datetime(), 
            cdate = xutils.format_date())
Ejemplo n.º 3
0
def save_ip(real_ip):
    if real_ip is not None:
        # 处理X-Forwarded-For
        real_ip = real_ip.split(",")[0]
        # 跳过内网
        # A类和C类
        if real_ip.startswith("10.") or real_ip.startswith("192.168") or real_ip == "127.0.0.1":
            return
        db = xtables.get_record_table()
        record = db.select_one(where=dict(type="ip", key=real_ip, cdate=xutils.format_date()))
        if record is None:
            db.insert(type="ip", key=real_ip, cdate=xutils.format_date(), 
                ctime=xutils.format_datetime(), value="1")
        else:
            db.update(value=int(record.value)+1, where=dict(id=record.id))
Ejemplo n.º 4
0
    def GET(self):
        city_code = xutils.get_argument("city_code", "101020100")
        city_name = xutils.get_argument("city_name", "上海")
        city_name = xutils.u(city_name)

        message = None

        db = xtables.get_record_table()
        record = db.select_one(where="type='weather' AND DATE(ctime)=$date_str AND key=$key", 
            vars=dict(date_str=xutils.format_date(), key=city_name))
        if record is not None:
            message = record.value
        else:
            url = "http://www.weather.com.cn/weather1d/%s.shtml" % city_code
            html = six.moves.urllib.request.urlopen(url).read()
            if html == b"<!-- empty -->":
                return dict(code="fail", message=u("city_code错误"))
            soup = BeautifulSoup(html, "html.parser")
            elements = soup.find_all(id="hidden_title")
            # print(elements)
            # print(len(html))
            # return html
            if len(elements) > 0:
                weather = elements[0]
                message = weather.attrs["value"]
                message = message.replace("/", u("至"))
                db.insert(ctime=xutils.format_datetime(), 
                    cdate=xutils.format_date(),
                    type="weather",
                    key=city_name,
                    value=message
                )

        if message is not None:
            message = u(message)
            if not xconfig.is_mute():
                xutils.say("%s %s" % (city_name, message))
            # six.print_(type(message), message)
            return dict(code="success", data=message)
        else:
            return dict(code="fail", message="结果为空")