def get_token(login: Login) -> str: try: acc = CitybikeAccount(login) return acc.get_token() except LoginError: raise HTTPException(status_code=401, detail="Login invalid")
async def get_account( login_bearer: HTTPAuthorizationCredentials = Security(login_bearer)): try: return CitybikeAccount(login_bearer.credentials) except LoginError: raise HTTPException(status_code=401, detail="Login invalid")
def get_uphill_challenge_details(challenge_id: int, acc: CitybikeAccount = Depends(get_account)): details = acc.get_uphill_challenge_detail(challenge_id) if details is None: raise HTTPException(status_code=404, detail="Challenge not found") return details
def accept_uphill_challenge(challenge_id: int, acc: CitybikeAccount = Depends(get_account)): acc.accept_uphill_challenge(challenge_id)
def cancel_current_uphill_challenge( acc: CitybikeAccount = Depends(get_account)): acc.cancel_current_uphill_challenge()
def get_current_uphill_challenge(acc: CitybikeAccount = Depends(get_account)): return acc.get_current_uphill_challenge()
def get_available_uphill_challenges( acc: CitybikeAccount = Depends(get_account)): return acc.get_uphill_challenges()
def get_userinfo(acc: CitybikeAccount = Depends(get_account)): return acc.get_user_info()
def get_rides_since(acc: CitybikeAccount, since: datetime = datetime.min): for r in acc.get_rides(): if r.start_time >= since: yield r else: break