def authorize(request): access_info, errors = request_access_info(code=request.GET['code']) if errors is not None: return views.error( request, "Something went wrong authenticating with FitBit. Please try again." ) user_id = access_info["user_id"] access_token = access_info["access_token"] scope = access_info["scope"] refresh_token = access_info["refresh_token"] expiration_date = fitbit_time.now() + timedelta( seconds=access_info["expires_in"]) expiration_date = fitbit_time.string_for_date(expiration_date) try: user = User.objects.get(fitbit_id=user_id) user.access_token = access_token user.scope = scope user.refresh_token = refresh_token user.access_token_expiration = expiration_date user.save() except: user = User.objects.create(fitbit_id=user_id, access_token=access_token, scope=scope, refresh_token=refresh_token) user.save() users.update_profile(user) devices = device.get_devices_for(user) if devices is None: return views.error( request, "No device on your FitBit account supports silent alarms. Please try again after adding a device to your FitBit account." ) if "sleep" in user.scope: subscription.subscribe(user, "sleep") import alarms if (alarms.user_alarms_count(user) == 8): print "User account is full" return views.alarms_full(request) watervibe.watervibe.register_fitbit_user(user) return views.authorization_success(request, user)
def createMenu(site, schedule_script, scheduled): # pass site url as parameter # get what user wants to do # and call corresponding function while (True): clear() print("COVID19 Tracer with ML prediction") print("1. Get status by Country") print("2. Get status by country and date") print("3. Difference between Latest state and previous one by country") print("4. Get two weeks prediction by specific country") print("5. Get timeline of cases by Country") print("6. Subscribe") print("7. Remove Subscription") print("99. Exit") choice = userInput.getChoice() if (choice==1): country=countrytoCode(userInput.read('Country')) apiParser.parse(tracer.statusCountry(country)) elif (choice==2): country=countrytoCode(userInput.read('Country')) date=userInput.read('Date (YYYY-MM-DD)') apiParser.parse(tracer.statusCountryDate(country, date)) elif (choice==3): country=countrytoCode(userInput.read('Country')) apiParser.parse(tracer.diffCountry(country)) elif (choice==4): country=countrytoCode(userInput.read('Country')) apiParser.listParse(tracer.predictionCountry(country)) elif (choice==5): country=countrytoCode(userInput.read('Country')) apiParser.listParse(tracer.timeCases(country)) elif (choice==6): if (is_admin() or name != 'nt'): # Code of your program here subscription.subscribe(schedule_script, scheduled) else: # Re-run the program with admin rights ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1) elif (choice == 7): if (is_admin() or name != 'nt'): subscription.rmSubscribe(schedule_script, scheduled) else: # Re-run the program with admin rights ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1) elif (choice==99): exit(0) else: print("Not a valid input")
def createMenu(api_path, icon_name, schedule_script): # Creates Menu which is shown to the user # And Taking input from user while (True): clear() print("*******AnimeNotify************") print("1. Subscribe") print("2. Remove Subscription") print("99. Quit") try: choice = int(input("Choice> ")) except ValueError: print("Invalid Choice") continue if (choice == 1): if (is_admin() or name != 'nt'): anime_name = (userInput.read("Name")).lower() subscription.subscribe(api_path, anime_name) else: # Re-run the program with admin rights ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1) elif (choice == 2): if (is_admin() or name != 'nt'): subscription.rmSubscribe() else: # Re-run the program with admin rights ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1) elif (choice == 99): exit() else: print("Invalid Choice")
with open(os.path.join(classdir, 'player.zip'), 'rb') as file_obj: bucket.blob( os.path.join( submissionid, 'player.zip')).upload_from_file(file_obj) except: compile_log_error( submissionid, 'Could not send executable to bucket') logging.info('Compilation succeeded') compile_report_result(submissionid, COMPILE_SUCCESS) else: compile_log_error(submissionid, 'Could not compress compiled classes') else: logging.info('Compilation failed') compile_report_result(submissionid, COMPILE_FAILED) finally: # Clean up working directory try: shutil.rmtree(sourcedir) os.remove(os.path.join(rootdir, 'source.zip')) shutil.rmtree(builddir) except: logging.warning('Could not clean up compilation directory') if __name__ == '__main__': subscription.subscribe(GCLOUD_SUB_COMPILE_NAME, compile_worker)
if game_winner == 'A': wins[0] += 1 elif game_winner == 'B': wins[1] += 1 # We should have as many game wins as games played assert (wins[0] + wins[1] == len(maps.split(','))) logging.info('Game ended. Result {}:{}'.format(wins[0], wins[1])) except: game_log_error(gametype, gameid, 'Could not determine winner') else: if wins[0] > wins[1]: game_report_result(gametype, gameid, GAME_REDWON) elif wins[1] > wins[0]: game_report_result(gametype, gameid, GAME_BLUEWON) else: game_log_error(gametype, gameid, 'Ended in draw, which should not happen') finally: # Clean up working directory try: shutil.rmtree(classdir) shutil.rmtree(builddir) os.remove(os.path.join(rootdir, 'replay.bc20')) except: logging.warning('Could not clean up game execution directory') if __name__ == '__main__': subscription.subscribe(GCLOUD_SUB_GAME_NAME, game_worker)
# # Send package to bucket for storage # if result[0] == 0: # try: # with open(os.path.join(classdir, 'player.zip'), 'rb') as file_obj: # bucket.blob(os.path.join(submissionid, 'player.zip')).upload_from_file(file_obj) # except: # compile_log_error(submissionid, 'Could not send executable to bucket') # logging.info('Compilation succeeded') # compile_report_result(submissionid, COMPILE_SUCCESS) # else: # compile_log_error(submissionid, 'Could not compress compiled classes') # else: # logging.info('Compilation failed') # compile_report_result(submissionid, COMPILE_FAILED) # finally: # # Clean up working directory # try: # shutil.rmtree(sourcedir) # os.remove(os.path.join(rootdir, 'source.zip')) # shutil.rmtree(builddir) # except: # logging.warning('Could not clean up compilation directory') compile_report_result(submissionid, COMPILE_SUCCESS) if __name__ == '__main__': subscription.subscribe(GCLOUD_SUB_COMPILE_NAME, compile_worker, give_up=True)
elif game_winner == 'B': wins[1] += 1 # We should have as many game wins as games played assert (wins[0] + wins[1] == len(maps.split(','))) logging.info('Game ended. Result {}:{}'.format(wins[0], wins[1])) except: game_log_error(gametype, gameid, 'Could not determine winner') else: if wins[0] > wins[1]: game_report_result(gametype, gameid, GAME_REDWON, wins[0], wins[1]) elif wins[1] > wins[0]: game_report_result(gametype, gameid, GAME_BLUEWON, wins[1], wins[0]) else: game_log_error(gametype, gameid, 'Ended in draw, which should not happen') finally: # Clean up working directory try: shutil.rmtree(classdir) shutil.rmtree(builddir) os.remove(os.path.join(rootdir, 'replay.bc20')) except: logging.warning('Could not clean up game execution directory') if __name__ == '__main__': subscription.subscribe(GCLOUD_SUB_GAME_NAME, game_worker, give_up=False)