Beispiel #1
0
    def __init__(
            self,
            site: Site = None,
            db: DB = None,
            ia_db: DB = None,
    ):
        LegacyDataProvider.__init__(self)

        # cache for documents
        self.cache: Dict[str, dict] = {}
        self.metadata_cache: Dict[str, Optional[dict]] = {}

        # cache for redirects
        self.redirect_cache: Dict[str, List[str]] = {}

        self.edition_keys_of_works_cache: Dict[str, List[str]] = {}

        import infogami
        from infogami.utils import delegate

        # web.ctx might not be defined at this time -_-
        self.get_site = lambda: site or web.ctx.site

        if not db:
            infogami._setup()
            delegate.fakeload()

            from openlibrary.solr.process_stats import get_db
            self.db: DB = get_db()
        else:
            self.db = db

        # self.ia_db = get_ia_db
        # Ignore mypy because it can't find ia_database for some reason :/
        self.ia_db: DB = ia_db or ia_database  # type: ignore
Beispiel #2
0
def connect_to_couch(config_file):
    "Connects to the couch databases"
    load_config(config_file)
    infogami._setup()

    f = open(config_file)
    config = yaml.load(f)
    f.close()
    admin_db = config["admin"]["counts_db"]
    return couchdb.Database(admin_db)
Beispiel #3
0
def connect_to_couch(config_file):
    "Connects to the couch databases"
    load_config(config_file)
    infogami._setup()

    f = open(config_file)
    config = yaml.load(f)
    f.close()
    admin_db = config["admin"]["counts_db"]
    return couchdb.Database(admin_db)
Beispiel #4
0
def setup_ol():
    infogami.config.db_printing = False

    infogami.config.db_parameters = web.config.db_parameters = ol.config.db_parameters
    ol.config.infobase_server = None
    web.load()

    server._infobase = ol.get_infobase()
    ol.db = server._infobase.store.db
    ol.db.printing = False

    infogami._setup()
Beispiel #5
0
def setup_module(module):
    monkey_patch_browser()

    infogami.config.site = "infogami.org"
    infogami.config.db_parameters = web.config.db_parameters = db_parameters

    server.get_site("infogami.org")  # to initialize db

    module.db = server._infobase.store.db
    module.db.printing = False
    module.t = module.db.transaction()

    infogami._setup()
Beispiel #6
0
def setup_module(module):
    monkey_patch_browser()

    infogami.config.site = "infogami.org"
    infogami.config.db_parameters = web.config.db_parameters = db_parameters

    server.get_site("infogami.org") # to initialize db

    module.db = server._infobase.store.db
    module.db.printing = False
    module.t = db.transaction()

    infogami._setup()
Beispiel #7
0
    def load_infogami(config_file):
        import web
        import infogami
        from infogami import config
        from infogami.utils import delegate

        config.plugin_path += ['openlibrary.plugins']
        config.site = "openlibrary.org"
        
        infogami.load_config(config_file)
        setup_infobase_config(config_file)

        infogami._setup()
        delegate.fakeload()
Beispiel #8
0
    def load_infogami(config_file):
        import web
        import infogami
        from infogami import config
        from infogami.utils import delegate

        config.plugin_path += ['openlibrary.plugins']
        config.site = "openlibrary.org"

        infogami.load_config(config_file)
        setup_infobase_config(config_file)

        infogami._setup()
        delegate.fakeload()
Beispiel #9
0
def main(config, start, end):
    """
    Get the unique visitors per day between the 2 dates (inclusive) and store them
    in the infogami database. Ignores errors
    :param datetime start:
    :param datetime end:
    :return:
    """
    load_config(config)  # loads config for psql db under the hood
    infogami._setup()

    current = start
    while current <= end:
        try:
            count = count_unique_ips_for_day(current)
            store_data(dict(visitors=count), current)
        except IndexError as e:
            print(e.message)
        current += timedelta(days=1)
