Skip to content

Commit

Permalink
Merge pull request #245 from amosproj/add-initialisation-prompt-link-…
Browse files Browse the repository at this point in the history
…to-script

fix: Add Andis link for init prompt and fix regex expression
  • Loading branch information
lukas-varga authored Jul 8, 2024
2 parents 4e9d41d + a495946 commit 5da4ebe
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/backend/RAG/LangChain_Implementation/get_google_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
from googleapiclient.discovery import build
from googleapiclient.http import MediaIoBaseDownload


def extract_document_id_from_url(url):
pattern = r'[A-Za-z0-9]*'
pattern = r'/d/([a-zA-Z0-9-_]+)'
matches = re.findall(pattern, url)
document_id = max(matches, key=len)
return document_id


def authenticate(credentials, scopes):
"""Obtaining auth with needed apis"""
creds = None
Expand Down Expand Up @@ -63,14 +65,19 @@ def download_file(file_id, credentials_path, file_name):


# Example usage
document_id = extract_document_id_from_url("https://docs.google.com/document/d/1xrfrwyRCTrxiCupiKSSFgKUxiCTXgr45gPJYybnY23w/edit")
document_id = extract_document_id_from_url(
'https://docs.google.com/document/d/1GtLyBqhk-cu8CSo4A15WTgGDbMbL4B9LLjdvBoU3234/edit'
)
# print("Document id: ", document_id)
credentials_json = 'credentials.json'

# Define the file path in a cross-platform manner
file_name = Path('data') / 'google_docs_content.txt'
file_name.parent.mkdir(parents=True, exist_ok=True)

# TODO: make this callable from typescript with url

content = download_file(document_id, credentials_json, file_name)
print(content)
try:
content = download_file(document_id, credentials_json, file_name)
print(content)
except Exception as e:
print(f'An error occurred: {e}')

0 comments on commit 5da4ebe

Please sign in to comment.