Last active
December 7, 2022 00:00
-
-
Save guinslym/df7c0b684d952f7dea53cfb55e642773 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lh3.api | |
from lh3.api import * | |
import re | |
content_range_pattern = re.compile(r"chats (\d+)-(\d+)\/(\d+)") | |
def extract_content_range(content_range): | |
matches = content_range_pattern.match(content_range) | |
begin = matches.group(1) | |
end = matches.group(2) | |
total = matches.group(3) | |
return (begin, end, total) | |
def search_chats(client, query, chat_range): | |
begin, end = chat_range | |
_, x_api_version = lh3.api._API.versions.get("v4") | |
headers = { | |
"Content-Type": "application/json", | |
"Range": "chats {begin}-{end}".format(begin=begin, end=end), | |
"X-Api-Version": x_api_version, | |
} | |
request = getattr(client.api().session, "post") | |
response = request( | |
client.api()._api("v4", "/chat/_search"), headers=headers, json=query | |
) | |
chats = client.api()._maybe_json(response) | |
content_range = extract_content_range(response.headers["Content-Range"]) | |
return chats, content_range | |
def query_for_search_transcript_with_this_keyword(in_transcript, results=(0, 500)): | |
query = { | |
"query": { | |
"transcript": [in_transcript], | |
}, | |
"sort": [{"started": "descending"}], | |
} | |
#import pdb; pdb.set_trace() | |
client = Client() | |
chats, content_range = search_chats(client, query, chat_range=results) | |
return chats |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment