Ejemplo n.º 1
0
class CityUtil:
    mDBUtil = DBUtil()
    mHttpUtil = HttpUtil()

    def init_city_list(self):
        mCityCount = self.mDBUtil.query_to_city_total_count()
        print mCityCount
        if mCityCount <= 0:
            self.save_city_list()

    def save_city_list(self):
        mHttpCityList = self.mHttpUtil.get_city_list()

        mParserCityHandler = ParserCityHandler()
        xml.sax.parseString(mHttpCityList.encode("utf-8"), mParserCityHandler)

        for mCityBean in mParserCityHandler.mCityBeanList:
            # print "zxl--->" + mCityBean.mCityName + "--->" + mCityBean.mCityPinYing
            self.mDBUtil.insert_to_city(mCityBean)
        # print "zxl--->insert city finish"

    def query_city_by_city_name(self, city_name):
        return self.mDBUtil.query_to_city_by_city_name(city_name)

    def query_all_city(self):
        return self.mDBUtil.query_all_city()
Ejemplo n.º 2
0
        elif self.tag == "MsgType":
            self.wx_msg["MsgType"] = content
        elif self.tag == "Content":
            self.wx_msg["Content"] = content
        elif self.tag == "MsgId":
            self.wx_msg["MsgId"] = content

    def endElement(self, tag):
        self.tag = ""
        # mPrintUtil.print_to_file("characters-----------end")


result = {}
mPrintUtil = PrintUtil()
mParserUtil = ParserUtil()
mHttpUtil = HttpUtil()
mCityUtil = CityUtil()

if __name__ == "__main__":

    form = cgi.FieldStorage()

    if form.list is None:
        mPrintUtil.print_to_file("form.list is none")
    else:
        echostr = form.getvalue("echostr")
        if echostr is None:
            mPrintUtil.print_to_file("echostr is none")
        else:
            mPrintUtil.print_to_file(echostr)
            print "Content-type:text/html;charset=UTF-8"
Ejemplo n.º 3
0
    # fo.write(city_name)
    # fo.write("\n")
    # fo.close()

    # test = "<span>-33</span><em>"
    # pattern = re.compile("<span>(-?\d+\.?\d*)</span><em>")
    # print re.findall(pattern, test)

    if city_name is None:
        result["code"] = -1
        result["desc"] = "参数错误"
    else:

        result["city_name"] = city_name

        mHttpUtil = HttpUtil()
        mCityUtil = CityUtil()
        mParserUtil = ParserUtil()
        mCityUtil.init_city_list()
        mCityResult = mCityUtil.query_city_by_city_name(city_name)

        # print mCityResult

        if len(mCityResult) > 0:

            print time.asctime(time.localtime(time.time()))
            driver = mHttpUtil.get_today_weather_from_zh_tian_qi(
                mCityResult[0]["city_code"])

            try:
                weather_page_content = driver.page_source
Ejemplo n.º 4
0
# print "__name__ = " + __name__
# print "</br>"

if __name__ == "__main__":

    #%e4%b8%8a%e6%b5%b7
    form = cgi.FieldStorage()
    city_name = form.getvalue("city").decode("utf-8")

    weather_content = ""
    #http://www.weather.com.cn/data/cityinfo/101010100.html
    if city_name is None:
        result["code"] = -1
        result["desc"] = "参数错误"
    else:
        mHttpUtil = HttpUtil()
        mCityUtil = CityUtil()
        mCityUtil.init_city_list()
        mCityResult = mCityUtil.query_city_by_city_name(city_name)

        if len(mCityResult) > 0:
            weather_py_response = mHttpUtil.get_weather_content_by_city_py(
                mCityResult[0]["city_py"])
            pattern = re.compile(
                u"""<div class="left">.*?<span><b>(.*?)</b>(\d+).*?~.*?(\d+)℃</span>.*?</dd>.*?<dd class="shidu"><b>(.*?)%</b><b>(.*?)</b><b>(.*?)</b></dd>.*?<dd class="kongqi" ><h5.*?>(.*?)</h5><h6>PM.*?</div>""",
                re.S)
            parser_resutl = re.findall(pattern, weather_py_response)
            if len(parser_resutl) > 0:

                weather_content = city_name + \
                                  "今天" + parser_resutl[0][0].decode("utf-8") + "," + \
Ejemplo n.º 5
0
    form = cgi.FieldStorage()

    param = form.getvalue("param").decode("utf-8")

    # param = "method=baidu.ting.billboard.billList&type=1&size=1&offset=0"
    # param = "method=baidu.ting.search.catalogSug&query=一次就好"
    # param = "method=baidu.ting.song.play&songid=74107430"

    print "music============test9--->%s" % param

    fo = open("foo.txt", "a+")
    fo.write("music============test9--->%s" % param)
    fo.write("\n")
    fo.close()

    mHttpUtil = HttpUtil()

    info = mHttpUtil.get_music_info(param)

    print info

    result["code"] = 0
    result["desc"] = "success"
    result["param"] = param
    result["result"] = json.loads(info, "utf-8")

    # fo = open("foo.txt", "a+")
    # fo.write(json.dumps(result, encoding="utf-8", ensure_ascii=False))
    # fo.write("\n")
    # fo.close()
Ejemplo n.º 6
0
import json

from com_zxl_common.HttpUtil import *
from com_zxl_common.ParseUtil import *

SEX_MAN = 0
SEX_FEMALE = 1

reload(sys)
sys.setdefaultencoding("utf8")

result = {}

if __name__ == "__main__":

    mHttpUtil = HttpUtil()
    mParseUtil = ParseUtil()

    form = cgi.FieldStorage()
    author_id = form.getvalue("author_id")
    # author_id = "120535270"
    if author_id is None:
        result["code"] = -1
        result["desc"] = "param error"
    else:
        qsbk_detail = mHttpUtil.get_qsbk_detail(author_id)
        # print "qsbk_detail--->" + qsbk_detail

        if qsbk_detail:

            qsbk_detail_parse_result = mParseUtil.parse_qsbk_detal(qsbk_detail)
Ejemplo n.º 7
0
import json

from com_zxl_common.HttpUtil import *
from com_zxl_common.ParseUtil import *

SEX_MAN = 0
SEX_FEMALE = 1

reload(sys)
sys.setdefaultencoding("utf8")

result = {}

if __name__ == "__main__":

    mHttpUtil = HttpUtil()
    mParseUtil = ParseUtil()

    form = cgi.FieldStorage()
    page = form.getvalue("page")
    # page = 1z
    if page is None:
        result["code"] = -1
        result["desc"] = "param error"
    else:
        qsbk_list = mHttpUtil.get_qsbk_list_by_page(page)
        # print "qsbk_list--->" + qsbk_list

        if qsbk_list:
            qsbk_element_list = mParseUtil.parse_qsbk_list(qsbk_list)
            mQsbkParseEleements = []
Ejemplo n.º 8
0
import cgi
import os, sys, json
import time
from com_zxl_common.CityUtil import *
from com_zxl_common.HttpUtil import *
from com_zxl_common.ParserUtil import *
from com_zxl_common.XPathParserUtil import *

reload(sys)
sys.setdefaultencoding('utf-8')

result = {}

if __name__ == "__main__":

    mHttpUtil = HttpUtil()
    mCityUtil = CityUtil()
    mParserUtil = ParserUtil()
    mXPathParserUtil = XPathParserUtil()

    try:

        mCityUtil.init_city_list()
        mCityListResult = mCityUtil.query_all_city()

        result["code"] = 0
        result["desc"] = "success"
        result["city_list"] = mCityListResult

    except BaseException, e:
        print e