-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_bot.py
More file actions
56 lines (43 loc) · 1.46 KB
/
Copy pathrun_bot.py
File metadata and controls
56 lines (43 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
"""Run the LinkedIn bot from .env without opening the GUI."""
import os
import sys
from dotenv import load_dotenv
load_dotenv(override=True)
from Scripts import constants
from Scripts import selenium_Funct as sf
def load_config_from_env():
constants.username = os.getenv("LINKEDIN_USERNAME", "").strip()
constants.password = os.getenv("LINKEDIN_PASSWORD", "")
constants.commaseparated = os.getenv("LINKEDIN_FIELDS", "").strip()
constants.location = os.getenv("LINKEDIN_LOCATION", "").strip()
constants.upto_page = int(os.getenv("LINKEDIN_PAGES", "1") or "1")
constants.max_connections = int(os.getenv("LINKEDIN_CONNECTIONS", "10") or "10")
def validate_config():
if not constants.username:
return "Set LINKEDIN_USERNAME in .env"
if not constants.password:
return "Set LINKEDIN_PASSWORD in .env"
if not constants.commaseparated:
return "Set LINKEDIN_FIELDS in .env"
if constants.upto_page < 1:
return "LINKEDIN_PAGES must be at least 1"
if constants.max_connections < 0:
return "LINKEDIN_CONNECTIONS cannot be negative"
return None
def main():
load_config_from_env()
error = validate_config()
if error:
print(f"ERROR: {error}", file=sys.stderr)
return 1
try:
sf.main()
finally:
try:
sf.shutdown_browser()
except Exception:
pass
return 0
if __name__ == "__main__":
sys.exit(main())