From dc91c9cbf4f343a0d8483b404dd60b2e4b142cea Mon Sep 17 00:00:00 2001 From: "Desai, Kartikey H" Date: Wed, 6 Feb 2019 16:16:50 -0500 Subject: [PATCH] Initial fix for issue 86. Fixes #86 --- stix2/v21/sdo.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/stix2/v21/sdo.py b/stix2/v21/sdo.py index 37699a6..887fd0b 100644 --- a/stix2/v21/sdo.py +++ b/stix2/v21/sdo.py @@ -3,6 +3,8 @@ from collections import OrderedDict import itertools +from six.moves.urllib.parse import quote_plus + from ..core import STIXDomainObject from ..custom import _custom_object_builder from ..properties import ( @@ -263,6 +265,30 @@ class Location(STIXDomainObject): self._check_properties_dependency(['latitude'], ['longitude']) self._check_properties_dependency(['longitude'], ['latitude']) + def to_maps_url(self, map_engine="Google Maps"): + params = [] + if self.get('latitude') is not None and self.get('longitude') is not None: + latitude = self.get('latitude') + longitude = self.get('longitude') + params.extend([str(latitude), str(longitude)]) + else: + properties = ['street_address', 'city', 'region', 'administrative_area', 'country', 'postal_code'] + params = [self.get(prop) for prop in properties if self.get(prop) is not None] + + return self._to_maps_url_creator(map_engine, params) + + def _to_maps_url_creator(self, map_engine, params): + if map_engine == "Google Maps": + url_base = "https://www.google.com/maps/search/?api=1&query=" + url_ending = params[0] + for i in range(1, len(params)): + url_ending = url_ending + "," + params[i] + + final_url = url_base + quote_plus(url_ending) + return final_url + else: + return "Other map engines are not currently supported." + class Malware(STIXDomainObject): # TODO: Add link