def move_import(): xmlfiles = request.files.getlist('files') imported_moves = [] for xmlfile in xmlfiles: filename = xmlfile.filename if filename: app.logger.info("importing '%s'" % filename) move_id = imports.move_import(xmlfile, filename, current_user, request.form) if move_id: imported_moves.append(move_id) if imported_moves and current_user.has_strava(): after = min(imported_moves, key=lambda move: move.date_time ).date_time - strava.MAX_DATE_TIME_OFFSET before = max(imported_moves, key=lambda move: move.date_time ).date_time + strava.MAX_DATE_TIME_OFFSET app.logger.debug("trying to find Strava activities in (%s, %s)" % (before, after)) associated_activities, known_activities, new_activities = strava.associate_activities( current_user, before=before, after=after) if len(associated_activities) == 1: flash("associated with Strava activity %d" % associated_activities[0][0].id) elif len(associated_activities) > 1: flash("associated %d Strava activities" % len(associated_activities)) else: flash('found no Strava activities to associate with', 'warning') if imported_moves: if len(imported_moves) == 1: move_id = imported_moves[0] flash("imported '%s': move %d" % (xmlfile.filename, move_id.id)) return redirect(url_for('move', id=move_id.id)) else: flash("imported %d moves" % len(imported_moves)) return redirect(url_for('moves')) else: model = {'has_strava': current_user.has_strava()} if current_user.has_strava(): associated_activities, known_activities, new_activities = strava.associate_activities( current_user) model['new_strava_activities'] = new_activities model['associated_strava_activities'] = associated_activities model['known_strava_activities'] = known_activities elif 'STRAVA_CLIENT_ID' in app.config: client = stravalib.client.Client() client_id_ = app.config['STRAVA_CLIENT_ID'] strava_authorize_url = client.authorization_url( client_id=client_id_, redirect_uri=url_for('strava_authorized', _external=True), scope='activity:read_all') model['strava_authorize_url'] = strava_authorize_url return render_template('import.html', **model)
def move_import(): xmlfiles = request.files.getlist('files') imported_moves = [] for xmlfile in xmlfiles: filename = xmlfile.filename if filename: app.logger.info("importing '%s'" % filename) move_id = imports.move_import(xmlfile, filename, current_user, request.form) if move_id: imported_moves.append(move_id) if imported_moves and current_user.has_strava(): after = min(imported_moves, key=lambda move: move.date_time).date_time - strava.MAX_DATE_TIME_OFFSET before = max(imported_moves, key=lambda move: move.date_time).date_time + strava.MAX_DATE_TIME_OFFSET app.logger.debug("trying to find Strava activities in (%s, %s)" % (before, after)) associated_activities, known_activities, new_activities = strava.associate_activities(current_user, before=before, after=after) if len(associated_activities) == 1: flash(u"associated with Strava activity %d" % associated_activities[0][0].id) elif len(associated_activities) > 1: flash(u"associated %d Strava activities" % len(associated_activities)) else: flash(u'found no Strava activities to associate with', 'warning') if imported_moves: if len(imported_moves) == 1: move_id = imported_moves[0] flash("imported '%s': move %d" % (xmlfile.filename, move_id.id)) return redirect(url_for('move', id=move_id.id)) else: flash("imported %d moves" % len(imported_moves)) return redirect(url_for('moves')) else: model = {'has_strava': current_user.has_strava()} if current_user.has_strava(): associated_activities, known_activities, new_activities = strava.associate_activities(current_user) model['new_strava_activities'] = new_activities model['associated_strava_activities'] = associated_activities model['known_strava_activities'] = known_activities elif 'STRAVA_CLIENT_ID' in app.config: client = stravalib.client.Client() client_id_ = app.config['STRAVA_CLIENT_ID'] strava_authorize_url = client.authorization_url(client_id=client_id_, redirect_uri=url_for('strava_authorized', _external=True), scope='view_private') model['strava_authorize_url'] = strava_authorize_url return render_template('import.html', **model)
def move_import(): xmlfiles = request.files.getlist('files') imported_moves = [] for xmlfile in xmlfiles: filename = xmlfile.filename if filename: app.logger.info("importing '%s'" % filename) move = imports.move_import(xmlfile, filename, current_user) if move: imported_moves.append(move) if imported_moves: if len(imported_moves) == 1: move = imported_moves[0] flash("imported '%s': move %d" % (xmlfile.filename, move.id)) return redirect(url_for('move', id=move.id)) else: flash("imported %d moves" % len(imported_moves)) return redirect(url_for('moves')) else: return render_template('import.html')
def run(self, username, filename): user = User.query.filter_by(username=username).one() with open(filename, "r") as f: move = move_import(f, filename, user) if move: print("imported move %d" % move.id)
def run(self, username, filename): user = User.query.filter_by(username=username).one() with open(filename, 'r') as f: move = move_import(f, filename, user) if move: print("imported move %d" % move.id)