Changeset d6f8304 in OpenWorkouts-current for ow/utilities.py
- Timestamp:
- Feb 11, 2019, 6:55:55 PM (5 years ago)
- Branches:
- current, feature/docs, master
- Children:
- 02aee97
- Parents:
- 93bbb89
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/utilities.py
r93bbb89 rd6f8304 3 3 import logging 4 4 import calendar 5 import subprocess 5 import shutil 6 import time 6 7 from datetime import datetime, timedelta 7 8 from decimal import Decimal … … 11 12 from xml.dom import minidom 12 13 from ZODB.blob import Blob 14 from splinter import Browser 15 13 16 14 17 log = logging.getLogger(__name__) … … 192 195 193 196 194 def save_map_screenshot(workout): 197 def save_map_screenshot(workout, request): 198 195 199 if workout.has_gpx: 200 201 map_url = request.resource_url(workout, 'map') 202 203 browser = Browser('chrome', headless=True) 204 browser.driver.set_window_size(1300, 436) 205 206 browser.visit(map_url) 207 # we need to wait a moment before taking the screenshot, to ensure 208 # all tiles are loaded in the map. 209 time.sleep(5) 210 211 # splinter saves the screenshot with a random name (even if we do 212 # provide a name) so we get the path to that file and later on we 213 # move it to the proper place 214 splinter_screenshot_path = browser.screenshot() 215 196 216 current_path = os.path.abspath(os.path.dirname(__file__)) 197 tool_path = os.path.join(current_path, '../bin/screenshot_map')198 199 217 screenshots_path = os.path.join( 200 218 current_path, 'static/maps', str(workout.owner.uid)) … … 206 224 screenshot_path += '.png' 207 225 208 subprocess.run( 209 [tool_path, str(workout.owner.uid), str(workout.workout_id), 210 screenshot_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) 226 shutil.move(splinter_screenshot_path, screenshot_path) 211 227 212 228 return True
Note: See TracChangeset
for help on using the changeset viewer.