Exemplo n.º 1
0
def my_plan(user, password):
    med_session = MedicoverSession(username=user, password=password)
    try:
        med_session.log_in()
    except Exception:
        click.secho("Unsuccessful logging in", fg="red")
        return
    click.echo("Logged in")
    plan = med_session.get_plan()

    with open("plan.tsv", mode="wt", encoding="utf-8") as f:
        f.write(plan)
Exemplo n.º 2
0
def my_appointments(user, password):
    med_session = MedicoverSession(username=user, password=password)
    try:
        med_session.log_in()
    except Exception:
        click.secho("Unsuccessful logging in", fg="red")
        return
    click.echo("Logged in")
    appointments = med_session.get_appointments()

    with open("appointments.json", mode="wt", encoding="utf-8") as f:
        json.dump(appointments, f)
Exemplo n.º 3
0
def my_appointments(user, password):
    med_session = MedicoverSession(username=user, password=password)
    try:
        med_session.log_in()
    except Exception:
        click.secho(f"Unsuccessful logging in as {user}", fg="red")
        return
    click.echo(f"Logged in as {user}")
    appointments = med_session.get_appointments()

    planned_appointments = list(
        filter(
            lambda a: datetime.strptime(a.appointment_datetime,
                                        "%Y-%m-%dT%H:%M:%S") >= now,
            appointments))
    if planned_appointments:
        click.echo("Showing only planned appointments:")
        for planned_appointment in planned_appointments:
            echo_appointment(planned_appointment)
    else:
        click.echo("No planned appointments.")
Exemplo n.º 4
0
def find_appointment(user, password, region, bookingtype, specialization,
                     clinic, doctor, start_date, service, interval,
                     enable_notifier, notification_title):

    valid = validate_arguments(bookingtype=bookingtype,
                               specialization=specialization,
                               service=service)

    if not valid:
        return

    iteration_counter = 1
    med_session = MedicoverSession(username=user, password=password)

    try:
        med_session.log_in()
    except Exception:
        click.secho('Unsuccessful logging in', fg='red')
        return

    click.echo('Logged in')

    med_session.load_search_form()

    while interval > 0 or iteration_counter < 2:
        appointments = med_session.search_appointments(
            region=region,
            bookingtype=bookingtype,
            specialization=specialization,
            clinic=clinic,
            doctor=doctor,
            start_date=start_date,
            service=service)

        if not appointments:
            click.echo(
                click.style(
                    f'(iteration: {iteration_counter}) No results found',
                    fg='yellow'))
        else:
            process_appointments(appointments,
                                 iteration_counter,
                                 notifier=enable_notifier,
                                 notification_title=notification_title)

        iteration_counter += 1
        time.sleep(interval * 60)
Exemplo n.º 5
0
def find_appointment(user, password, region, specialization, clinic,
                     start_date, interval):
    counter = 0
    med_session = MedicoverSession(username=user, password=password)

    try:
        r = med_session.log_in()
    except Exception:
        click.secho('Unsuccessful logging in', fg='red')
        return

    click.echo('Logged in')

    med_session.load_search_form()  # TODO: can I get rid of it?

    while interval > 0 or counter < 1:
        appointments = med_session.search_appointments(
            region=region,
            specialization=specialization,
            clinic=clinic,
            start_date=start_date)

        if not appointments:
            click.echo(
                click.style(f'(iteration: {counter}) No results found',
                            fg='yellow'))
        else:
            applen = len(appointments)
            click.echo(
                click.style(
                    f'(iteration: {counter}) Found {applen} appointments',
                    fg='green',
                    blink=True))
            for appointment in appointments:
                click.echo(
                    appointment.appointment_datetime + ' ' +
                    click.style(appointment.doctor_name, fg='bright_green') +
                    ' ' + appointment.clinic_name)
        counter += 1
        time.sleep(interval * 60)
Exemplo n.º 6
0
def find_appointment(
    user,
    password,
    region,
    bookingtype,
    specialization,
    clinic,
    doctor,
    start_date,
    end_date,
    start_time,
    end_time,
    service,
    interval,
    days_ahead,
    enable_notifier,
    notification_title,
):

    if end_date:
        start_date_dt = datetime.strptime(start_date, "%Y-%m-%d")
        end_date_dt = datetime.strptime(end_date, "%Y-%m-%d")
        diff = end_date_dt - start_date_dt
        days_ahead = diff.days

    valid = validate_arguments(bookingtype=bookingtype,
                               specialization=specialization,
                               service=service)

    if not valid:
        return

    iteration_counter = 1
    med_session = MedicoverSession(username=user, password=password)

    try:
        med_session.log_in()
    except Exception:
        click.secho("Unsuccessful logging in", fg="red")
        return

    click.echo("Logged in")

    med_session.load_search_form()

    while interval > 0 or iteration_counter < 2:
        appointments = []
        start_date_param = start_date
        for _ in range(days_ahead):
            found_appointments = med_session.search_appointments(
                region=region,
                bookingtype=bookingtype,
                specialization=specialization,
                clinic=clinic,
                doctor=doctor,
                start_date=start_date_param,
                end_date=end_date,
                start_time=start_time,
                end_time=end_time,
                service=service,
            )

            if not found_appointments:
                break

            appointment_datetime = found_appointments[-1].appointment_datetime
            appointment_datetime = datetime.strptime(appointment_datetime,
                                                     "%Y-%m-%dT%H:%M:%S")
            appointment_datetime = appointment_datetime + timedelta(days=1)
            start_date_param = appointment_datetime.date().isoformat()
            appointments.extend(found_appointments)

        if not appointments:
            click.echo(
                click.style(
                    f"(iteration: {iteration_counter}) No results found",
                    fg="yellow"))
        else:
            process_appointments(
                appointments,
                iteration_counter,
                notifier=enable_notifier,
                notification_title=notification_title,
            )

        iteration_counter += 1
        time.sleep(interval * 60)
