Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not is_facebook_url(url):
return None
splitted = safe_urlsplit(url)
if not splitted.path or splitted.path == '/':
return None
# Obvious post path
if '/posts/' in splitted.path:
parts = urlpathsplit(splitted.path)
parent_id_or_handle = parts[0]
if NUMERIC_ID_RE.match(parent_id_or_handle):
return FacebookPost(parts[2], parent_id=parent_id_or_handle)
return FacebookPost(parts[2], parent_handle=parent_id_or_handle)
# Ye olded permalink path
if splitted.query and '/permalink.php' in splitted.path:
query = parse_qs(splitted.query)
return FacebookPost(query['story_fbid'][0], parent_id=query['id'][0])
# Group permalink path
if '/groups/' in splitted.path and '/permalink/' in splitted.path:
parts = urlpathsplit(splitted.path)
return FacebookPost(parts[3], group_id=parts[1])
# Profile path
if splitted.path == '/profile.php':
splitted = safe_urlsplit(url)
if not splitted.path or splitted.path == '/':
return None
# Obvious post path
if '/posts/' in splitted.path:
parts = urlpathsplit(splitted.path)
parent_id_or_handle = parts[0]
if NUMERIC_ID_RE.match(parent_id_or_handle):
return FacebookPost(parts[2], parent_id=parent_id_or_handle)
return FacebookPost(parts[2], parent_handle=parent_id_or_handle)
# Ye olded permalink path
if splitted.query and '/permalink.php' in splitted.path:
query = parse_qs(splitted.query)
return FacebookPost(query['story_fbid'][0], parent_id=query['id'][0])
# Group permalink path
if '/groups/' in splitted.path and '/permalink/' in splitted.path:
parts = urlpathsplit(splitted.path)
return FacebookPost(parts[3], group_id=parts[1])
# Profile path
if splitted.path == '/profile.php':
query = parse_qs(splitted.query)
user_id = query['id'][0]
if NUMERIC_ID_RE.match(parent_id_or_handle):
return FacebookPost(parts[2], parent_id=parent_id_or_handle)
return FacebookPost(parts[2], parent_handle=parent_id_or_handle)
# Ye olded permalink path
if splitted.query and '/permalink.php' in splitted.path:
query = parse_qs(splitted.query)
return FacebookPost(query['story_fbid'][0], parent_id=query['id'][0])
# Group permalink path
if '/groups/' in splitted.path and '/permalink/' in splitted.path:
parts = urlpathsplit(splitted.path)
return FacebookPost(parts[3], group_id=parts[1])
# Profile path
if splitted.path == '/profile.php':
query = parse_qs(splitted.query)
user_id = query['id'][0]
return FacebookUser(user_id)
# People path
if splitted.path.startswith('/people'):
parts = urlpathsplit(splitted.path)
user_id = parts[2]
return FacebookUser(user_id)
# Handle path
if splitted.path:
parts = urlpathsplit(splitted.path)