def download_new(pages=50): """ Download newest 50 pages to update the data base. :param pages: :return: """ from mysql_database import connect, insert_link, insert_reply conn = connect() stop = False import json for i in range(1, pages): ids, links = get_page1(str(i)) if stop: break import sys sys.stderr.write(str(i) + "\n") ids, links = get_page1(str(i)) for id in ids: reply = get_yasuo(id) link = get_link(id) id, sql, data = parseReply2sql(json.loads(reply)) rst = insert_reply(conn, id, sql) id, sql, data = parseLink2sql(json.loads(link)) if id is not None: insert_link(conn, id, sql) conn.close()
def fileLink2sql(): """ :return: """ import json from mysql_database import connect, insert_link conn = connect() with open("links.json") as LINKS, open("links.sql", "w") as SQL: for line in LINKS: id, sql = parseLink2sql(json.loads(line)) if id: insert_link(conn, id, sql) conn.close()