parse_credentials

 1#!/usr/local/bin/python3
 2import re
 3
 4
 5def _validate_email(email):
 6    """
 7    validate the email
 8    regex to check for valid email
 9    """
10    return re.match(r"[^@]+@[^@]+\.[^@]+", email)
11
12
13def main(input_file):
14    """
15    call the _parse_urls function
16    print the number of urls parsed
17    """
18    try:
19        with open(input_file, 'r') as f:
20            EMAIL = f.readline().split('"')[1]
21            PASSWORD = f.readline().split('"')[1]
22    except FileNotFoundError:
23        print("Credentials file not found")
24        exit()
25    except IndexError:
26        print("Credentials file is empty")
27        exit()
28    if _validate_email(EMAIL):
29        print("Successfully parsed email")
30    else:
31        print("Invalid email")
32        exit()
33    print("Successfully parsed password")
34    return EMAIL, PASSWORD
35
36
37if __name__ == '__main__':
38    print("This script is not meant to be run directly")
def main(input_file):
14def main(input_file):
15    """
16    call the _parse_urls function
17    print the number of urls parsed
18    """
19    try:
20        with open(input_file, 'r') as f:
21            EMAIL = f.readline().split('"')[1]
22            PASSWORD = f.readline().split('"')[1]
23    except FileNotFoundError:
24        print("Credentials file not found")
25        exit()
26    except IndexError:
27        print("Credentials file is empty")
28        exit()
29    if _validate_email(EMAIL):
30        print("Successfully parsed email")
31    else:
32        print("Invalid email")
33        exit()
34    print("Successfully parsed password")
35    return EMAIL, PASSWORD

call the _parse_urls function print the number of urls parsed