caption_hashtags property for only-if evaluation
caption_hashtags is a list of all hashtags that are mentioned in the Post's caption. It allows to easily filter Posts that have multiple hashtags, and as such fixes #24. Further, the documentation of --only-if has been completed by linking to a description of the syntax in the Python documentation, and by linking to a list of all defined properties with their meanings. So, this commit also closes #42.
This commit is contained in:
@@ -275,6 +275,16 @@ class Post:
|
||||
elif "caption" in self._node:
|
||||
return self._node["caption"]
|
||||
|
||||
@property
|
||||
def caption_hashtags(self) -> List[str]:
|
||||
"""List of all hashtags (without preceeding #) which occur in the Post's caption."""
|
||||
if not self.caption:
|
||||
return []
|
||||
# This regular expression is from jStassen, adjusted to use Python's \w to support Unicode
|
||||
# http://blog.jstassen.com/2016/03/code-regex-for-instagram-username-and-hashtags/
|
||||
hashtag_regex = re.compile(r"(?:#)(\w(?:(?:\w|(?:\.(?!\.))){0,28}(?:\w))?)")
|
||||
return re.findall(hashtag_regex, self.caption)
|
||||
|
||||
@property
|
||||
def is_video(self) -> bool:
|
||||
"""True if the Post is a video."""
|
||||
|
Reference in New Issue
Block a user