def writePoemForTask(dbconfig, task):
    page_id = task["page_id"]
    poem_id = task["poem_id"]
    wikibard.poemForPageID(page_id,
                           'elizabethan',
                           dbconfig,
                           multi=True,
                           callback=stanzaWrite,
                           user_info=(poem_id, dbconfig))
    tasks.markTaskCompleted(dbconfig, task)
示例#2
0
def cachePoemForPageID(pageID):
    import server.dbconnect as dbconnect

    ## Create the row for the cached posStringForPoemLines
    write_conn = mysql.connector.connect(user="******", password="******", host="localhost", database="cached_poems")
    cursor = write_conn.cursor()
    query = """INSERT INTO cached_poems (page_id) VALUES (%s);"""
    values = (pageID,)
    cursor.execute(query, values)
    cursor.execute("""COMMIT;""");
    query = """SELECT LAST_INSERT_ID();"""
    cursor.execute(query)
    res = cursor.fetchall()
    poem_id = res[0][0]

    ## Write the poem
    dbconfig = dbconnect.MySQLDatabaseConnection.dbconfigForName('local')
    poem = poemForPageID(pageID, 'elizabethan', dbconfig)
    line_ids = [line['id'] for line in poem]

    ## Store the poem
    query = (
        """UPDATE cached_poems SET"""
        """ line_0=%s, line_1=%s, line_2=%s, line_3=%s,"""
        """ line_4=%s, line_5=%s, line_6=%s, line_7=%s,"""
        """ line_8=%s, line_9=%s, line_10=%s, line_11=%s,"""
        """ line_12=%s, line_13=%s, complete=1"""
        """ WHERE id=%s;"""
    )
    values = tuple(line_ids + [poem_id])
    cursor.execute(query, values)
    cursor.execute("""COMMIT;""");
    write_conn.close()
def writePoem(dbconfig, page_id, poem_id, remoteconfig):
    ## Write the poem
    poem = wikibard.poemForPageID(page_id, 'elizabethan', dbconfig)
    if None in poem:
        print "Error printing poem"
        return
    print(poem)
    line_ids = [line['id'] for line in poem]

    ## Store the poem
    conn = mysql.connector.connect(user=remoteconfig['user'],
                                    password=remoteconfig['password'],
                                    host=remoteconfig['host'],
                                    database=remoteconfig['database'])
    cursor = conn.cursor()
    query = (
        """UPDATE cached_poems SET"""
        """ line_0=%s, line_1=%s, line_2=%s, line_3=%s,"""
        """ line_4=%s, line_5=%s, line_6=%s, line_7=%s,"""
        """ line_8=%s, line_9=%s, line_10=%s, line_11=%s,"""
        """ line_12=%s, line_13=%s, complete=1"""
        """ WHERE id=%s;"""
    )
    values = tuple(line_ids + [poem_id])
    cursor.execute(query, values)
    cursor.execute("""COMMIT;""")
    conn.close()
示例#4
0
    outf = None
    if args.output:
        outf = codecs.open(args.output, 'w', 'utf-8')
    dbconfig = dbconnect.MySQLDatabaseConnection.dbconfigForName('local')
    dbconn = dbconnect.MySQLDatabaseConnection.connectionWithConfiguration('local')
    cursor = dbconn.connection.cursor()
    query = (
        """SELECT view_counts.id FROM view_counts INNER JOIN page_categories"""
        """ ON page_categories.id = view_counts.id WHERE view_counts.count < 202917"""
        """ ORDER BY view_counts.count DESC LIMIT %s;"""
        )
    values = (10000, )
    cursor.execute(query, values)
    res = cursor.fetchall()
    for i in range(args.count):
        random_id = random.sample(res, 1)[0][0]
        # random_id = 35607283
        poem = wikibard.poemForPageID(random_id, 'elizabethan', dbconfig, multi=True)
        lines = [dbreader.textForLineID(dbconn, p['id']) for p in poem]
        if outf:
            outf.write(dbreader.pageTitleForPageID(dbconn, random_id))
            outf.write(u'\n\n')
            for l in lines:
                outf.write(l)
                outf.write(u'\n')
            outf.write(u"\n\n\n")
    if outf:
        outf.close()
    t.end("poems")
    t.printTime()
示例#5
0
def writePoemForTask(dbconfig, task):
    page_id = task["page_id"]
    poem_id = task["poem_id"]
    wikibard.poemForPageID(page_id, 'elizabethan', dbconfig, multi=True, callback=stanzaWrite, user_info=(poem_id, dbconfig))
    tasks.markTaskCompleted(dbconfig, task)