def outJson(self):
    sql = ("SELECT * FROM\n            (SELECT * FROM %s WHERE online = 1 ORDER BY delay DESC) AS delay\n            GROUP BY LOWER(delay.title)\n            HAVING delay.title != '' and delay.title != 'CCTV-' AND delay.delay < 500\n            ORDER BY level ASC, length(title) ASC, title ASC\n            " % self.DB.table)
    result = self.DB.query(sql)
    fmtList = {'cctv': [], 'local': [], 'other': [], 'radio': []}
    for item in result:
        tmp = {'title': item[1], 'url': item[3]}
        if (item[4] == 1):
            fmtList['cctv'].append(tmp)
        elif (item[4] == 2):
            fmtList['local'].append(tmp)
        elif (item[4] == 3):
            fmtList['local'].append(tmp)
        elif (item[4] == 7):
            fmtList['radio'].append(tmp)
        else:
            fmtList['other'].append(tmp)
    jsonStr = json.dumps(fmtList)
    with open('tv.json', 'w') as f:
        f.write(jsonStr)
def outJson(self):
    sql = ("SELECT * FROM\n            (SELECT * FROM %s WHERE online = 1 ORDER BY delay DESC) AS delay\n            GROUP BY LOWER(delay.title)\n            HAVING delay.title !=  and delay.title != 'CCTV-' AND delay.delay < 500\n            ORDER BY level ASC, length(title) ASC, title ASC\n            " % self.DB.table)
    result = self.DB.query(sql)
    fmtList = {'cctv': [], 'local': [], 'other': [], 'radio': []}
    for item in result:
        tmp = {'title': item[1], 'url': item[3]}
        if (item[4] == 1):
            fmtList['cctv'].append(tmp)
        elif (item[4] == 2):
            fmtList['local'].append(tmp)
        elif (item[4] == 3):
            fmtList['local'].append(tmp)
        elif (item[4] == 7):
            fmtList['radio'].append(tmp)
        else:
            fmtList['other'].append(tmp)
    jsonStr = json.dumps(fmtList)
    with open('tv.json', 'w') as f:
        f.write(jsonStr)