@@ -647,28 +647,32 @@ def postprocess_activity(activity, mentions=False):
647
647
648
648
@staticmethod
649
649
def postprocess_object (obj , mentions = False ):
650
- """Does source-independent post-processing of an object, in place.
650
+ """Does source-independent post-processing of an AS1 object, in place.
651
651
652
652
* Populates ``location.position`` based on latitude and longitude.
653
653
* Optionally interprets HTML links in content with text starting with ``@``,
654
654
eg ``@user`` or ``@user.com`` or ``@[email protected] ``, as @-mentions
655
655
and adds ``mention`` tags for them.
656
656
657
657
Args:
658
- obj (dict)
658
+ obj (dict): AS1 object
659
659
mentions (boolean): whether to detect @-mention links and convert them to
660
660
mention tags
661
661
662
662
Returns:
663
663
dict: ``obj``, modified in place
664
664
"""
665
665
loc = obj .get ('location' )
666
- if loc :
666
+ if loc and isinstance ( loc , dict ) and 'position' not in loc :
667
667
lat = loc .get ('latitude' )
668
668
lon = loc .get ('longitude' )
669
- if lat and lon and not loc .get ('position' ):
670
- # ISO 6709 location string. details: http://en.wikipedia.org/wiki/ISO_6709
671
- loc ['position' ] = '%0+10.6f%0+11.6f/' % (lat , lon )
669
+ if lat is not None and lon is not None :
670
+ try :
671
+ # ISO 6709 location string. details: http://en.wikipedia.org/wiki/ISO_6709
672
+ loc ['position' ] = '%0+2f%0+2f/' % (float (lat ), float (lon ))
673
+ except ValueError :
674
+ # couldn't convert lat or lon to float
675
+ pass
672
676
673
677
if mentions :
674
678
# @-mentions to mention tags
0 commit comments