Index: ow/utilities.py
===================================================================
--- ow/utilities.py	(revision 8c2b0949ae91540ee5c8101b9d5ff39003773da3)
+++ ow/utilities.py	(revision 5ec3a0b5cf5640304a0953320daef2a28bbca9a5)
@@ -1,36 +1,7 @@
 import re
-import os
-import logging
-import calendar
-import shutil
-import time
-from datetime import datetime, timedelta
-from decimal import Decimal
-from shutil import copyfileobj
-from uuid import uuid4
-
+import datetime
 from unidecode import unidecode
 from xml.dom import minidom
-from ZODB.blob import Blob
-from splinter import Browser
-
-from pyramid.i18n import TranslationStringFactory
-
-_ = TranslationStringFactory('OpenWorkouts')
-
-
-log = logging.getLogger(__name__)
-
-
-def get_verification_token():
-    """
-    Generate a new uuid4 verification token we can give a user for
-    verification purposes.
-    uuid4 is a standard that generates a randomly generated token,
-    optimized for a very low chance of collisions. But even if
-    we had a collision, it wouldn't matter - it's simple some users
-    getting the same token in their verification mail.
-    """
-    return uuid4()
+from decimal import Decimal
 
 
@@ -108,8 +79,8 @@
                 rfc3339 = trkpt.getElementsByTagName('time')[0].firstChild.data
                 try:
-                    t = datetime.strptime(
+                    t = datetime.datetime.strptime(
                         rfc3339, '%Y-%m-%dT%H:%M:%S.%fZ')
                 except ValueError:
-                    t = datetime.strptime(
+                    t = datetime.datetime.strptime(
                         rfc3339, '%Y-%m-%dT%H:%M:%SZ')
 
@@ -142,228 +113,2 @@
                     'cad': cad,
                     'atemp': atemp})
