Skip to content

Commit

Permalink
fixed utils (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Impervguin authored Oct 22, 2024
1 parent 213e58b commit 25b5ccd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions googleimport/utils.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import transliterate as tr

from urllib.parse import urlparse

def ParseSharedFolderID(url: str) -> str:
"""Parses the Shared Folder ID from the Google Drive URL."""
path = urlparse(url).path
folderIndex = 0
splitURL = url.split('/')
splitURL = path.split('/')
while folderIndex < len(splitURL) - 1:
if splitURL[folderIndex] == 'folders':
return splitURL[folderIndex + 1]
folderIndex += 1
raise ValueError('Could not parse Shared Folder ID: no folders found')

def ParseSharedFileID(url: str) -> str:
"""Parses the Shared File ID from the Google Drive URL."""
path = urlparse(url).path
fileIndex = 0
splitURL = url.split('/')
splitURL = path.split('/')
while fileIndex < len(splitURL) - 1:
if splitURL[fileIndex] == 'file':
return splitURL[fileIndex + 2]
Expand All @@ -34,4 +36,4 @@ def CreateLoginFromName(name : str) -> str:
for part in nameParts[1:]:
loginParts.append(tr.translit(part, 'ru', reversed=True)[0])
login = '_'.join(loginParts)
return login.lower()
return login.lower()

0 comments on commit 25b5ccd

Please sign in to comment.