itsmaarouf / bls-appointment-scripts-helper

A script to check the BLS Appointment slots, Auto submit and notify by a sound from browser
https://morocco.blsspainvisa.com/spanish/index.php
129 stars 87 forks source link

I ported this to Python Code for "individual Appointment + Payment Receipt + BLS alert + Auto Page Reload on Error". #9

Open imedox opened 1 year ago

imedox commented 1 year ago

*****

pip install requests beautifulsoup4

*****

- The code uses the requests library to make HTTP requests and the BeautifulSoup library for HTML parsing. It retrieves the web page, extracts the necessary information from the HTML, and performs actions based on the extracted data. It also handles updating form fields and submitting the form.

*****

- Make sure to replace 'YOUR_URL' in the url variable with the actual URL you want to use. Additionally, install the necessary libraries if not already installed: requests, bs4 (BeautifulSoup), pyperclip, and playsound.

*****

- The code will first check if there is a problem loading the page based on the title. If there is a problem, it will refresh the page and try again. If there is no problem loading, it will check if the specified element is present. If the element is found, it will process it accordingly. Otherwise, it will refresh the page.

*****

import requests from bs4 import BeautifulSoup import time import pyperclip from playsound import playsound

def main(): url = 'YOUR_URL' time_delay = 1 # in seconds

while True:
    html = get_web_page(url)
    title = extract_title(html)

    # Check if the page has a problem loading
    if is_problem_loading_page(title):
        print("Problem loading page. Refreshing...")
        time.sleep(time_delay)
        continue

    # Check if the specified element is present
    if is_element_present(html):
        process_element(html)
    else:
        print("Element not found. Refreshing...")

    print("End of code")
    time.sleep(time_delay)

def get_web_page(url): headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36' } response = requests.get(url, headers=headers) return response.text

def extract_title(html): soup = BeautifulSoup(html, 'html.parser') return soup.title.text.strip() if soup.title else ''

def is_problem_loading_page(title):

List of titles indicating a problem loading the page

problem_titles = ['Problem loading page']

return title in problem_titles

def is_element_present(html): soup = BeautifulSoup(html, 'html.parser')

Check if the specified element is present

return bool(soup.find('your_element_selector'))

def process_element(html):

Rest of your code for processing the element

table = extract_table_code(html)
datee = extract_date_from_table(table)
fin_date = format_date_for_input(datee)

if fin_date and not get_input_value(html, 'app_date'):
    update_input_value(url, 'app_date', fin_date)
else:
    fill_form_fields(url)

if is_payment_page(html):
    token = extract_payment_token(html)
    payment_url = generate_payment_url(token)
    print(payment_url)
    copy_to_clipboard(payment_url)

play_alert_sound(html)

def extract_table_code(html): soup = BeautifulSoup(html, 'html.parser') script_tags = soup.find_all('script')

for script_tag in script_tags:
    if 'available_dates' in script_tag.text:
        return script_tag.text

return ''

def extract_date_from_table(table): bgn = table.find('available_dates') + 20 end = table.find('fullCapicity_dates') - 9 table_code = table[bgn:end] return table_code[:10] if table_code else ''

def format_date_for_input(datee): if datee: dd = datee[0:2] mm = datee[3:5] yyyy = datee[6:10] return '-'.join([yyyy, mm, dd])

return ''

def get_input_value(html, input_id): soup = BeautifulSoup(html, 'html.parser') input_element = soup.find('input', {'id': input_id}) return input_element.get('value') if input_element else ''

def update_input_value(url, input_id, value): payload = { input_id: value } headers = { 'Content-Type': 'application/x-www-form-urlencoded' } response = requests.post(url, data=payload, headers=headers)

def is_payment_page(html): soup = BeautifulSoup(html, 'html.parser') return soup.find(id='print') is not None

def extract_payment_token(html): soup = BeautifulSoup(html, 'html.parser') token_input = soup.find('input', {'name': 'paymentLinkToken'}) return token_input['value'] if token_input else ''

def generate_payment_url(token): payment_url = f"https://payment.cmi.co.ma/fim/paymentLinkService?token={token}" return payment_url

def copy_to_clipboard(text): pyperclip.copy(text) print("Copied URL to clipboard")

def play_alert_sound(html): soup = BeautifulSoup(html, 'html.parser') if soup.select('.day.activeClass'): playsound('https://www.soundjay.com/mechanical/sounds/smoke-detector-1.mp3')

if name == 'main': main()

SwapnilSoni1999 commented 1 year ago

Have you tested this?

Sabirue commented 1 year ago

On Wed, 21 Jun 2023 at 16:16, Swapnil Soni @.***> wrote:

Have you tested this?

— Reply to this email directly, view it on GitHub https://github.com/itsmaarouf/bls-appointment-scripts-helper/issues/9#issuecomment-1601034474, or unsubscribe https://github.com/notifications/unsubscribe-auth/BATNXBFLLLOGNACGKV2ASR3XMMF37ANCNFSM6AAAAAAYSI3AVE . You are receiving this because you are subscribed to this thread.Message ID: @.*** com>

No dates were today in the morning I wasn't ready

SwapnilSoni1999 commented 1 year ago

@imedox okay but does it parses the open dates ?

Sabirue commented 1 year ago

On Wed, 21 Jun 2023 at 19:18, Swapnil Soni @.***> wrote:

@imedox https://github.com/imedox okay but does it parses the open dates ?

— Reply to this email directly, view it on GitHub https://github.com/itsmaarouf/bls-appointment-scripts-helper/issues/9#issuecomment-1601357719, or unsubscribe https://github.com/notifications/unsubscribe-auth/BATNXBFEQEM4FUGUL4U2QEDXMM3GJANCNFSM6AAAAAAYSI3AVE . You are receiving this because you are subscribed to this thread.Message ID: @.*** com>

I didn’t try because in the morning when appointments were opened I wasn’t the computer operator because I was out of the house

imedox commented 1 year ago

Mod DZ Active : salam 3alikoum, ana dert portage ta3 code ta3 habibna Hamza barek, te9der tmodifieh kima t7ab.

Mod DZ Disables : The Answer it should be!

abdelhak081995 commented 1 year ago

salem alykoum khawti khasni script ta3 bls algerie allah y7fadkoum

Djoe281 commented 1 year ago

@imedox SVP nouveau script BLS ALGER

imedox commented 1 year ago

Dsl kyo, j'ai abandonné ce projet.

Djoe281 commented 1 year ago

Pourquoi Abandonné il est tres actif

Djugurta DJOUDER

Technicien Supérieur en Maintenance des Systèmes Informatiques Infographe & Designer

Golden Passementerie Louahadj Abdelaziz

Atelier Fabrication des rubans

Haouche Mourad grand foret 03 groupe 964 reghaia 16063 Alger

Mob : 0661 80 44 49 – @.***

E-mail : @. - @.

Le mar. 10 oct. 2023 à 14:42, imedox @.***> a écrit :

Dsl kyo, j'ai abandonné ce projet.

— Reply to this email directly, view it on GitHub https://github.com/itsmaarouf/bls-appointment-scripts-helper/issues/9#issuecomment-1755455450, or unsubscribe https://github.com/notifications/unsubscribe-auth/BDDSAUN3UOKCIAHTT7P5SUDX6VGDNAVCNFSM6AAAAAAYSI3AVGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJVGQ2TKNBVGA . You are receiving this because you commented.Message ID: @.***>