-
-
-def semicircles_to_degrees(semicircles):
-    return semicircles * (180 / pow(2, 31))
-
-
-def degrees_to_semicircles(degrees):
-    return degrees * (pow(2, 31) / 180)
-
-
-def miles_to_kms(miles):
-    factor = 0.62137119
-    return miles / factor
-
-
-def kms_to_miles(kms):
-    factor = 0.62137119
-    return kms * factor
-
-
-def meters_to_kms(meters):
-    return meters / 1000
-
-
-def kms_to_meters(kms):
-    return kms * 1000
-
-
-def mps_to_kmph(mps):
-    """
-    Transform a value from meters-per-second to kilometers-per-hour
-    """
-    return mps * 3.6
-
-
-def kmph_to_mps(kmph):
-    """
-    Transform a value from kilometers-per-hour to meters-per-second
-    """
-    return kmph * 0.277778
-
-
-def copy_blob(blob):
-    """
-    Create a copy of a blob object, returning another blob object that is
-    the copy of the given blob file.
-    """
-    new_blob = Blob()
-    if getattr(blob, 'file_extension', None):
-        new_blob.file_extension = blob.file_extension
-    with blob.open('r') as orig_blob, new_blob.open('w') as dest_blob:
-        orig_blob.seek(0)
-        copyfileobj(orig_blob, dest_blob)
-    return new_blob
-
-
-def create_blob(data, file_extension, binary=False):
-    """
-    Create a ZODB blob file from some data, return the blob object
-    """
-    blob = Blob()
-    blob.file_extension = file_extension
-    with blob.open('w') as open_blob:
-        # use .encode() to convert the string to bytes if needed
-        if not binary and not isinstance(data, bytes):
-            data = data.encode('utf-8')
-        open_blob.write(data)
-    return blob
-
-
-def save_map_screenshot(workout, request):
-
-    if workout.has_gpx:
-
-        map_url = request.resource_url(workout, 'map')
-
-        browser = Browser('chrome', headless=True)
-        browser.driver.set_window_size(1300, 436)
-
-        browser.visit(map_url)
-        # we need to wait a moment before taking the screenshot, to ensure
-        # all tiles are loaded in the map.
-        time.sleep(5)
-
-        # splinter saves the screenshot with a random name (even if we do
-        # provide a name) so we get the path to that file and later on we
-        # move it to the proper place
-        splinter_screenshot_path = browser.screenshot()
-
-        current_path = os.path.abspath(os.path.dirname(__file__))
-        screenshots_path = os.path.join(
-            current_path, 'static/maps', str(workout.owner.uid))
-        if not os.path.exists(screenshots_path):
-            os.makedirs(screenshots_path)
-
-        screenshot_path = os.path.join(
-            screenshots_path, str(workout.workout_id))
-        screenshot_path += '.png'
-
-        shutil.move(splinter_screenshot_path, screenshot_path)
-        os.chmod(screenshot_path, 0o644)
-        return True
-
-    return False
-
-
-def timedelta_to_hms(value):
-    """
-    Return hours, minutes, seconds from a timedelta object
-    """
-    hours, remainder = divmod(int(value.total_seconds()), 3600)
-    minutes, seconds = divmod(remainder, 60)
-    return hours, minutes, seconds
-
-
-def get_week_days(day, start_day=1):
-    """
-    Return a list of datetime objects for the days of the week "day" is in.
-
-    day is a datetime object (like in datetime.now() for "today")
-
-    start_day can be used to set if week starts on monday (1) or sunday (0)
-    """
-    first_day = day - timedelta(days=day.isoweekday() - start_day)
-    week_days = [first_day + timedelta(days=i) for i in range(7)]
-    return week_days
-
-
-def get_month_week_number(day):
-    """
-    Given a datetime object (day), return the number of week the day is
-    in the current month (week 1, 2, 3, etc)
-    """
-    weeks = calendar.monthcalendar(day.year, day.month)
-    for week in weeks:
-        if day.day in week:
-            return weeks.index(week)
-
-
-def get_month_names():
-    """
-    Return a list with the names of the months, marked for translation.
-
-    This should be done automatically by the calendar module:
-
-    >>> import calendar
-    >>> calendar.month_name[1]
-    'January'
-    >>>
-
-    But even trying setting the proper locale (using locale.setlocale()),
-    in some operating systems the names are not translated (OpenBSD).
-
-    So, for now, we use this dirty trick
-    """
-    return [
-        '',
-        _('January'),
-        _('February'),
-        _('March'),
-        _('April'),
-        _('May'),
-        _('June'),
-        _('July'),
-        _('August'),
-        _('September'),
-        _('October'),
-        _('November'),
-        _('December')
-    ]
-
-
-def get_week_day_names():
-    """
-    Return a list with the names of the week days, marked for translation.
-
-    As with get_month_names(), this is a dirty workaround for some locale
-    problem in some operating systems
-    """
-    return [
-        _('Monday'),
-        _('Tuesday'),
-        _('Wednesday'),
-        _('Thursday'),
-        _('Friday'),
-        _('Saturday'),
-        _('Sunday'),
-    ]
-
-
-def part_of_day(dt):
-    """
-    Given a datetime object (dt), return which part of the day was it
-    (morning, afternoon, evening, night), translated in the proper
-    """
-    parts = {
-        _('Morning'): (5, 11),
-        _('Afternoon'): (12, 17),
-        _('Evening'): (18, 22),
-        _('Night'): (23, 4)
-    }
-    for key, value in parts.items():
-        if value[0] <= dt.hour <= value[1]:
-            return key
-
-
-def get_available_locale_names():
-    """
-    Return a list of tuples with info about available locale/language
-    names.
-
-    The locale codes and names in this list match the available translations
-    under ow/locale for the UI elements
-    """
-    return [
-        ('en', _('English')),
-        ('es', _('Spanish'))
-    ]
-
-
-def get_gender_names():
-    return [
-        ('male', _('Male')),
-        ('female', _('Female')),
-        ('robot', _('Robot'))
-    ]
