Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
public-apis
Commits
2eb6d201
Unverified
Commit
2eb6d201
authored
Jan 11, 2022
by
Matheus Felipe
Browse files
Implement functions to check duplicate links
parent
4808d633
Changes
1
Hide whitespace changes
Inline
Side-by-side
scripts/validate/links.py
View file @
2eb6d201
...
@@ -32,6 +32,31 @@ def find_links_in_file(filename: str) -> List[str]:
...
@@ -32,6 +32,31 @@ def find_links_in_file(filename: str) -> List[str]:
return
links
return
links
def
check_duplicate_links
(
links
:
List
[
str
])
->
bool
:
"""Check for duplicated links and return True or False."""
print
(
'Checking for duplicated links...'
)
seen
=
{}
duplicates
=
[]
has_duplicate
=
False
for
link
in
links
:
if
link
not
in
seen
:
seen
[
link
]
=
1
else
:
if
seen
[
link
]
==
1
:
duplicates
.
append
(
link
)
if
not
duplicates
:
print
(
f
'No duplicate links.'
)
else
:
print
(
f
'Found duplicate links:
{
duplicates
}
'
)
has_duplicate
=
True
return
has_duplicate
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
num_args
=
len
(
sys
.
argv
)
num_args
=
len
(
sys
.
argv
)
...
@@ -40,3 +65,5 @@ if __name__ == '__main__':
...
@@ -40,3 +65,5 @@ if __name__ == '__main__':
sys
.
exit
(
1
)
sys
.
exit
(
1
)
links
=
find_links_in_file
(
sys
.
argv
[
1
])
links
=
find_links_in_file
(
sys
.
argv
[
1
])
has_duplicate
=
check_duplicate_links
(
links
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment