Skip to content
Snippets Groups Projects
Commit 467639a6 authored by roadscape's avatar roadscape
Browse files

mentions matching util

parent 720ef3fc
No related branches found
No related tags found
No related merge requests found
......@@ -27,9 +27,9 @@ class NotifyType(IntEnum):
reply_comment = 13
reblog = 14
follow = 15
mention = 16
# inactive
#mention = 13
#vote_post = 15
#vote_comment = 16
......
......@@ -24,7 +24,7 @@ STRINGS = {
NotifyType.follow: '<src> followed <dst>',
NotifyType.reply_post: '<src> replied to you: <post>', # `dst` requires parent post?
NotifyType.reply_comment: '<src> replied to you: <post>',
#NotifyType.mention: '<post> mentioned <dst>',
NotifyType.mention: '<post> mentioned <dst>',
#NotifyType.vote_post: '<src> voted on <post>',
#NotifyType.vote_comment: '<src> voted on <post>',
......
"""Methods for normalizing steemd post metadata."""
#pylint: disable=line-too-long
import re
import math
import ujson as json
from funcy.seqs import first, distinct
from hive.utils.normalize import sbd_amount, rep_log10, safe_img_url, parse_time, utc_timestamp
def mentions(body):
"""Given a post body, return proper @-mentioned account names."""
matches = re.findall('(?:^|[^a-zA-Z0-9_!#$%&*@])(:?@)([a-z\\d\\-.]+)', body)
names = [grp[1] for grp in matches]
return list(dict.fromkeys(names)) # uniq-ordered
def post_basic(post):
"""Basic post normalization: json-md, tags, and flags."""
......
......@@ -2,6 +2,7 @@
from decimal import Decimal
from hive.utils.post import (
mentions,
post_basic,
post_legacy,
post_payout,
......@@ -137,6 +138,13 @@ POST_2 = {
"vote_rshares": 0
}
def test_body_mentions():
assert mentions('Hi @abc, meet @bob') == ['abc', 'bob']
assert mentions('Hi @abc, meet @abc') == ['abc']
assert mentions('') == []
assert mentions('@') == []
assert mentions('steemit.com/@apple') == []
def test_post_basic():
ret = post_basic(POST_1)
expect = {'json_metadata': {'tags': ['spam'], 'image': ['https://pbs.twimg.com/media/DBgNm3jXoAAioyE.jpg', 'https://example.com/image.jpg'], 'app': 'steemit/0.1', 'format': 'markdown'},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment