Skip to content

Instantly share code, notes, and snippets.

@cjauvin
Last active November 25, 2018 20:48
Show Gist options
  • Select an option

  • Save cjauvin/7ba5df44c508ea5cb69b73be8e678fd8 to your computer and use it in GitHub Desktop.

Select an option

Save cjauvin/7ba5df44c508ea5cb69b73be8e678fd8 to your computer and use it in GitHub Desktop.

Revisions

  1. cjauvin revised this gist Nov 25, 2018. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions seb.py
    Original file line number Diff line number Diff line change
    @@ -20,3 +20,12 @@ def get_placements():

    if __name__ == '__main__':
    app.run(host='127.0.0.1', port=8080, debug=True)

    # To test:
    # python3 seb.py
    #
    # curl http://127.0.0.1:8080/get_placements
    # <?xml version="1.0" encoding="utf-8"?>
    # <kml xmlns="http://www.opengis.net/kml/2.2">
    # <Placemark>bla</Placemark>
    # </kml>%
  2. cjauvin revised this gist Nov 25, 2018. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions seb.py
    Original file line number Diff line number Diff line change
    @@ -5,17 +5,18 @@

    @app.route('/get_placements')
    def get_placements():
    placements = '<Placemark>bla</Placemark>'
    placements = '<Placemark>bla</Placemark>' # replace with your own placement creation logic
    f = BytesIO() # memory buffer, acting as a file
    # f-strings are new in py3.6+
    content = f'''<?xml version="1.0" encoding="utf-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
    {placements}
    </kml>'''
    # the content string must be of type `bytes` in this context (not `unicode`, which is the default)
    # the content string must be of type `bytes` in this context (not `unicode`, which is the default with py3+)
    f.write(content.encode('utf8'))
    f.seek(0)
    # not sure if `as_attachment` is needed in your context
    return send_file(f, attachment_filename="placement.kml", as_attachment=True)

    if __name__ == '__main__':
    app.run(host='127.0.0.1', port=8080, debug=True)
    app.run(host='127.0.0.1', port=8080, debug=True)
  3. cjauvin created this gist Nov 25, 2018.
    21 changes: 21 additions & 0 deletions seb.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    from flask import Flask, send_file
    from io import BytesIO

    app = Flask(__name__)

    @app.route('/get_placements')
    def get_placements():
    placements = '<Placemark>bla</Placemark>'
    f = BytesIO() # memory buffer, acting as a file
    content = f'''<?xml version="1.0" encoding="utf-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
    {placements}
    </kml>'''
    # the content string must be of type `bytes` in this context (not `unicode`, which is the default)
    f.write(content.encode('utf8'))
    f.seek(0)
    # not sure if `as_attachment` is needed in your context
    return send_file(f, attachment_filename="placement.kml", as_attachment=True)

    if __name__ == '__main__':
    app.run(host='127.0.0.1', port=8080, debug=True)