Exemple #1
0
def get_site(staging=False):
    if 'site' in web.ctx:
        return web.ctx.site
    rc = read_rc()

    param = dict((k, rc['staging_' + k if staging else k]) for k in ('db', 'user', 'pw', 'host'))
    print(param)
    param['dbn'] = 'postgres'

    infogami.config.db_parameters = param
    infogami.config.db_printing = False

    ib = get_infobase(rc)
    web.ctx.site = ib.get('openlibrary.org')
    cache.loadhook()
    return web.ctx.site
Exemple #2
0
def get_site(staging=False):
    if 'site' in web.ctx:
        return web.ctx.site
    rc = read_rc()

    param = dict((k, rc['staging_' + k if staging else k])
                 for k in ('db', 'user', 'pw', 'host'))
    print(param)
    param['dbn'] = 'postgres'

    infogami.config.db_parameters = param
    infogami.config.db_printing = False

    ib = get_infobase(rc)
    web.ctx.site = ib.get('openlibrary.org')
    cache.loadhook()
    return web.ctx.site
Exemple #3
0
        r.insert(0, c)
    return ''.join(r)

def count_books():
    rows = list(web.query("select count(*) as num from thing where type=52"))
    return rows[0].num

def count_fulltext():
    rows = list(web.query("select count(*) as num from edition_str where key_id=40"))
    return commify(rows[0].num)

def get_macro():
    rows = list(web.query("select data from data, thing where thing_id=thing.id and key='/macros/BookCount' and revision=latest_revision"))
    return cjson.decode(rows[0].data)['macro']['value']

rc = read_rc()
web.config.db_parameters = dict(dbn='postgres', db=rc['db'], user=rc['user'], pw=rc['pw'], host=rc['host'])
web.config.db_printing = False
web.ctx.ip = '127.0.0.1'
web.load()

book_count = count_books()
open('/home/edward/book_count', 'a').write("%d %d\n" % (time(), book_count))

infogami = Infogami(rc['infogami'])
infogami.login('edward', rc['edward'])

macro = get_macro()
re_books = re.compile(r'books = "<strong>[\d,]+</strong>"')
books = commify(book_count)
macro = re_books.sub('books = "<strong>' + books + '</strong>"', macro)
Exemple #4
0
def count_fulltext():
    rows = list(
        web.query("select count(*) as num from edition_str where key_id=40"))
    return commify(rows[0].num)


def get_macro():
    rows = list(
        web.query(
            "select data from data, thing where thing_id=thing.id and key='/macros/BookCount' and revision=latest_revision"
        ))
    return cjson.decode(rows[0].data)['macro']['value']


rc = read_rc()
web.config.db_parameters = dict(dbn='postgres',
                                db=rc['db'],
                                user=rc['user'],
                                pw=rc['pw'],
                                host=rc['host'])
web.config.db_printing = False
web.ctx.ip = '127.0.0.1'
web.load()

book_count = count_books()
open('/home/edward/book_count', 'a').write("%d %d\n" % (time(), book_count))

infogami = Infogami(rc['infogami'])
infogami.login('edward', rc['edward'])