main

 1#!/usr/local/bin/python3
 2import sys
 3import argparse
 4
 5import parse_url
 6import parse_credentials
 7import fb_scrapper
 8
 9def main():
10    """
11    Entrypoint for the program
12
13    This function parses the command line arguments and calls the other functions
14    """
15    parser = argparse.ArgumentParser(description='Facebook Post Comments Scrapper')
16    parser.add_argument('credentials_file', type=str,
17                        help='A txt file with username and password')
18    parser.add_argument('input_file', type=str,
19                        help='A input file with list of urls')
20    parser.add_argument('out_dir', type=str,
21                        help='Output directory to store the comments')
22
23    args = parser.parse_args()
24    if args.credentials_file.endswith('.txt'): # check if the file is a txt file
25        print("Credentials file: " + args.credentials_file)
26    else:
27        print("Credentials file not found")
28        sys.exit(1)
29    if args.input_file.endswith('.txt') | args.input_file.endswith('.csv'):
30        print("Input file: " + args.input_file)
31    else:
32        print("Input file must be a .txt or .csv file")
33        sys.exit(1)
34    if args.out_dir.endswith('/'):
35        print("Output directory: " + args.out_dir)
36    else:
37        print("Output directory must end with /")
38        sys.exit(1)
39    urls = parse_url.main(args.input_file)
40    email, password = parse_credentials.main(args.credentials_file)
41    fb_scrapper.main(email, password, urls, args.out_dir)
42
43
44if __name__ == '__main__':
45    main()
def main():
10def main():
11    """
12    Entrypoint for the program
13
14    This function parses the command line arguments and calls the other functions
15    """
16    parser = argparse.ArgumentParser(description='Facebook Post Comments Scrapper')
17    parser.add_argument('credentials_file', type=str,
18                        help='A txt file with username and password')
19    parser.add_argument('input_file', type=str,
20                        help='A input file with list of urls')
21    parser.add_argument('out_dir', type=str,
22                        help='Output directory to store the comments')
23
24    args = parser.parse_args()
25    if args.credentials_file.endswith('.txt'): # check if the file is a txt file
26        print("Credentials file: " + args.credentials_file)
27    else:
28        print("Credentials file not found")
29        sys.exit(1)
30    if args.input_file.endswith('.txt') | args.input_file.endswith('.csv'):
31        print("Input file: " + args.input_file)
32    else:
33        print("Input file must be a .txt or .csv file")
34        sys.exit(1)
35    if args.out_dir.endswith('/'):
36        print("Output directory: " + args.out_dir)
37    else:
38        print("Output directory must end with /")
39        sys.exit(1)
40    urls = parse_url.main(args.input_file)
41    email, password = parse_credentials.main(args.credentials_file)
42    fb_scrapper.main(email, password, urls, args.out_dir)

Entrypoint for the program

This function parses the command line arguments and calls the other functions