Exemplo n.º 7
0
def find_appointment(user, password, region, bookingtype, specialization,
                     service, clinic, doctor, start_date, interval,
                     pushover_token, pushover_user, pushover_device,
                     pushover_msgtitle):

    counter = 0
    med_session = MedicoverSession(username=user, password=password)

    # Checking if pushover is enabled and notifications should be send later
    if pushover_user and pushover_token:
        try:
            client = Client(user_key=pushover_user, api_token=pushover_token)
            pushover_notification = True
        except Exception:
            click.secho('Pushover not initialized correctly', fg='red')
            return
    else:
        pushover_notification = False

    try:
        med_session.log_in()
    except Exception:
        click.secho('Unsuccessful logging in', fg='red')
        return

    click.echo(f'{now_formatted_logging}: Logged in {pushover_msgtitle}')

    med_session.load_search_form()  # TODO: can I get rid of it?

    while interval > 0 or counter < 1:
        notification = ""
        notificationcounter = 0
        for c in clinic:
            for d in doctor:
                appointments = med_session.search_appointments(
                    region=region,
                    bookingtype=bookingtype,
                    specialization=specialization,
                    service=service,
                    clinic=c,
                    doctor=d,
                    start_date=start_date)

                if not appointments:
                    click.echo(
                        click.style(
                            f'(iteration: {counter}) No results found ' +
                            pushover_msgtitle,
                            fg='yellow'))
                else:
                    applen = len(appointments)
                    click.echo(
                        click.style(
                            f'(iteration: {counter}) Found {applen} appointments '
                            + pushover_msgtitle,
                            fg='green',
                            blink=True))
                    for appointment in appointments:
                        appointmentcheck = user + appointment.appointment_datetime + appointment.doctor_name
                        click.echo(appointment.appointment_datetime + ' ' +
                                   click.style(appointment.doctor_name,
                                               fg='bright_green') + ' ' +
                                   appointment.clinic_name)
                        #Pusover notifications message generation - will be generated only for newly found appointements
                        if pushover_notification:
                            try:
                                # TODO: replace shelves with SQL as concurency will fail
                                # TODO: crude workaround to create shelve if not existing
                                visistshelve = shelve.open('./visits.db')
                                alreadynotified = appointmentcheck in list(
                                    visistshelve.values())
                                visistshelve.close()
                            except Exception:
                                click.secho(
                                    'Problem in Reading stored appointments',
                                    fg='red')
                                return

                            if not alreadynotified:
                                notificationcounter += 1
                                notification = notification + '<b>' + appointment.appointment_datetime + '</b> <font color="#0000ff">' + appointment.doctor_name + '</font> ' + appointment.clinic_name + '\n'
                                try:
                                    visistshelve = shelve.open('./visits.db')
                                    visistshelve[
                                        appointmentcheck] = appointmentcheck
                                    visistshelve.close()
                                except Exception:
                                    click.secho(
                                        'Problem in Writing appointments to storage',
                                        fg='red')
                                    return

        #Pushover notification final trim (max 1024 chars) and delivery
        if pushover_notification and notificationcounter > 0:
            if len(notification) > 1020:
                notification = notification[
                    0:
                    960] + '<b><font color="#ff0000"> + more appointments online</font></b>'
            if len(pushover_msgtitle) > 0:
                pushover_msgtitle = pushover_msgtitle + ': '
            client.send_message(notification,
                                title=pushover_msgtitle + "Found " +
                                str(notificationcounter) + " appointments",
                                device=pushover_device,
                                html=1)

        counter += 1
        # TODO: Time to sleep should not be over 10 minutes as this is maximum time for Medicover session
        time.sleep(interval * 60)

    # Leveraging existing function as if it's running i.e. via Cron ther may be too many sessions left open
    try:
        r = med_session.log_out()
    except Exception:
        click.secho('Logout problems', fg='red')
        return