chg: [dev] clean up how keys are accessed in self._parameters

pull/573/head
VVX7 2020-05-08 19:54:12 -04:00
parent 759e9196de
commit fff0caa330
1 changed files with 20 additions and 21 deletions

View File

@ -15,19 +15,19 @@ class MicroblogObject(AbstractMISPObjectGenerator):
def generate_attributes(self):
# Raw post.
if self._parameters.get('post'):
if 'post' in self._parameters:
self.add_attribute('post', value=self._parameters['post'])
# Title of the post.
if self._parameters.get('title'):
if 'title' in self._parameters:
self.add_attribute('title', value=self._parameters['title'])
# Original link into the microblog post (Supposed harmless).
if self._parameters.get('link'):
if 'link' in self._parameters:
self.add_attribute('link', value=self._parameters['link'])
# Original URL location of the microblog post (potentially malicious.
if self._parameters.get('url'):
if 'url' in self._parameters:
if isinstance(self._parameters.get('url'), list):
for i in self._parameters.get('url'):
self.add_attribute('url', value=i)
@ -35,7 +35,7 @@ class MicroblogObject(AbstractMISPObjectGenerator):
self.add_attribute('url', value=self._parameters['url'])
# Archive of the original document (Internet Archive, Archive.is, etc).
if self._parameters.get('archive'):
if 'archive' in self._parameters:
if isinstance(self._parameters.get('archive'), list):
for i in self._parameters.get('archive'):
self.add_attribute('archive', value=i)
@ -43,34 +43,33 @@ class MicroblogObject(AbstractMISPObjectGenerator):
self.add_attribute('archive', value=self._parameters['archive'])
# Display name of the account who posted the microblog.
if self._parameters.get('display-name'):
if 'display-name' in self._parameters:
self.add_attribute('display-name', value=self._parameters['display-name'])
# The user ID of the microblog this post replies to.
if self._parameters.get('in-reply-to-user-id'):
if 'in-reply-to-user-id' in self._parameters:
self.add_attribute('in-reply-to-user-id', value=self._parameters['in-reply-to-user-id'])
# The microblog ID of the microblog this post replies to.
if self._parameters.get('in-reply-to-status-id'):
if 'in-reply-to-status-id' in self._parameters:
self.add_attribute('in-reply-to-status-id', value=self._parameters['in-reply-to-status-id'])
# The user display name of the microblog this post replies to.
if self._parameters.get('in-reply-to-display-name'):
if 'in-reply-to-display-name' in self._parameters:
self.add_attribute('in-reply-to-display-name', value=self._parameters['in-reply-to-display-name'])
# The language of the post.
if self._parameters.get('language'):
if 'language' in self._parameters:
self.add_attribute('language', value=self._parameters['language'], disable_correlation=True)
# TODO: handle attachments
# The microblog post file or screen capture.
# if self._parameters.get('attachment'):
# if 'attachment' in self._parameters:
# self.add_attribute('attachment', value=self._parameters['attachment'])
# Type of the microblog post.
type_allowed_values = ["Twitter", "Facebook", "LinkedIn", "Reddit", "Google+",
"Instagram", "Forum", "Other"]
if self._parameters.get('type'):
if 'type' in self._parameters:
if isinstance(self._parameters.get('type'), list):
for i in self._parameters.get('type'):
if i in type_allowed_values:
@ -81,7 +80,7 @@ class MicroblogObject(AbstractMISPObjectGenerator):
# State of the microblog post.
type_allowed_values = ["Informative", "Malicious", "Misinformation", "Disinformation", "Unknown"]
if self._parameters.get('state'):
if 'state' in self._parameters:
if isinstance(self._parameters.get('state'), list):
for i in self._parameters.get('state'):
if i in type_allowed_values:
@ -91,12 +90,12 @@ class MicroblogObject(AbstractMISPObjectGenerator):
self.add_attribute('state', value=self._parameters['state'])
# Username who posted the microblog post (without the @ prefix).
if self._parameters.get('username'):
if 'username' in self._parameters:
self.add_attribute('username', value=self._parameters['username'])
# == the username account verified by the operator of the microblog platform.
type_allowed_values = ["Verified", "Unverified", "Unknown"]
if self._parameters.get('verified-username'):
if 'verified-username' in self._parameters:
if isinstance(self._parameters.get('verified-username'), list):
for i in self._parameters.get('verified-username'):
if i in type_allowed_values:
@ -106,7 +105,7 @@ class MicroblogObject(AbstractMISPObjectGenerator):
self.add_attribute('verified-username', value=self._parameters['verified-username'])
# embedded-link.
if self._parameters.get('embedded-link'):
if 'embedded-link' in self._parameters:
if isinstance(self._parameters.get('embedded-link'), list):
for i in self._parameters.get('embedded-link'):
self.add_attribute('embedded-link', value=i)
@ -114,7 +113,7 @@ class MicroblogObject(AbstractMISPObjectGenerator):
self.add_attribute('embedded-link', value=self._parameters['embedded-link'])
# embedded-safe-link
if self._parameters.get('embedded-safe-link'):
if 'embedded-safe-link' in self._parameters:
if isinstance(self._parameters.get('embedded-safe-link'), list):
for i in self._parameters.get('embedded-safe-link'):
self.add_attribute('embedded-safe-link', value=i)
@ -122,7 +121,7 @@ class MicroblogObject(AbstractMISPObjectGenerator):
self.add_attribute('embedded-safe-link', value=self._parameters['embedded-safe-link'])
# Hashtag into the microblog post.
if self._parameters.get('hashtag'):
if 'hashtag' in self._parameters:
if isinstance(self._parameters.get('hashtag'), list):
for i in self._parameters.get('hashtag'):
self.add_attribute('hashtag', value=i)
@ -130,7 +129,7 @@ class MicroblogObject(AbstractMISPObjectGenerator):
self.add_attribute('hashtag', value=self._parameters['hashtag'])
# username quoted
if self._parameters.get('username-quoted'):
if 'username-quoted' in self._parameters:
if isinstance(self._parameters.get('username-quoted'), list):
for i in self._parameters.get('username-quoted'):
self.add_attribute('username-quoted', value=i)
@ -138,5 +137,5 @@ class MicroblogObject(AbstractMISPObjectGenerator):
self.add_attribute('username-quoted', value=self._parameters['username-quoted'])
# twitter post id
if self._parameters.get('twitter-id'):
if 'twitter-id' in self._parameters:
self.add_attribute('twitter-id', value=self._parameters['twitter-id'])