db_search.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:united-states-of-browsers 作者: kchawla-pi 项目源码 文件源码
def search(db_path: PathInfo,
           word_query: Optional[Text]='',
           date_start: Optional[Text]=None,
           date_stop: Optional[Text]=None,
           ) -> Iterable[NamedTuple]:
    """ Returns the search result as a list of NamedTuple of records.
    Accepts database file path and optionally, keywords and date range.

    Optional:
        word_query: if None (default), not included in search filter.
        date_start: if None(default), the earliest date is used.
        date_stop: if None (default), the present date is used.
    """
    if not date_start:
        date_start = int(dt.timestamp(dt.strptime('1970-01-02', '%Y-%m-%d')) * 10**6)
    else:
        date_start = int(dt.timestamp(dt.strptime(date_start, '%Y-%m-%d')) * 10**6)
    if not date_stop:
        date_stop = int(dt.utcnow().timestamp() * 10 ** 6)
    else:
        date_stop = int(dt.timestamp(dt.strptime(date_stop, '%Y-%m-%d')) * 10**6)
    word_query = helpers.query_sanitizer(word_query, allowed_chars=[' ', '%', '(', ')', '_'])
    sql_query, query_bindings = _make_sql_statement(word_query, date_start, date_stop)
    search_results = _run_search(db_path, sql_query, query_bindings)
    return search_results
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号