Example #1
0
def update_swm_post(post: str, tag=None):
    post = Post(post).export()
    prepare_post(post)

    tag = get_swm_tag(post['body'])

    if tag:
        lat, lng, desc = get_swm_tag(post['body'])
    else:
        raise NoSWMTag(f'Not contains tag {post["identifier"]}')

    try:
        lat = float(clean_coordinate(lat))
        lng = float(clean_coordinate(lng))

    except Exception as e:
        logging.exception('Parsing coords error')
    else:
        geo = {
            "geometry": {
                "type": "Point",
                "coordinates": [lng, lat]
            },
            "properties": {
                'name': "",
                'desc': desc
            }
        }

        PostModel.objects(identifier=post['identifier']).update(**post,
                                                                geo=geo,
                                                                upsert=True)