Beispiel #10
0
def main(start, end):
    """
    Get the unique visitors per day between the 2 dates (inclusive) and store them
    in the infogami database. Ignores errors
    :param datetime start:
    :param datetime end:
    :return:
    """
    infogami._setup()

    current = start
    while current <= end:
        print current
        try:
            count = count_unique_ips_for_day(current)
            store_data(dict(visitors=count), current)
        except IndexError, e:
            print("           " + e.message)
        current += timedelta(days=1)
Beispiel #11
0
def main(config, start, end):
    """
    Get the unique visitors per day between the 2 dates (inclusive) and store them
    in the infogami database. Ignores errors
    :param datetime start:
    :param datetime end:
    :return:
    """
    load_config(config)  # loads config for psql db under the hood
    infogami._setup()

    current = start
    while current <= end:
        try:
            count = count_unique_ips_for_day(current)
            store_data(dict(visitors=count), current)
        except IndexError as e:
            print(e.message)
        current += timedelta(days=1)
Beispiel #12
0
def setup_ol_config(openlibrary_config_file):
    """Setup OL configuration.

    Required for storing counts in store.
    """
    import infogami
    from infogami import config

    config.plugin_path += ['openlibrary.plugins']
    config.site = "openlibrary.org"

    infogami.load_config(openlibrary_config_file)
    infogami.config.infobase_parameters = dict(type="ol")

    if config.get("infobase_config_file"):
        dir = os.path.dirname(openlibrary_config_file)
        path = os.path.join(dir, config.infobase_config_file)
        config.infobase = yaml.safe_load(open(path).read())

    infogami._setup()
Beispiel #13
0
    def __init__(self):
        LegacyDataProvider.__init__(self)
        # cache for documents
        self.cache = {}
        self.metadata_cache = {}

        # cache for redirects
        self.redirect_cache = {}

        self.edition_keys_of_works_cache = {}

        import infogami
        from infogami.utils import delegate

        infogami._setup()
        delegate.fakeload()

        from openlibrary.solr.process_stats import get_ia_db, get_db
        self.db = get_db()
        self.ia_db = get_ia_db()
Beispiel #14
0
    def __init__(self):
        LegacyDataProvider.__init__(self)
        # cache for documents
        self.cache = {}
        self.metadata_cache = {}

        # cache for redirects
        self.redirect_cache = {}

        self.edition_keys_of_works_cache = {}

        import infogami
        from infogami.utils import delegate

        infogami._setup()
        delegate.fakeload()

        from openlibrary.solr.process_stats import get_ia_db, get_db
        self.db = get_db()
        self.ia_db = get_ia_db()
Beispiel #15
0
def setup_ol_config(openlibrary_config_file):
    """Setup OL configuration.

    Required for storing counts in store.
    """
    import infogami
    from infogami import config
    from infogami.utils import delegate

    config.plugin_path += ['openlibrary.plugins']
    config.site = "openlibrary.org"

    infogami.load_config(openlibrary_config_file)
    infogami.config.infobase_parameters = dict(type="ol")

    if config.get("infobase_config_file"):
        dir = os.path.dirname(openlibrary_config_file)
        path = os.path.join(dir, config.infobase_config_file)
        config.infobase = yaml.safe_load(open(path).read())

    infogami._setup()
Beispiel #16
0
    def __init__(
        self,
        site: Site = None,
        db: DB = None,
    ):
        """Test with
        import web; import infogami
        from openlibrary.config import load_config
        load_config('/openlibrary/config/openlibrary.yml')
        infogami._setup()
        from infogami import config
        """
        super().__init__()

        # cache for documents
        self.cache: dict[str, dict] = {}

        # cache for redirects
        self.redirect_cache: dict[str, list[str]] = {}

        self.edition_keys_of_works_cache: dict[str, list[str]] = {}

        import infogami
        from infogami.utils import delegate

        # web.ctx might not be defined at this time -_-
        self.get_site = lambda: site or web.ctx.site

        if not db:
            infogami._setup()
            delegate.fakeload()

            from openlibrary.solr.process_stats import get_db

            self.db: DB = get_db()
        else:
            self.db = db