id int64 0 458k | file_name stringlengths 4 119 | file_path stringlengths 14 227 | content stringlengths 24 9.96M | size int64 24 9.96M | language stringclasses 1
value | extension stringclasses 14
values | total_lines int64 1 219k | avg_line_length float64 2.52 4.63M | max_line_length int64 5 9.91M | alphanum_fraction float64 0 1 | repo_name stringlengths 7 101 | repo_stars int64 100 139k | repo_forks int64 0 26.4k | repo_open_issues int64 0 2.27k | repo_license stringclasses 12
values | repo_extraction_date stringclasses 433
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
400 | code.py | internetarchive_openlibrary/openlibrary/plugins/importapi/code.py | """Open Library Import API
"""
from typing import Any
from infogami.plugins.api.code import add_hook
from infogami.infobase.client import ClientException
from openlibrary.catalog.utils import get_non_isbn_asin
from openlibrary.plugins.openlibrary.code import can_write
from openlibrary.catalog.marc.marc_binary import ... | 28,010 | Python | .py | 672 | 30.941964 | 122 | 0.574285 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
401 | metaxml_to_json.py | internetarchive_openlibrary/openlibrary/plugins/importapi/metaxml_to_json.py | #!/usr/bin/env python
"""
This example uses the import_edition_builder class to convert
an IA meta.xml into a json object that the Import API can consume.
usage:
> python metaxml_to_json.py romanceonthreele00hafnrich_meta.xml
{
"publishers": ["New York : Bloomsbury"],
"description": "Includes bibliographical ... | 2,868 | Python | .py | 84 | 27.071429 | 93 | 0.604634 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
402 | import_opds.py | internetarchive_openlibrary/openlibrary/plugins/importapi/import_opds.py | """
OL Import API OPDS parser
"""
from openlibrary.plugins.importapi import import_edition_builder
def parse_string(e, key):
return (key, e.text)
def parse_author(e, key):
name = e.find('{http://www.w3.org/2005/Atom}name')
return (key, name.text)
def parse_category(e, key):
return (key, e.get('la... | 2,196 | Python | .py | 53 | 35.54717 | 78 | 0.62453 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
403 | import_edition_builder.py | internetarchive_openlibrary/openlibrary/plugins/importapi/import_edition_builder.py | """
Create a edition dict that can be passed to catalog.add_book.load()
This class encapsulates the logic of creating edition dicts.
You can use add(key) to add a new key to the edition dict. This class
will take care of whether it should be a string or a list. For example,
you can use add('subject') to add an entry ... | 5,236 | Python | .py | 137 | 30.708029 | 82 | 0.578202 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
404 | import_validator.py | internetarchive_openlibrary/openlibrary/plugins/importapi/import_validator.py | from typing import Annotated, Any, Final, TypeVar
from annotated_types import MinLen
from pydantic import BaseModel, ValidationError, model_validator
T = TypeVar("T")
NonEmptyList = Annotated[list[T], MinLen(1)]
NonEmptyStr = Annotated[str, MinLen(1)]
STRONG_IDENTIFIERS: Final = {"isbn_10", "isbn_13", "lccn"}
cla... | 2,426 | Python | .py | 60 | 33.216667 | 98 | 0.68475 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
405 | test_import_edition_builder.py | internetarchive_openlibrary/openlibrary/plugins/importapi/tests/test_import_edition_builder.py | import pytest
from openlibrary.plugins.importapi.import_edition_builder import import_edition_builder
import_examples = [
{
'edition_name': '3rd ed.',
'pagination': 'xii, 444 p.',
'title': 'A course of pure mathematics',
'publishers': ['At the University Press'],
'number_of_... | 2,923 | Python | .py | 84 | 25.285714 | 87 | 0.510931 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
406 | test_import_validator.py | internetarchive_openlibrary/openlibrary/plugins/importapi/tests/test_import_validator.py | import pytest
from pydantic import ValidationError
from openlibrary.plugins.importapi.import_validator import import_validator, Author
def test_create_an_author_with_no_name():
Author(name="Valid Name")
with pytest.raises(ValidationError):
Author(name="")
valid_values = {
"title": "Beowulf",
... | 2,842 | Python | .py | 65 | 39.461538 | 83 | 0.721758 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
407 | test_code_ils.py | internetarchive_openlibrary/openlibrary/plugins/importapi/tests/test_code_ils.py | import datetime
from openlibrary.plugins.importapi import code
"""Tests for Koha ILS (Integrated Library System) code.
"""
class Test_ils_cover_upload:
def test_build_url(self):
build_url = code.ils_cover_upload().build_url
assert (
build_url("http://example.com/foo", status="ok")
... | 2,417 | Python | .py | 63 | 27.492063 | 78 | 0.500427 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
408 | test_code.py | internetarchive_openlibrary/openlibrary/plugins/importapi/tests/test_code.py | from .. import code
from openlibrary.catalog.add_book.tests.conftest import add_languages # noqa: F401
import web
import pytest
def test_get_ia_record(monkeypatch, mock_site, add_languages) -> None: # noqa F811
"""
Try to test every field that get_ia_record() reads.
"""
monkeypatch.setattr(web, "ctx... | 3,550 | Python | .py | 99 | 28.979798 | 85 | 0.594705 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
409 | autocomplete.py | internetarchive_openlibrary/openlibrary/plugins/worksearch/autocomplete.py | import itertools
import web
import json
from infogami.utils import delegate
from infogami.utils.view import safeint
from openlibrary.core.models import Thing
from openlibrary.plugins.upstream import utils
from openlibrary.plugins.worksearch.search import get_solr
from openlibrary.utils import (
find_olid_in_strin... | 4,619 | Python | .py | 124 | 29.451613 | 94 | 0.584081 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
410 | bulk_search.py | internetarchive_openlibrary/openlibrary/plugins/worksearch/bulk_search.py | import web
from infogami import config
from infogami.utils import delegate
from infogami.utils.view import public, safeint, render
class bulk_search(delegate.page):
path = "/search/bulk"
def GET(self):
return render['bulk_search/bulk_search']()
def setup():
pass
| 289 | Python | .py | 10 | 25.3 | 55 | 0.750916 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
411 | publishers.py | internetarchive_openlibrary/openlibrary/plugins/worksearch/publishers.py | """Publisher pages
"""
from infogami.utils import delegate, stats
from infogami.utils.view import render_template, safeint
import web
import logging
from . import subjects
from . import search
logger = logging.getLogger("openlibrary.worksearch")
class publishers(subjects.subjects):
path = '(/publishers/[^/]+)'... | 3,088 | Python | .py | 85 | 28.023529 | 108 | 0.60928 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
412 | search.py | internetarchive_openlibrary/openlibrary/plugins/worksearch/search.py | """Search utilities.
"""
from openlibrary.utils.solr import Solr
from infogami import config
_ACTIVE_SOLR: Solr | None = None
def get_solr():
global _ACTIVE_SOLR
if not _ACTIVE_SOLR:
base_url = config.plugin_worksearch.get('solr_base_url')
_ACTIVE_SOLR = Solr(base_url)
return _ACTIVE_SOL... | 322 | Python | .py | 11 | 25.363636 | 64 | 0.703583 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
413 | code.py | internetarchive_openlibrary/openlibrary/plugins/worksearch/code.py | from dataclasses import dataclass
import itertools
import time
import copy
import json
import logging
import re
from typing import Any, cast
from collections.abc import Iterable
from unicodedata import normalize
import requests
import web
from requests import Response
import urllib
from infogami import config
from inf... | 27,307 | Python | .py | 767 | 26.680574 | 88 | 0.568853 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
414 | languages.py | internetarchive_openlibrary/openlibrary/plugins/worksearch/languages.py | """Language pages
"""
from infogami.plugins.api.code import jsonapi
from infogami.utils import delegate, stats
from infogami.utils.view import render_template, safeint
import web
import json
import logging
from openlibrary.plugins.upstream.utils import get_language_name
from . import subjects
from . import search
... | 3,411 | Python | .py | 95 | 28.494737 | 108 | 0.622751 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
415 | subjects.py | internetarchive_openlibrary/openlibrary/plugins/worksearch/subjects.py | """Subject pages.
"""
from dataclasses import dataclass
from typing import Literal
import web
import json
import datetime
from infogami.plugins.api.code import jsonapi
from infogami.utils import delegate
from infogami.utils.view import render_template, safeint
from openlibrary.core.models import Subject
from openlib... | 14,574 | Python | .py | 408 | 24.735294 | 112 | 0.524745 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
416 | test_autocomplete.py | internetarchive_openlibrary/openlibrary/plugins/worksearch/tests/test_autocomplete.py | import json
from unittest.mock import patch
from openlibrary.plugins.worksearch.autocomplete import autocomplete, works_autocomplete
import web
from openlibrary.utils.solr import Solr
def test_autocomplete():
ac = autocomplete()
with (
patch('web.input') as mock_web_input,
patch('web.header')... | 3,951 | Python | .py | 102 | 26.882353 | 88 | 0.510672 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
417 | test_worksearch.py | internetarchive_openlibrary/openlibrary/plugins/worksearch/tests/test_worksearch.py | import web
from openlibrary.plugins.worksearch.code import (
process_facet,
get_doc,
)
def test_process_facet():
facets = [('false', 46), ('true', 2)]
assert list(process_facet('has_fulltext', facets)) == [
('true', 'yes', 2),
('false', 'no', 46),
]
def test_get_doc():
doc = ... | 2,300 | Python | .py | 70 | 20.828571 | 66 | 0.451482 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
418 | authors.py | internetarchive_openlibrary/openlibrary/plugins/worksearch/schemes/authors.py | from datetime import datetime
import logging
from collections.abc import Callable
from openlibrary.plugins.worksearch.schemes import SearchScheme
logger = logging.getLogger("openlibrary.worksearch")
class AuthorSearchScheme(SearchScheme):
universe = ['type:author']
all_fields = {
'key',
'nam... | 1,581 | Python | .py | 53 | 22.169811 | 74 | 0.538411 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
419 | works.py | internetarchive_openlibrary/openlibrary/plugins/worksearch/schemes/works.py | from copy import deepcopy
from datetime import datetime
import logging
import re
import sys
from typing import Any, cast
from collections.abc import Callable
import luqum.tree
import web
import infogami
from openlibrary.plugins.upstream.utils import convert_iso_to_marc
from openlibrary.plugins.worksearch.schemes impor... | 26,861 | Python | .py | 631 | 29.293185 | 110 | 0.518831 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
420 | editions.py | internetarchive_openlibrary/openlibrary/plugins/worksearch/schemes/editions.py | from datetime import datetime
import logging
from openlibrary.plugins.worksearch.schemes import SearchScheme
logger = logging.getLogger("openlibrary.worksearch")
# Kind of mostly a stub for now since you can't really search editions
# directly, but it's still useful for somethings (eg editions have a custom
# sort ... | 2,081 | Python | .py | 61 | 26.803279 | 86 | 0.594045 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
421 | __init__.py | internetarchive_openlibrary/openlibrary/plugins/worksearch/schemes/__init__.py | import logging
from collections.abc import Callable
import luqum.tree
from luqum.exceptions import ParseError
from openlibrary.solr.query_utils import (
escape_unknown_fields,
fully_escape_query,
luqum_parser,
)
logger = logging.getLogger("openlibrary.worksearch")
class SearchScheme:
# Set of querie... | 4,797 | Python | .py | 111 | 33.027027 | 86 | 0.586081 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
422 | subjects.py | internetarchive_openlibrary/openlibrary/plugins/worksearch/schemes/subjects.py | from datetime import datetime
import logging
from collections.abc import Callable
from openlibrary.plugins.worksearch.schemes import SearchScheme
logger = logging.getLogger("openlibrary.worksearch")
class SubjectSearchScheme(SearchScheme):
universe = ['type:subject']
all_fields = {
'key',
'n... | 1,300 | Python | .py | 43 | 23.162791 | 74 | 0.5623 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
423 | test_works.py | internetarchive_openlibrary/openlibrary/plugins/worksearch/schemes/tests/test_works.py | from unittest.mock import patch
import pytest
from openlibrary.plugins.worksearch.schemes.works import WorkSearchScheme
# {'Test name': ('query', fields[])}
QUERY_PARSER_TESTS = {
'No fields': ('query here', 'query here'),
'Misc': (
'title:(Holidays are Hell) authors:(Kim Harrison) OR authors:(Lynsay S... | 4,209 | Python | .py | 131 | 25.900763 | 105 | 0.591792 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
424 | code.py | internetarchive_openlibrary/openlibrary/plugins/books/code.py | """Open Library Books API
"""
import json
import re
import urllib
import web
from infogami.utils import delegate
from infogami.plugins.api.code import jsonapi
from openlibrary.plugins.books import dynlinks, readlinks
class books_json(delegate.page):
"""
Endpoint for mapping bib keys (e.g. ISBN, LCCN) to ce... | 3,137 | Python | .py | 74 | 34.837838 | 98 | 0.633553 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
425 | dynlinks.py | internetarchive_openlibrary/openlibrary/plugins/books/dynlinks.py | from typing import Any
import importlib
import json
import sys
from collections.abc import Hashable, Iterable, Mapping
import web
from openlibrary.core.models import Edition
from openlibrary.core.imports import ImportItem
from openlibrary.plugins.openlibrary.processors import urlsafe
from openlibrary.core import hel... | 17,850 | Python | .py | 438 | 31.244292 | 103 | 0.550546 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
426 | readlinks.py | internetarchive_openlibrary/openlibrary/plugins/books/readlinks.py | """'Read' api implementation. This is modeled after the HathiTrust
Bibliographic API, but also includes information about loans and other
editions of the same work that might be available.
"""
import sys
import re
import requests
import web
from openlibrary.core import ia
from openlibrary.core import helpers
from op... | 14,211 | Python | .py | 360 | 28.791667 | 97 | 0.537084 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
427 | test_dynlinks.py | internetarchive_openlibrary/openlibrary/plugins/books/tests/test_dynlinks.py | """Test suite for dynlinks.
Most of the tests here use 3 sets of data.
data0: This contains OL0A, OL0M and OL0W with each having just name/title.
data1: This contains OL1A, OL1M, OL1W with each having name/tile and interconnections.
data9: This contains OL9A, OL9M and OL9W with interconnections and almost all fields.... | 14,480 | Python | .py | 374 | 26.906417 | 96 | 0.48872 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
428 | test_readlinks.py | internetarchive_openlibrary/openlibrary/plugins/books/tests/test_readlinks.py | import pytest
import web
from openlibrary.plugins.books import readlinks
@pytest.mark.parametrize(
"collections,subjects,options,expected",
[
(['lendinglibrary'], ['Lending library'], {}, 'lendable'),
(['lendinglibrary'], ['Some other subject'], {}, 'restricted'),
(['inlibrary'], ['In... | 1,500 | Python | .py | 38 | 33.394737 | 88 | 0.628003 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
429 | test_doctests.py | internetarchive_openlibrary/openlibrary/plugins/books/tests/test_doctests.py | import doctest
import pytest
def find_doctests(modules):
finder = doctest.DocTestFinder()
for m in modules:
mod = __import__(m, None, None, ['x'])
yield from finder.find(mod, mod.__name__)
@pytest.mark.parametrize('test', find_doctests(["openlibrary.plugins.books.dynlinks"]))
def test_doctes... | 486 | Python | .py | 13 | 32.692308 | 87 | 0.690832 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
430 | code.py | internetarchive_openlibrary/openlibrary/plugins/inside/code.py | from time import time
import json
import web
from infogami.utils import delegate
from infogami.utils.view import render_template, safeint
from openlibrary.core.fulltext import fulltext_search
RESULTS_PER_PAGE = 20
class search_inside(delegate.page):
path = '/search/inside'
def GET(self):
search_s... | 1,291 | Python | .py | 35 | 29.514286 | 86 | 0.64257 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
431 | memory.py | internetarchive_openlibrary/openlibrary/plugins/admin/memory.py | """memory profiler
"""
import gc
import web
from collections import defaultdict
_mark = {}
_mark_ids = {}
class Storage(web.Storage):
pass
def mark():
"""Mark the current counts to show the difference."""
global _mark, _mark_ids
objects = get_objects()
d = defaultdict(set)
for obj in obje... | 1,529 | Python | .py | 57 | 21.22807 | 84 | 0.58 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
432 | mem.py | internetarchive_openlibrary/openlibrary/plugins/admin/mem.py | from infogami.utils import delegate
from infogami.utils.view import render, safeint
from openlibrary.plugins.admin import memory
import web
import gc
def render_template(name, *a, **kw):
return render[name](*a, **kw)
class Object:
def __init__(self, obj, name=None):
self.obj = obj
self.name ... | 3,393 | Python | .py | 97 | 25.268041 | 80 | 0.546793 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
433 | code.py | internetarchive_openlibrary/openlibrary/plugins/admin/code.py | """Plugin to provide admin interface.
"""
import os
from collections.abc import Iterable
import requests
import sys
import web
import subprocess
import datetime
import traceback
import logging
import json
from internetarchive.exceptions import ItemLocateError
from infogami import config
from infogami.utils import de... | 28,542 | Python | .py | 704 | 31.816761 | 105 | 0.603616 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
434 | graphs.py | internetarchive_openlibrary/openlibrary/plugins/admin/graphs.py | """Utilities for rendering Graphite graphs.
"""
import web
from infogami import config
import urllib
def get_graphite_base_url():
return config.get("graphite_base_url", "")
class GraphiteGraph:
"""Representation of Graphite graph.
Usage:
g = GraphiteGraph()
g.add("stats.timers.ol.pag... | 2,105 | Python | .py | 60 | 27.783333 | 134 | 0.601783 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
435 | services.py | internetarchive_openlibrary/openlibrary/plugins/admin/services.py | """
Contains stuff needed to list services and modules run by OpenLibrary
for the admin panel
"""
import re
import requests
from collections import defaultdict
from bs4 import BeautifulSoup
class Nagios:
def __init__(self, url):
try:
self.data = BeautifulSoup(requests.get(url).content, "lxml... | 2,177 | Python | .py | 61 | 27.42623 | 88 | 0.605226 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
436 | conftest.py | internetarchive_openlibrary/openlibrary/plugins/admin/tests/conftest.py | import pytest
@pytest.fixture
def serviceconfig(request):
import os
import yaml
root = os.path.dirname(__file__)
with open(os.path.join(root, "sample_services.yml")) as in_file:
return yaml.safe_load(in_file)
| 236 | Python | .py | 8 | 25.125 | 68 | 0.702222 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
437 | test_services.py | internetarchive_openlibrary/openlibrary/plugins/admin/tests/test_services.py | """
Tests for the services module used by the admin interface.
"""
def test_loader(serviceconfig):
"Make sure services are loaded"
from .. import services
services = services.load_all(serviceconfig, "http://nagios.url")
assert len(list(services)) == 2
s = sorted(services)
assert s[0] == "ol-w... | 594 | Python | .py | 15 | 35.466667 | 68 | 0.668403 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
438 | test_code.py | internetarchive_openlibrary/openlibrary/plugins/admin/tests/test_code.py | from typing import cast
from openlibrary.accounts.model import Account, OpenLibraryAccount
from openlibrary.plugins.admin.code import revert_all_user_edits
import web
from openlibrary.plugins.upstream.models import Changeset
def make_test_account(username: str) -> OpenLibraryAccount:
web.ctx.site.register(
... | 6,033 | Python | .py | 147 | 31.278912 | 82 | 0.580403 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
439 | models.py | internetarchive_openlibrary/openlibrary/plugins/upstream/models.py | import logging
import re
from functools import cached_property
import sys
import web
from collections import defaultdict
from isbnlib import canonical, mask, NotValidISBNError
from infogami import config
from infogami.infobase import client
from infogami.utils.view import safeint
from infogami.utils import stats
fr... | 33,567 | Python | .py | 821 | 30.677223 | 120 | 0.576141 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
440 | checkins.py | internetarchive_openlibrary/openlibrary/plugins/upstream/checkins.py | """Reading log check-ins handler and services.
"""
import json
import web
from datetime import datetime
from math import floor
from infogami.utils import delegate
from infogami.utils.view import public
from openlibrary.accounts import get_current_user
from openlibrary.app import render_template
from openlibrary.cor... | 8,086 | Python | .py | 210 | 29.77619 | 88 | 0.609481 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
441 | jsdef.py | internetarchive_openlibrary/openlibrary/plugins/upstream/jsdef.py | """Templetor extension to support javascript templates.
During AJAX development, there will be need to generate HTML and update
some part of the DOM. It it clumsy to do that in javascript. Even though
there are some javascript template engines, it often ends up in duplication
because of writing a Python template and a... | 7,243 | Python | .py | 207 | 28.120773 | 94 | 0.564176 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
442 | mybooks.py | internetarchive_openlibrary/openlibrary/plugins/upstream/mybooks.py | import json
import web
from web.template import TemplateResult
from typing import Final, Literal, cast, TYPE_CHECKING
from infogami import config
from infogami.utils import delegate
from infogami.utils.view import public, safeint, render
from openlibrary.i18n import gettext as _
from openlibrary import accounts
fro... | 22,798 | Python | .py | 536 | 31.733209 | 91 | 0.571203 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
443 | covers.py | internetarchive_openlibrary/openlibrary/plugins/upstream/covers.py | """Handle book cover/author photo upload.
"""
from logging import getLogger
import requests
import web
from io import BytesIO
from infogami.utils import delegate
from infogami.utils.view import safeint
from openlibrary import accounts
from openlibrary.plugins.upstream.models import Image
from openlibrary.plugins.ups... | 4,823 | Python | .py | 127 | 29.669291 | 88 | 0.599957 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
444 | code.py | internetarchive_openlibrary/openlibrary/plugins/upstream/code.py | """Upstream customizations."""
import datetime
import hashlib
import json
import os.path
import random
import web
from infogami import config
from infogami.core import code as core
from infogami.plugins.api.code import jsonapi, make_query
from infogami.plugins.api.code import request as infogami_request
from infoga... | 11,994 | Python | .py | 312 | 29.599359 | 91 | 0.60176 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
445 | borrow.py | internetarchive_openlibrary/openlibrary/plugins/upstream/borrow.py | """Handlers for borrowing books"""
import copy
import hashlib
import hmac
import json
import logging
import re
from typing import Literal
import requests
import time
from datetime import datetime
import web
from infogami import config
from infogami.utils import delegate
from infogami.utils.view import public, render... | 32,862 | Python | .py | 744 | 35.375 | 178 | 0.625729 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
446 | recentchanges.py | internetarchive_openlibrary/openlibrary/plugins/upstream/recentchanges.py | """New recentchanges implementation.
This should go into infogami.
"""
import web
import json
import yaml
from infogami.utils import delegate
from infogami.utils.view import public, render, render_template, safeint
from infogami.utils.view import add_flash_message # TODO: unused import?
from infogami.utils import f... | 5,717 | Python | .py | 149 | 29.308725 | 88 | 0.593405 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
447 | account.py | internetarchive_openlibrary/openlibrary/plugins/upstream/account.py | from datetime import datetime
import json
import logging
import re
import requests
from typing import Any, TYPE_CHECKING, Final
from collections.abc import Callable
from collections.abc import Iterable, Mapping
from math import ceil
import web
from infogami.utils import delegate
from infogami import config
from infog... | 48,653 | Python | .py | 1,098 | 33.925319 | 150 | 0.59531 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
448 | utils.py | internetarchive_openlibrary/openlibrary/plugins/upstream/utils.py | import functools
import os
from typing import Any, Protocol, TYPE_CHECKING, TypeVar
from collections.abc import Callable, Generator, Iterable, Iterator
import unicodedata
import web
import json
import babel
import babel.core
import babel.dates
from babel.lists import format_list
from collections import defaultdict
imp... | 48,570 | Python | .py | 1,381 | 27.876177 | 125 | 0.57675 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
449 | table_of_contents.py | internetarchive_openlibrary/openlibrary/plugins/upstream/table_of_contents.py | from dataclasses import dataclass
from functools import cached_property
import json
from typing import Required, TypeVar, TypedDict
from infogami.infobase.client import Nothing, Thing
from openlibrary.core.models import ThingReferenceDict
import web
@dataclass
class TableOfContents:
entries: list['TocEntry']
... | 5,351 | Python | .py | 157 | 24.923567 | 88 | 0.535943 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
450 | spamcheck.py | internetarchive_openlibrary/openlibrary/plugins/upstream/spamcheck.py | import re
from collections.abc import Iterable
import web
def get_spam_words() -> list[str]:
doc = web.ctx.site.store.get("spamwords") or {}
return doc.get("spamwords", [])
def get_spam_domains() -> list[str]:
doc = web.ctx.site.store.get("spamwords") or {}
return doc.get("domains", [])
def set_sp... | 1,810 | Python | .py | 46 | 33.608696 | 79 | 0.643757 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
451 | addtag.py | internetarchive_openlibrary/openlibrary/plugins/upstream/addtag.py | """Handlers for adding and editing tags."""
import web
from typing import NoReturn
from infogami.core.db import ValidationException
from infogami.utils.view import add_flash_message, public
from infogami.infobase.client import ClientException
from infogami.utils import delegate
from openlibrary.accounts import get_... | 4,715 | Python | .py | 121 | 29.636364 | 87 | 0.596753 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
452 | adapter.py | internetarchive_openlibrary/openlibrary/plugins/upstream/adapter.py | """Adapter to provide upstream URL structure over existing Open Library Infobase interface.
Upstream requires:
/user/.* -> /people/.*
/b/.* -> /books/.*
/a/.* -> /authors/.*
This adapter module is a filter that sits above an Infobase server and fakes the new URL structure.
"""
import json
import web
im... | 7,942 | Python | .py | 237 | 25.012658 | 99 | 0.531528 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
453 | merge_authors.py | internetarchive_openlibrary/openlibrary/plugins/upstream/merge_authors.py | """Merge authors.
"""
import re
import json
import web
from typing import Any
from infogami.infobase.client import ClientException
from infogami.utils import delegate
from infogami.utils.view import render_template, safeint
from openlibrary.accounts import get_current_user
from openlibrary.plugins.upstream.edits imp... | 13,033 | Python | .py | 304 | 33.118421 | 129 | 0.593661 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
454 | edits.py | internetarchive_openlibrary/openlibrary/plugins/upstream/edits.py | """Librarian Edits
"""
import json
import web
from openlibrary import accounts
from openlibrary.core.edits import CommunityEditsQueue, get_status_for_view
from infogami.utils import delegate
from infogami.utils.view import render_template
def response(status='ok', **kwargs):
return {'status': status, **kwargs}
... | 7,215 | Python | .py | 181 | 27.906077 | 87 | 0.559155 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
455 | addbook.py | internetarchive_openlibrary/openlibrary/plugins/upstream/addbook.py | """Handlers for adding and editing books."""
import io
import web
import json
import csv
import datetime
from typing import Literal, overload, NoReturn
from infogami import config
from infogami.core.db import ValidationException
from infogami.utils import delegate
from infogami.utils.view import safeint, add_flash_m... | 36,952 | Python | .py | 888 | 30.702703 | 104 | 0.560469 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
456 | data.py | internetarchive_openlibrary/openlibrary/plugins/upstream/data.py | """Code for handling /data/*.txt.gz URLs.
"""
import web
from infogami import config
from infogami.utils import delegate
from infogami.utils.view import public
import requests
IA_BASE_URL = config.get('ia_base_url')
def get_ol_dumps():
"""Get list of all archive.org items in the ol_exports collection uploaded... | 2,585 | Python | .py | 72 | 29.958333 | 119 | 0.622535 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
457 | forms.py | internetarchive_openlibrary/openlibrary/plugins/upstream/forms.py | import web
from infogami.infobase.client import ClientException
from infogami.core import forms
from openlibrary.i18n import lgettext as _
from openlibrary.utils.form import (
Form,
Textbox,
Email,
Password,
Checkbox,
Hidden,
Validator,
RegexpValidator,
)
from openlibrary import account... | 4,495 | Python | .py | 139 | 25.309353 | 86 | 0.630023 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
458 | test_checkins.py | internetarchive_openlibrary/openlibrary/plugins/upstream/tests/test_checkins.py | from openlibrary.plugins.upstream.checkins import (
is_valid_date,
make_date_string,
patron_check_ins,
)
class TestMakeDateString:
def test_formatting(self):
date_str = make_date_string(2000, 12, 22)
assert date_str == "2000-12-22"
def test_zero_padding(self):
date_str = m... | 2,493 | Python | .py | 69 | 27.043478 | 71 | 0.574151 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
459 | test_utils.py | internetarchive_openlibrary/openlibrary/plugins/upstream/tests/test_utils.py | from openlibrary.mocks.mock_infobase import MockSite
from .. import utils
from openlibrary.catalog.add_book.tests.conftest import add_languages # noqa: F401
import web
import pytest
def test_url_quote():
assert utils.url_quote('https://foo bar') == 'https%3A%2F%2Ffoo+bar'
assert utils.url_quote('abc') == 'ab... | 11,048 | Python | .py | 244 | 37.934426 | 130 | 0.609526 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
460 | test_addbook.py | internetarchive_openlibrary/openlibrary/plugins/upstream/tests/test_addbook.py | """py.test tests for addbook"""
import web
from .. import addbook
from openlibrary import accounts
from openlibrary.mocks.mock_infobase import MockSite
def strip_nones(d):
return {k: v for k, v in d.items() if v is not None}
def mock_user():
return type(
'MockUser',
(object,),
{
... | 14,902 | Python | .py | 385 | 25.397403 | 86 | 0.470087 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
461 | test_merge_authors.py | internetarchive_openlibrary/openlibrary/plugins/upstream/tests/test_merge_authors.py | import web
from infogami.infobase import client, common
from openlibrary.plugins.upstream.merge_authors import (
AuthorMergeEngine,
AuthorRedirectEngine,
BasicMergeEngine,
BasicRedirectEngine,
get_many,
make_redirect_doc,
space_squash_and_strip,
)
from openlibrary.utils import dicthash
de... | 9,917 | Python | .py | 252 | 30.376984 | 103 | 0.518276 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
462 | test_forms.py | internetarchive_openlibrary/openlibrary/plugins/upstream/tests/test_forms.py | from .. import forms
from .. import spamcheck
class TestRegister:
def test_validate(self, monkeypatch):
monkeypatch.setattr(forms, 'find_account', lambda **kw: None)
monkeypatch.setattr(forms, 'find_ia_account', lambda **kw: None)
monkeypatch.setattr(spamcheck, "get_spam_domains", list)
... | 542 | Python | .py | 15 | 27.733333 | 72 | 0.591603 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
463 | test_related_carousels.py | internetarchive_openlibrary/openlibrary/plugins/upstream/tests/test_related_carousels.py | from .. import models
def test_related_subjects():
subjects = {
"In library",
"Conduct of life",
"London (England)",
"Science Fiction & Fantasy",
"Self-experimentation in medicine in fiction",
"Accessible book",
"Physicians in fiction",
"Fiction",
... | 1,914 | Python | .py | 64 | 21.5 | 76 | 0.577922 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
464 | test_account.py | internetarchive_openlibrary/openlibrary/plugins/upstream/tests/test_account.py | from .. import account
import web
import os
import re
import pytest
import sys
def open_test_data(filename):
"""Returns a file handle to file with specified filename inside test_data directory."""
root = os.path.dirname(__file__)
fullpath = os.path.join(root, 'test_data', filename)
return open(fullpat... | 10,881 | Python | .py | 288 | 26.090278 | 91 | 0.506069 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
465 | test_models.py | internetarchive_openlibrary/openlibrary/plugins/upstream/tests/test_models.py | """
Capture some of the unintuitive aspects of Storage, Things, and Works
"""
import web
from infogami.infobase import client
from openlibrary.mocks.mock_infobase import MockSite
import openlibrary.core.lists.model as list_model
from .. import models
class TestModels:
def setup_method(self, method):
web... | 3,810 | Python | .py | 84 | 36.547619 | 80 | 0.620625 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
466 | test_table_of_contents.py | internetarchive_openlibrary/openlibrary/plugins/upstream/tests/test_table_of_contents.py | from openlibrary.plugins.upstream.table_of_contents import TableOfContents, TocEntry
class TestTableOfContents:
def test_from_db_well_formatted(self):
db_table_of_contents = [
{"level": 1, "title": "Chapter 1"},
{"level": 2, "title": "Section 1.1"},
{"level": 2, "title"... | 6,664 | Python | .py | 172 | 27.610465 | 84 | 0.503642 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
467 | recaptcha.py | internetarchive_openlibrary/openlibrary/plugins/recaptcha/recaptcha.py | """Recapcha Input to use in web.py forms."""
import web
import requests
import logging
class Recaptcha(web.form.Input):
def __init__(self, public_key, private_key):
self.public_key = public_key
self._private_key = private_key
validator = web.form.Validator('Recaptcha failed', self.validat... | 1,110 | Python | .py | 29 | 29.413793 | 73 | 0.604846 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
468 | code.py | internetarchive_openlibrary/openlibrary/plugins/recaptcha/code.py | # from infogami.core.forms import register
# from infogami import config
#
# import recaptcha
#
# if config.get('plugin_recaptcha') is not None:
# public_key = config.plugin_recaptcha.public_key
# private_key = config.plugin_recaptcha.private_key
# else:
# public_key = config.recaptcha_public_key
# priv... | 474 | Python | .py | 14 | 32.857143 | 70 | 0.76087 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
469 | test_docker_compose.py | internetarchive_openlibrary/tests/test_docker_compose.py | import os
import yaml
def p(*paths):
"""Util to get absolute path from relative path"""
return os.path.join(os.path.dirname(__file__), *paths)
class TestDockerCompose:
def test_all_root_services_must_be_in_prod(self):
"""
Each service in compose.yaml should also be in
compose.pro... | 2,211 | Python | .py | 48 | 37.0625 | 87 | 0.617633 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
470 | expire_accounts.py | internetarchive_openlibrary/scripts/expire_accounts.py | from datetime import datetime
import web
def delete_old_links():
for doc in web.ctx.site.store.values(type="account-link"):
expiry_date = datetime.strptime(doc["expires_on"], "%Y-%m-%dT%H:%M:%S.%f")
now = datetime.utcnow()
key = doc["_key"]
if expiry_date > now:
print(... | 565 | Python | .py | 18 | 24.611111 | 82 | 0.573284 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
471 | get_web_error.py | internetarchive_openlibrary/scripts/get_web_error.py | #!/usr/bin/env python3
"""
% `python3 get_web_error.py 2023-02-03/011556535629.html | lynx --stdin`
To see the contents of an Open Library user-reported like 2023-02-03/011556535629.html:
1. Copy this script into your user directory on any Open Library host.
2. Type the command above substituting in the error code yo... | 1,716 | Python | .py | 39 | 39.128205 | 87 | 0.683673 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
472 | delete_import_items.py | internetarchive_openlibrary/scripts/delete_import_items.py | """
Deletes entries from the import_item table.
Reads ia_ids that should be deleted from an input file. The input file is expected to be tab-delimited, and each line will have the following format:
{N number of ia_ids in this line} {edition_key} {ia_id 1} [...] {ia_id N}
Requires a configuration file in order to run... | 4,909 | Python | .py | 127 | 29.92126 | 150 | 0.605939 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
473 | store_counts.py | internetarchive_openlibrary/scripts/store_counts.py | #!/usr/bin/env python
import sys
import _init_path # Imported for its side effect of setting PYTHONPATH
from openlibrary.admin import stats
if __name__ == "__main__":
if len(sys.argv) != 5:
print(
"Usage : %s infobase_config openlibrary_config coverstore_config number_of_days",
... | 408 | Python | .py | 12 | 28 | 93 | 0.637755 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
474 | _init_path.py | internetarchive_openlibrary/scripts/_init_path.py | """Helper to add openlibrary module to sys.path.
"""
import os
from os.path import abspath, realpath, join, dirname, pardir
import sys
path = __file__.replace('.pyc', '.py')
scripts_root = dirname(realpath(path))
OL_PATH = abspath(join(scripts_root, pardir))
sys.path.insert(0, OL_PATH)
# Add the PWD as the first en... | 595 | Python | .py | 14 | 41.214286 | 78 | 0.753899 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
475 | fake_loan_server.py | internetarchive_openlibrary/scripts/fake_loan_server.py | #!/usr/bin/env python
"""
Fake loan status server to make dev instance work with borrowing books.
"""
import web
urls = ("/is_loaned_out/(.*)", "is_loaned_out")
app = web.application(urls, globals())
class is_loaned_out:
def GET(self, resource_id):
web.header("Content-type", "application/json")
r... | 374 | Python | .py | 13 | 25.538462 | 71 | 0.646067 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
476 | mail_bad_author_query.py | internetarchive_openlibrary/scripts/mail_bad_author_query.py | #!/usr/bin/env python
import web
import os
import smtplib
import sys
from email.mime.text import MIMEText
password = open(os.path.expanduser('~/.openlibrary_db_password')).read()
if password.endswith('\n'):
password = password[:-1]
db_error = web.database(
dbn='postgres', db='ol_errors', host='localhost', user... | 1,597 | Python | .py | 51 | 28.431373 | 85 | 0.684655 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
477 | generate-api-docs.py | internetarchive_openlibrary/scripts/generate-api-docs.py | import web
import os
import re
import shutil
from collections import defaultdict
template = """\
$def with (mod, submodules)
$ name = mod.split(".")[-1]
$name
$("=" * len(name))
$if submodules:
Submodules
----------
.. toctree::
:maxdepth: 1
$for m in submodules: $m
Documentation
... | 2,810 | Python | .py | 93 | 23.763441 | 81 | 0.578358 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
478 | import_open_textbook_library.py | internetarchive_openlibrary/scripts/import_open_textbook_library.py | #!/usr/bin/env python
import json
import requests
import time
from itertools import islice
from typing import Any
from collections.abc import Generator
from openlibrary.core.imports import Batch
from scripts.solr_builder.solr_builder.fn_to_cli import FnToCLI
from openlibrary.config import load_config
FEED_URL = 'https... | 4,544 | Python | .py | 114 | 31 | 84 | 0.596268 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
479 | import_pressbooks.py | internetarchive_openlibrary/scripts/import_pressbooks.py | """
To run:
PYTHONPATH=. python ./scripts/import_pressbooks.py /olsystem/etc/openlibrary.yml ./path/to/pressbooks.json
"""
import json
import datetime
import logging
import requests
import html
from infogami import config
from openlibrary.config import load_config
from openlibrary.core.imports import Batch
from scri... | 4,553 | Python | .py | 125 | 28.736 | 106 | 0.581744 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
480 | oclc_to_marc.py | internetarchive_openlibrary/scripts/oclc_to_marc.py | """Find marc record URL from oclc number.
Usage: python oclc_to_marc.py oclc_1 oclc_2
"""
import requests
import urllib
root = "https://openlibrary.org"
def wget(path):
return requests.get(root + path).json()
def find_marc_url(d):
if d.get('source_records'):
return d['source_records'][0]
#... | 1,119 | Python | .py | 32 | 29.59375 | 99 | 0.611578 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
481 | test_py3.sh | internetarchive_openlibrary/scripts/test_py3.sh | #!/bin/sh
pytest . \
--ignore=scripts/2011 \
--ignore=infogami \
--ignore=vendor
RETURN_CODE=$?
ruff --exit-zero --select=E722,F403 --show-source # Show bare exceptions and wildcard (*) imports
safety check || true # Show any insecure dependencies
exit ${RETURN_CODE}
| 294 | Python | .py | 9 | 29 | 98 | 0.680851 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
482 | affiliate_server.py | internetarchive_openlibrary/scripts/affiliate_server.py | #!/usr/bin/env python
"""Run affiliate server.
Usage:
start affiliate-server using dev webserver:
./scripts/affiliate_server.py openlibrary.yml 31337
start affiliate-server as fastcgi:
./scripts/affiliate_server.py openlibrary.yml fastcgi 31337
start affiliate-server using gunicorn webserver:
./scrip... | 27,759 | Python | .py | 643 | 34.797823 | 104 | 0.63134 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
483 | copydocs.py | internetarchive_openlibrary/scripts/copydocs.py | #!/usr/bin/env python
from __future__ import annotations
from collections import namedtuple
import json
import os
import sys
from collections.abc import Iterator
import web
from scripts.solr_builder.solr_builder.fn_to_cli import FnToCLI
sys.path.insert(0, ".") # Enable scripts/copydocs.py to be run.
import scripts... | 12,281 | Python | .py | 314 | 30.165605 | 88 | 0.582072 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
484 | update-loans.py | internetarchive_openlibrary/scripts/update-loans.py | #!/usr/bin/env python
"""Script to update loans and waiting loans on regular intervals.
Tasks done:
* delete all waiting-loans that are expired
"""
import sys
import web
from openlibrary.core import waitinglist
from openlibrary.plugins.upstream import borrow
web.config.debug = False
def usage():
print(
... | 903 | Python | .py | 30 | 25.466667 | 130 | 0.695602 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
485 | solr_dump_xisbn.py | internetarchive_openlibrary/scripts/solr_dump_xisbn.py | #!/usr/bin/env python
"""
Script for creating a file of similar ISBNs or LCCNs from Solr.
Run on ol-solr1 (the staging solr). Turn off solr-next-updater on
ol-home0 , to avoid extra strain on the server, and then kick it off with
`tmux` (use tmux so if the ssh connection disconnects the process continu... | 6,968 | Python | .py | 172 | 30.424419 | 481 | 0.571977 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
486 | manage-imports.py | internetarchive_openlibrary/scripts/manage-imports.py | #!/usr/bin/env python
import datetime
import json
import logging
import os
import sys
import time
import web
from openlibrary.api import OLError, OpenLibrary
from openlibrary.config import load_config
from openlibrary.core.ia import get_candidate_ocaids
from openlibrary.core.imports import Batch, ImportItem
logger ... | 7,148 | Python | .py | 187 | 30.31016 | 88 | 0.62052 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
487 | pull-templates.py | internetarchive_openlibrary/scripts/pull-templates.py | #!/usr/bin/env python
"""Script to pull templates and macros from an openlibrary instance to repository.
"""
import _init_path # Imported for its side effect of setting PYTHONPATH
import os
import web
from optparse import OptionParser
from openlibrary.api import OpenLibrary, marshal
def parse_options(args=None):
... | 2,843 | Python | .py | 81 | 27.975309 | 82 | 0.595325 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
488 | detect_missing_i18n.py | internetarchive_openlibrary/scripts/detect_missing_i18n.py | #!/usr/bin/env python
"""Utility script to list html files which might be missing i18n strings."""
import _init_path # noqa: F401 Imported for its side effect of setting PYTHONPATH
import re
import sys
from pathlib import Path
from enum import Enum
from scripts.solr_builder.solr_builder.fn_to_cli import FnToCLI
impor... | 7,573 | Python | .py | 193 | 31.699482 | 194 | 0.596862 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
489 | open_syllabus_project_parser.py | internetarchive_openlibrary/scripts/open_syllabus_project_parser.py | '''
Run from root of openlibrary like so:
PYTHONPATH=$(PWD) python3 scripts/open_syllabus_project_parser.py
A python script that takes as an argument one directory.
In that that directory there are files named as follows:
part-00000-d2b72298-1996-464d-b238-27e4737d69ab-c000.json.gz
part-00001-d2b72298-1996-464d-b238-... | 2,293 | Python | .py | 88 | 21.772727 | 67 | 0.639091 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
490 | lc_marc_update.py | internetarchive_openlibrary/scripts/lc_marc_update.py | #!/usr/bin/env python
from openlibrary.catalog.importer.scribe import BadImport
from openlibrary.catalog.read_rc import read_rc
from openlibrary import config
from ftplib import FTP
from time import sleep
from lxml import etree
import sys
import httplib
import json
import argparse
import lxml.etree
parser = argparse.... | 4,857 | Python | .py | 149 | 26.248322 | 79 | 0.613165 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
491 | partner_batch_imports.py | internetarchive_openlibrary/scripts/partner_batch_imports.py | """
Process partner bibliographic csv data into importable json book
records and then batch submit into the ImportBot
`import_item` table (http://openlibrary.org/admin/imports)
which queues items to be imported via the
Open Library JSON import API: https://openlibrary.org/api/import
To Run:
PYTHONPATH=. python ./scri... | 10,312 | Python | .py | 275 | 28.963636 | 87 | 0.591287 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
492 | import_standard_ebooks.py | internetarchive_openlibrary/scripts/import_standard_ebooks.py | #!/usr/bin/env python
import json
import requests
from requests.auth import AuthBase, HTTPBasicAuth
import time
from typing import Any
import feedparser
from openlibrary.core.imports import Batch
from scripts.solr_builder.solr_builder.fn_to_cli import FnToCLI
from openlibrary.config import load_config
from infogami i... | 3,581 | Python | .py | 83 | 37.614458 | 84 | 0.669638 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
493 | update_stale_work_references.py | internetarchive_openlibrary/scripts/update_stale_work_references.py | """
PYTHONPATH=. python ./scripts/update_stale_work_references.py /olsystem/etc/openlibrary.yml
"""
import web
import infogami
from infogami import config
from openlibrary.config import load_config
from openlibrary.core.models import Work
from scripts.solr_builder.solr_builder.fn_to_cli import FnToCLI
import datetime
... | 576 | Python | .py | 18 | 29.166667 | 91 | 0.754069 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
494 | pr_slack_digest.py | internetarchive_openlibrary/scripts/pr_slack_digest.py | from datetime import datetime
import requests
import os
def send_slack_message(message: str):
response = requests.post(
'https://slack.com/api/chat.postMessage',
headers={
'Authorization': f"Bearer {os.environ.get('SLACK_TOKEN')}",
'Content-Type': 'application/json; charse... | 2,331 | Python | .py | 62 | 29.564516 | 113 | 0.549757 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
495 | migrate_db.py | internetarchive_openlibrary/scripts/migrate_db.py | #!/usr/bin/env python
"""Script to migrate the OL database to latest schema.
"""
import itertools
import json
import os
import sys
import web
changelog = """\
2010-04-22: 10 - Created unique index on thing.key
2010-07-01: 11 - Added `seq` table
2010-08-02: 12 - Added `data` column to transaction table.
2010-08-03: 1... | 3,954 | Python | .py | 116 | 25.181034 | 88 | 0.566483 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
496 | solr_updater.py | internetarchive_openlibrary/scripts/solr_updater.py | """New script to handle solr updates.
Author: Anand Chitipothu
Changes:
2013-02-25: First version
2018-02-11: Use newer config method
"""
import asyncio
import datetime
import json
import logging
from pathlib import Path
import re
import socket
import sys
import urllib
from typing import Union
from collections.abc ... | 11,014 | Python | .py | 266 | 31.890977 | 153 | 0.583949 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
497 | cron_watcher.py | internetarchive_openlibrary/scripts/cron_watcher.py | #!/usr/bin/env python
"""
Daily Cron-audit task (Python) sentry (who watches the watchers)
If not dump and cdump uploaded for last YYYY-MM on archive.org
If not sitemaps updated for this YYYY-MM on www
If not partner dumps uploaded for this YYYY-MM on archive.org
If no imports in last 48 hours (i.e. 2 days)
If DD>17 f... | 1,806 | Python | .py | 39 | 41.051282 | 76 | 0.68469 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
498 | oldump.py | internetarchive_openlibrary/scripts/oldump.py | #!/usr/bin/env python
import logging
import os
import sys
from datetime import datetime
import _init_path # Imported for its side effect of setting PYTHONPATH
logger = logging.getLogger(__file__)
logger.setLevel(logging.DEBUG)
def log(*args) -> None:
args_str = " ".join(str(a) for a in args)
msg = f"{date... | 1,325 | Python | .py | 32 | 36.09375 | 85 | 0.672642 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |
499 | promise_batch_imports.py | internetarchive_openlibrary/scripts/promise_batch_imports.py | """
As of 2022-12: Run on `ol-home0 cron container as
```
$ ssh -A ol-home0
$ docker exec -it -uopenlibrary openlibrary-cron-jobs-1 bash
$ PYTHONPATH="/openlibrary" python3 /openlibrary/scripts/promise_batch_imports.py /olsystem/etc/openlibrary.yml
```
The imports can be monitored for their statuses and rolled up / c... | 8,449 | Python | .py | 185 | 39.183784 | 216 | 0.656687 | internetarchive/openlibrary | 5,078 | 1,311 | 956 | AGPL-3.0 | 9/5/2024, 5:07:13 PM (Europe/Amsterdam) |