Exemple #1
0
def random_person():
    c = db.cursor()
    c.execute("SELECT id FROM people ORDER BY id DESC LIMIT 1")
    mid, = c.fetchone()
    c.execute("SELECT name,pic_url FROM people WHERE id > %d LIMIT 1" % \
              (random.randint(1,mid),))
    person = c.fetchone()
    return person
Exemple #2
0
def random_word(part='NN'):
    c = db.cursor()
    c.execute("SELECT id FROM words WHERE part='%s' ORDER BY id DESC LIMIT 1" % part)
    mid, = c.fetchone()
    c.execute("SELECT word FROM words WHERE part='%s' and id >= %d LIMIT 1" % \
              (part, random.randint(1, mid)))
    word, = c.fetchone()
    return word