Esempio n. 1
0
    def upload(self, track):

        _open_url(self.browser, _URL_UPLOAD)

        try:
            self.browser.select_form(
                predicate=lambda f: 'action' in f.attrs and \
                f.attrs['action'] == '/upload/files')
        except mechanize.FormNotFoundError as e:
            raise StravaError('Upload form not found')


        data = tcx.track_to_tcx(track, fake_garmin_device= \
                                      self.fake_garmin_device,
                                    no_laps=self.no_laps)

        self.browser.form.add_file(StringIO.StringIO(data), 'text/plain',
                                   track.name + '.tcx')

        try:
            self.browser.submit()
        except mechanize.HTTPError as e:
            raise StravaError(str(e))

        resp = _get_response(self.browser)

        if len(resp) != 1:
            raise StravaError('Unexpected response')

        resp = resp[0]

        if 'error' in resp and resp['error'] is not None:
            raise StravaError(resp['error'])

        return UploadStatus(self.browser, resp['id'])
Esempio n. 2
0
    def upload(self, track):

        data = json.dumps({
            'token' : self.token,
            'type' : 'tcx',
            'data' : tcx.track_to_tcx(track),
            'activity_type' : 'ride',
        })

        req = urllib2.Request(_URL_UPLOAD, data,
                               {'Content-Type' : 'application/json'})

        resp = _req(req)

        if 'error' in resp:
            raise StravaError(resp['error'])

        return UploadStatus(self.token, resp['upload_id'])
Esempio n. 3
0
    def upload(self, track):

        _open_url(self.browser, _URL_UPLOAD)

        try:
            self.browser.select_form(
                predicate=lambda f: 'action' in f.attrs and \
                f.attrs['action'] == '/upload/files')
        except mechanize.FormNotFoundError as e:
            raise StravaError('Upload form not found')


        data = tcx.track_to_tcx(track, fake_garmin_device= \
                                      self.fake_garmin_device,
                                    no_laps=self.no_laps)

        self.browser.form.add_file(StringIO.StringIO(data),
                                   'text/plain',
                                   track.name + '.tcx')

        try:
            self.browser.submit()
        except mechanize.HTTPError as e:
            raise StravaError(str(e))

        resp = _get_response(self.browser)

        if len(resp) != 1:
            raise StravaError('Unexpected response')

        resp = resp[0]

        if 'error' in resp and resp['error'] is not None:
            raise StravaError(resp['error'])

        return UploadStatus(self.browser, resp['id'])