Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def authenticate(username, password):
print("Signing in...")
if password:
icloud = PyiCloudService(username, password)
else:
icloud = PyiCloudService(username)
if icloud.requires_2fa:
print("Two-factor authentication required. Your trusted devices are:")
devices = icloud.trusted_devices
for i, device in enumerate(devices):
print(" %s: %s" % (i, device.get('deviceName',
"SMS to %s" % device.get('phoneNumber'))))
device = click.prompt('Which device would you like to use?', default=0)
device = devices[device]
if not icloud.send_verification_code(device):
print("Failed to send verification code")
sys.exit(1)
def on_intent(request):
api = PyiCloudService(os.environ['APPLE_ID'], os.environ['PASSWORD'])
for iphone in get_iphones(api):
iphone.play_sound()
speechlet_response = build_speechlet_response(
title=request['intent']['name'],
output='Ok, you should be able to hear it beeping now.',
reprompt_text='Ok, you should be able to hear it beeping now.',
should_end_session=True,
)
return build_response(
session_attributes={},
speechlet_response=speechlet_response,
)
def reset_account_icloud(self):
"""Reset an iCloud account."""
icloud_dir = self.hass.config.path("icloud")
if not os.path.exists(icloud_dir):
os.makedirs(icloud_dir)
try:
self.api = PyiCloudService(
self.username, self.password, cookie_directory=icloud_dir, verify=True
)
except PyiCloudFailedLoginException as error:
self.api = None
_LOGGER.error("Error logging into iCloud Service: %s", error)
return
try:
self.devices = {}
self._overridestates = {}
self._intervals = {}
for device in self.api.devices:
status = device.status(DEVICESTATUSSET)
_LOGGER.debug("Device Status is %s", status)
devicename = slugify(status["name"].replace(" ", "", 99))
_LOGGER.info("Adding icloud device: %s", devicename)
# Which password we use is determined by your username, so we
# do need to check for this first and separately.
if not username:
parser.error('No username supplied')
if not password:
password = utils.get_password(
username,
interactive=command_line.interactive
)
if not password:
parser.error('No password supplied')
try:
api = pyicloud.PyiCloudService(
username.strip(),
password.strip()
)
if (
not utils.password_exists_in_keyring(username) and
command_line.interactive and
confirm("Save password in keyring? ")
):
utils.store_password_in_keyring(username, password)
break
except pyicloud.exceptions.PyiCloudFailedLoginException:
# If they have a stored password; we just used it and
# it did not work; let's delete it if there is one.
if utils.password_exists_in_keyring(username):
utils.delete_password_in_keyring(username)
# Which password we use is determined by your username, so we
# do need to check for this first and separately.
if not username:
parser.error('No username supplied')
if not password:
password = utils.get_password(
username,
interactive=command_line.interactive
)
if not password:
parser.error('No password supplied')
try:
api = pyicloud.PyiCloudService(
username.strip(),
password.strip()
)
if (
not utils.password_exists_in_keyring(username) and
command_line.interactive and
confirm("Save password in keyring? ")
):
utils.store_password_in_keyring(username, password)
if api.requires_2sa:
import click
print("Two-step authentication required.",
"Your trusted devices are:")
devices = api.trusted_devices
def find_iphone(text):
try:
api = PyiCloudService(ICLOUD_USERNAME, ICLOUD_PASSWORD)
except PyiCloudFailedLoginException:
tts("Invalid Username & Password")
return
# All Devices
devices = api.devices
# Just the iPhones
iphones = []
for device in devices:
current = device.status()
if "iPhone" in current['deviceDisplayName']:
iphones.append(device)
# The one to ring