Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added parser function and replaced rsplit with url_parser #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions kerckhoff/packages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def as_dict(self):
}

def save(self, *args, **kwargs):
self.drive_folder_id = self.drive_folder_url.rsplit('/', 1)[-1]
self.drive_folder_id = url_parser(self.drive_folder_url)
super().save(*args, **kwargs)

def populate(self, user):
Expand Down Expand Up @@ -140,7 +140,7 @@ def setup_and_save(self, user, pset_slug):
self.drive_folder_id = drive_id
self.drive_folder_url = url
else:
folder_id = self.drive_folder_url.rsplit('/', 1)[-1]
folder_id = url_parser(self.drive_folder_url)
details = get_file(google, folder_id)
if details.get("mimeType") != "application/vnd.google-apps.folder":
raise ValidationError({"drive_folder_url" : ["The Google drive link must be a link to an existing folder!"]})
Expand Down
7 changes: 7 additions & 0 deletions kerckhoff/packages/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ def replace_url(fn):
text = IMAGE_REGEX.sub(replace_url,package.cached_article_preview)
return text

def url_parser(url_string):
domain = url_string.split("?")
separate = domain[0].split('/')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a couple of potential issues with this approach - the "/" can show up in multiple places, and I can't recall if urls can only contain one ?. Have you tried looking at https://docs.python.org/3/library/urllib.parse.html?

url_string = separate[len(separate) - 1]
return url_string


def transfer_to_s3(session: OAuth2Session, package):
if package.images.get("s3") is None:
package.images["s3"] = {}
Expand Down