Beispiel #1
0
def getnannies(nannysystem):
    nannysystem = escape(nannysystem)
    db = data.storage()
    with db:
        ret = [n for n in db._CONN.execute('select %s from nannies where nannysystem_no = ?' % ",".join(db._NANNIES_COL[1:]), (nannysystem, ))]
#     print request.args['a'], type(request.args['a'])
#     print request.args['b'], type(request.args['b'])
    return jsonpify(ret)
Beispiel #2
0
def showtable():
    db = data.storage()
    with db:
        districts = db.execute('select * from districts')
        for d in districts:
            print '<ul><li>%s</li>' % d[0]
            for ns in db.execute('select * from nannysystems where district_no = "%s"' % d[1]):
                print '<ul><li>%s</li><ul>' % ns[1]
                for n in db.execute('select * from nannies where nannysystem_no = "%s" limit 10' % ns[2]):
                    print u'<li>姓名:%s,登記證編號:%s,已收托幼兒數:%s</li>' % (n[2], n[3], n[13])
                print '</ul></ul>'
            print '</ul>'
Beispiel #3
0
def showjson():
    db = data.storage()
    with db:
        districts = [i for i in db.execute('select * from districts')]
        js = json.dumps(districts, encoding="utf-8")
        print js
        nannysystems = {}
        for d in districts:
            tmp = [i for i in db.execute('select name, no from nannysystems where district_no = "%s"' % d[1])]
#             print tmp
            nannysystems[d[1]] = tmp
#         for k, v in nannysystems.iteritems():
#             print k, v
        print json.dumps(nannysystems, encoding="utf-8")
Beispiel #4
0
def getnannies(nannysystem):
    nannysystem = escape(nannysystem)
    db = data.storage()
    with db:
        ret = [
            n for n in db._CONN.execute(
                'select %s from nannies where nannysystem_no = ?' %
                ",".join(db._NANNIES_COL[1:]), (nannysystem, ))
        ]


#     print request.args['a'], type(request.args['a'])
#     print request.args['b'], type(request.args['b'])
    return jsonpify(ret)
Beispiel #5
0
def showtable():
    db = data.storage()
    with db:
        districts = db.execute('select * from districts')
        for d in districts:
            print '<ul><li>%s</li>' % d[0]
            for ns in db.execute(
                    'select * from nannysystems where district_no = "%s"' %
                    d[1]):
                print '<ul><li>%s</li><ul>' % ns[1]
                for n in db.execute(
                        'select * from nannies where nannysystem_no = "%s" limit 10'
                        % ns[2]):
                    print u'<li>姓名:%s,登記證編號:%s,已收托幼兒數:%s</li>' % (n[2], n[3],
                                                                  n[13])
                print '</ul></ul>'
            print '</ul>'
Beispiel #6
0
def showjson():
    db = data.storage()
    with db:
        districts = [i for i in db.execute('select * from districts')]
        js = json.dumps(districts, encoding="utf-8")
        print js
        nannysystems = {}
        for d in districts:
            tmp = [
                i for i in db.execute(
                    'select name, no from nannysystems where district_no = "%s"'
                    % d[1])
            ]
            #             print tmp
            nannysystems[d[1]] = tmp


#         for k, v in nannysystems.iteritems():
#             print k, v
        print json.dumps(nannysystems, encoding="utf-8")
Beispiel #7
0
    logger = logging.getLogger('NCrawler')
    logger.setLevel(logging.DEBUG)
    handler = logging.handlers.RotatingFileHandler(
            LOG_FILENAME, maxBytes=1048576, backupCount=5, encoding = "utf-8")
    formatter = logging.Formatter("%(asctime)s %(levelname)s-%(name)s %(message)s")
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    logger.info('Program started!')

    # Get all countries
    res = requests.post('http://cwisweb.sfaa.gov.tw/js_molde/address_json_db.jsp?keyNames=00000&p=0')
    # print res.status_code
    # print res.headers
    districts = json.loads(res.text.strip())[1:]
    if len(sys.argv) > 1:
        db = data.storage(sys.argv[1])
    else:
        db = data.storage()
    with db:
        if _INIT_DB:
            db.initialize()
        db.insert_districts(districts)
    count4 = 2

    # Foreach district
    for district in districts:
        print district['name'], district['no']
    
        # Get administrative district
#         print '   ------'
#         res = requests.post('http://cwisweb.sfaa.gov.tw/js_molde/address_json_db.jsp?keyNames=%s&p=1' % district['no'])
Beispiel #8
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

import data
from bs4 import BeautifulSoup

if __name__ == "__main__":
    with open('../OtherDatas/LandSection-20140502.xml', encoding="utf-8") as f:
        dataxml = f.read()
    soup = BeautifulSoup(dataxml, "html.parser")
    print('file loaded')
    with data.storage() as db:
        db.initialize()
#     sys.exit(0)
        count = 0
        for i in soup.findAll('item'):
            city = i.find('city').text.strip()
            office = i.find('office').text.strip()
            area = i.find('area').text.strip()
            section = i.find('section').text.strip()
            ssection = i.find('ssection').text.strip()
            code = i.find('code').text.strip()
            comment = i.find('comment').text.strip()
            row = [city, office, area, section, ssection, code, comment]
            db._CONN.execute("INSERT INTO landnames (city, office, area, section, ssection, code, comment) VALUES (?,?,?,?,?,?,?)",
                             (city, office, area, section, ssection, code, comment,) )
            count += 1
            if count & 1023 == 0:
                print(count)
        db._CONN.commit()