def handle(self, *args, **options): for line in open(options['infile']): line = line.strip().split(options['delimiter']) oh_id = line[0] oh_refresh_token = line[1] moves_refresh_token = line[2] if len(OpenHumansMember.objects.filter(oh_id=oh_id)) == 0: oh_member = OpenHumansMember.create( oh_id=oh_id, access_token="mock", refresh_token=oh_refresh_token, expires_in=-3600) oh_member.save() oh_member._refresh_tokens( client_id=settings.OPENHUMANS_CLIENT_ID, client_secret=settings.OPENHUMANS_CLIENT_SECRET) oh_member = OpenHumansMember.objects.get(oh_id=oh_id) moves_member = DataSourceMember( access_token="mock", refresh_token=moves_refresh_token, token_expires=DataSourceMember.get_expiration(-3600)) moves_member.user = oh_member moves_member._refresh_tokens( client_id=settings.MOVES_CLIENT_ID, client_secret=settings.MOVES_CLIENT_SECRET) process_moves.delay(oh_member.oh_id)
def handle(self, *args, **options): users = DataSourceMember.objects.all() for moves_user in users: if moves_user.last_updated < (arrow.now() - timedelta(days=4)): oh_id = moves_user.user.oh_id process_moves.delay(oh_id) else: print("didn't update {}".format(moves_user.moves_id))
def update_data(request): if request.method == "POST" and request.user.is_authenticated: oh_member = request.user.oh_member process_moves.delay(oh_member.oh_id) moves_member = oh_member.datasourcemember moves_member.last_submitted = arrow.now().format() moves_member.save() messages.info(request, ("An update of your Moves data has been started! " "It can take some minutes before the first data is " "available. Reload this page in a while to find your " "data")) return redirect('/dashboard')
def moves_complete(request): """ Receive user from Moves. Store data, start processing. """ logger.debug("Received user returning from Moves.") # Exchange code for token. # This creates an OpenHumansMember and associated user account. code = request.GET.get('code', '') ohmember = request.user.oh_member moves_member = moves_code_to_member(code=code, ohmember=ohmember) if moves_member: messages.info(request, "Your Moves account has been connected") process_moves.delay(ohmember.oh_id) return redirect('/dashboard') logger.debug('Invalid code exchange. User returned to starting page.') messages.info(request, ("Something went wrong, please try connecting your " "Moves account again")) return redirect('/dashboard')