def checkin(): if request.method == 'POST': identity = request.form['identity'] location = { 'kind': 'latitude#location', 'latitude': float(request.form['latitude']), 'longitude': float(request.form['longitude']), 'accuracy': int(request.form['accuracy']), 'timestampMs': int(time.time() * 1000), } user = g.db.users.find_one({'_id': identity}) if 'locations' not in user: user['locations'] = [] user['locations'].insert(0, location) g.db.users.save(user) rules.check(identity, (location['latitude'], location['longitude'])) return redirect(url_for('user_detail', identity=user['_id'])) else: return render_template('admin/checkin.html')
""" if __name__ == "__main__": conn = Connection(settings.MONGODB_HOST, settings.MONGODB_PORT) users = conn.geocron.users for user in users.find(): if 'locations' not in user: user['locations'] = [] oauth = user.get('oauth', None) if oauth: timestamps = [l['timestampMs'] for l in user['locations']] latitude = Latitude(oauth['token'], oauth['secret']) location = latitude.current_location() if location and 'data' in location: location = location['data'] if 'timestampMs' in location and location['timestampMs'] not in timestamps: user['locations'].append(location) rules.check(user['_id'], (location['latitude'], location['longitude'])) users.save(user) time.sleep(1)
if __name__ == "__main__": conn = Connection(settings.MONGODB_HOST, settings.MONGODB_PORT) users = conn.geocron.users for user in users.find(): if 'locations' not in user: user['locations'] = [] oauth = user.get('oauth', None) if oauth: timestamps = [l['timestampMs'] for l in user['locations']] latitude = Latitude(oauth['token'], oauth['secret']) location = latitude.current_location() if location and 'data' in location: location = location['data'] if 'timestampMs' in location and location[ 'timestampMs'] not in timestamps: user['locations'].append(location) rules.check(user['_id'], (location['latitude'], location['longitude'])) users.save(user) time.sleep(1)