Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
api
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
retribute.me
api
Commits
76e08567
Verified
Commit
76e08567
authored
6 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Added url extraction from activitypub profiles
parent
cb55f756
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
retribute_api/search/activitypub.py
+41
-0
41 additions, 0 deletions
retribute_api/search/activitypub.py
setup.cfg
+2
-0
2 additions, 0 deletions
setup.cfg
tests/search/test_activitypub.py
+41
-0
41 additions, 0 deletions
tests/search/test_activitypub.py
with
84 additions
and
0 deletions
retribute_api/search/activitypub.py
0 → 100644
+
41
−
0
View file @
76e08567
import
lxml.html
from
rest_framework
import
serializers
def
get_urls
(
content
):
links
=
[]
dom
=
lxml
.
html
.
fromstring
(
content
)
for
link
in
dom
.
xpath
(
"
//a/@href
"
):
links
.
append
(
link
)
return
links
def
extract_urls_from_attachments
(
attachments
):
data
=
[]
for
attachment
in
attachments
:
if
attachment
[
"
type
"
]
!=
"
PropertyValue
"
:
continue
urls
=
get_urls
(
attachment
[
"
value
"
])
if
not
urls
:
continue
row
=
{
"
summary
"
:
attachment
[
"
name
"
],
"
url
"
:
urls
[
0
]}
data
.
append
(
row
)
return
data
class
TagSerializer
(
serializers
.
Serializer
):
name
=
serializers
.
CharField
()
type
=
serializers
.
CharField
()
class
AttachmentSerializer
(
serializers
.
Serializer
):
type
=
serializers
.
CharField
()
name
=
serializers
.
CharField
()
value
=
serializers
.
CharField
()
class
ActorSerializer
(
serializers
.
Serializer
):
attachment
=
serializers
.
ListField
(
child
=
AttachmentSerializer
(),
min_length
=
1
)
tag
=
serializers
.
ListField
(
child
=
TagSerializer
(),
min_length
=
0
)
This diff is collapsed.
Click to expand it.
setup.cfg
+
2
−
0
View file @
76e08567
...
@@ -31,6 +31,8 @@ install_requires =
...
@@ -31,6 +31,8 @@ install_requires =
django-redis
django-redis
djangorestframework
djangorestframework
psycopg2-binary
psycopg2-binary
lxml
[options.entry_points]
[options.entry_points]
...
...
This diff is collapsed.
Click to expand it.
tests/search/test_activitypub.py
0 → 100644
+
41
−
0
View file @
76e08567
from
retribute_api.search
import
activitypub
def
test_profile_serializer
():
payload
=
{
"
tag
"
:
[{
"
type
"
:
"
Hashtag
"
,
"
name
"
:
"
#nobot
"
}],
"
attachment
"
:
[
{
"
type
"
:
"
PropertyValue
"
,
"
name
"
:
"
patreon
"
,
"
value
"
:
'
<a href=
"
https://patreon.com/username
"
rel=
"
me nofollow noopener
"
>Test</a>
'
,
}
],
}
serializer
=
activitypub
.
ActorSerializer
(
data
=
payload
)
assert
serializer
.
is_valid
(
raise_exception
=
True
)
is
True
assert
serializer
.
validated_data
==
payload
def
test_extract_urls_from_attachments
():
attachments
=
[
{
"
type
"
:
"
PropertyValue
"
,
"
name
"
:
"
Support me on Patreon
"
,
"
value
"
:
'
<a href=
"
https://patreon.com/username
"
rel=
"
me nofollow noopener
"
target=
"
_blank
"
>This is my Patreon</a>
'
,
},
{
"
type
"
:
"
PropertyValue
"
,
"
name
"
:
"
Support me on Ko-Fi
"
,
"
value
"
:
'
<a href=
"
https://ko-fi.com/username
"
rel=
"
me nofollow noopener
"
target=
"
_blank
"
>This is my Ko-Fi</a>
'
,
},
{
"
type
"
:
"
PropertyValue
"
,
"
name
"
:
"
Irrelevant text
"
,
"
value
"
:
"
No link
"
},
]
expected
=
[
{
"
summary
"
:
"
Support me on Patreon
"
,
"
url
"
:
"
https://patreon.com/username
"
},
{
"
summary
"
:
"
Support me on Ko-Fi
"
,
"
url
"
:
"
https://ko-fi.com/username
"
},
]
assert
activitypub
.
extract_urls_from_attachments
(
attachments
)
==
expected
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment