How to use the arxiv.base.globals.get_application_config function in arxiv

To help you get started, we’ve selected a few arxiv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arXiv / arxiv-browse / browse / services / document / cache.py View on Github external
def get_session(app: object = None) -> DocumentCacheSession:
    """Get a new session with the document cache service."""
    config = get_application_config(app)
    document_cache_path = config.get('DOCUMENT_CACHE_PATH', None)

    return DocumentCacheSession(document_cache_path)
github arXiv / arxiv-browse / browse / controllers / tb_page / __init__.py View on Github external
from arxiv import status
from arxiv.base import logging
from arxiv.base.globals import get_application_config
from browse.exceptions import TrackbackNotFound
from browse.services.database import get_paper_trackback_pings, \
                                     get_recent_trackback_pings, \
                                     get_trackback_ping
from browse.controllers import check_supplied_identifier
from browse.domain.identifier import Identifier, IdentifierException
from browse.services.document import metadata
from browse.services.document.metadata import AbsException, \
    AbsNotFoundException
from browse.services.search.search_authors import queries_for_authors, \
    split_long_author_list

app_config = get_application_config()
logger = logging.getLogger(__name__)

Response = Tuple[Dict[str, Any], int, Dict[str, Any]]
truncate_author_list_size = 10
trackback_count_options = [25, 50, 100, 200]


def get_tb_page(arxiv_id: str) -> Response:
    """Get the data needed to display the trackback page for an arXiv article.

    Parameters
    ----------
    arxiv_id : str

    Returns
    -------
github arXiv / arxiv-browse / browse / services / util / response_headers.py View on Github external
Parameters
    ----------
    dt : datetime
        The datetime to use as the basis for comparison to guess the
        "next update" datetime.

    Returns
    -------
    Tuple[datetime, bool]
        A UTC-based datetime for the next update; a boolean that indicates
        whether the provided dt is likely to coincide with a publish process,
        which is the APPROX_PUBLISH_DURATION window starting 20:00 on the
        normal publish days specified by PUBLISH_ISO_WEEKDAYS.
    """
    config = get_application_config()
    tz = gettz(config.get('ARXIV_BUSINESS_TZ', 'US/Eastern'))
    dt = dt.astimezone(tz=tz)

    possible_publish_dt = dt.replace(hour=20, minute=0, second=0)

    after_todays_publish: bool = dt >= possible_publish_dt
    likely_in_publish = False
    delta_to_next_publish = timedelta(days=0)

    weekday = dt.isoweekday()
    if after_todays_publish:
        delta_to_next_publish = timedelta(days=1)
        if dt < (possible_publish_dt + APPROX_PUBLISH_DURATION) \
           and weekday in PUBLISH_ISO_WEEKDAYS:
            likely_in_publish = True
github arXiv / arxiv-browse / browse / services / database / models.py View on Github external
import hashlib
from typing import Optional
from validators import url as is_valid_url
from datetime import datetime
from dateutil.tz import tzutc, gettz
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import BigInteger, Column, DateTime, Enum, ForeignKey, \
    ForeignKeyConstraint, Index, \
    Integer, SmallInteger, String, Table, text, Text
from sqlalchemy.orm import relationship
from werkzeug.local import LocalProxy
from arxiv.base.globals import get_application_config

db: SQLAlchemy = SQLAlchemy()

app_config = get_application_config()
tz = gettz(app_config.get('ARXIV_BUSINESS_TZ', 'US/Eastern'))
tb_secret = app_config.get('TRACKBACK_SECRET', 'baz')
metadata = db.metadata


class Document(db.Model):
    """Model for documents stored as part of the arXiv repository."""

    __tablename__ = 'arXiv_documents'

    document_id = Column(Integer, primary_key=True)
    paper_id = Column(String(20), nullable=False,
                      unique=True, server_default=text("''"))
    title = Column(String(255), nullable=False,
                   index=True, server_default=text("''"))
    authors = Column(Text)
github arXiv / arxiv-browse / browse / controllers / home_page / __init__.py View on Github external
"""Handle requests to support the home page."""

import os
import re
from flask import current_app
from typing import Any, Dict, Optional, Tuple
from werkzeug.exceptions import InternalServerError

from browse.services.database import get_document_count
from arxiv import status, taxonomy
from arxiv.base import logging
from arxiv.base.globals import get_application_config

app_config = get_application_config()
logger = logging.getLogger(__name__)

Response = Tuple[Dict[str, Any], int, Dict[str, Any]]

RE_TOTAL_PAPERS = re.compile(r'^total_papers\s+(?P[0-9]+)',
                             re.MULTILINE)


def get_home_page() -> Response:
    """Get the data needed to generated the home page."""
    response_data: Dict[str, Any] = {}
    response_headers: Dict[str, Any] = {}
    try:
        response_data['document_count'] = _get_document_count()
    except Exception as ex:
        logger.warning(f'Could not get abs page data: {ex}')
github arXiv / arxiv-browse / browse / services / document / metadata.py View on Github external
def get_session(app: object = None) -> AbsMetaSession:
    """Get a new session with the abstract metadata service."""
    config = get_application_config(app)
    orignal_versions_path = config.get('DOCUMENT_ORIGNAL_VERSIONS_PATH', None)
    latest_versions_path = config.get('DOCUMENT_LATEST_VERSIONS_PATH', None)

    return AbsMetaSession(latest_versions_path, orignal_versions_path)