def parse_hko(pageurl):
    ''' parse lunar calendar from hk Obs
    Args: pageurl
    Return:
          a string contains all posts'''

    print('grabbing and parsing %s' % pageurl)
    with urllib.request.urlopen(pageurl) as f:
        html = f.read()
        lines = html.decode('utf-8').split('\n')

    sql_nojq = ('insert or replace into ical (date,lunardate) '
                'values(?,?) ')
    sql_jq = ('insert or replace into ical (date,lunardate,jieqi) '
              'values(?,?,?) ')
    conn = sqlite3.connect(DB_FILE)
    db = conn.cursor()
    for line in lines:
        m = RE_CAL.match(line)
        if m:
            fds = line.split()
            # add leading zero to month and day
            if len(m.group(2)) == 1:
                str_m = '0%s' % m.group(2)
            else:
                str_m = m.group(2)
            if len(m.group(3)) == 1:
                str_d = '0%s' % m.group(3)
            else:
                str_d = m.group(3)

            dt = '%s-%s-%s' % (m.group(1), str_m, str_d)
            if len(fds) > 3:  # last field is jieqi
                db.execute(sql_jq, (dt, fds[1], fds[3]))
            else:
                db.execute(sql_nojq, (dt, fds[1]))
    conn.commit()
 parse lunar calendar from hk Obs
    Args: pageurl
    Return:
          a string contains all posts
lunar_ical.py