-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
77 lines (63 loc) · 1.83 KB
/
main.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import logging as log
from datetime import date
from email import message
from logging import error
from time import strftime
import pandas as pd
import yaml
from linkedin import linkedin
from mailer import send_email, send_email_with_df
from naukri import naukri
log.basicConfig(
format="%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s",
level=log.INFO,
)
with open("config.yaml", "r") as file:
tmp = yaml.safe_load(file)
send_from = tmp["from"]["mail"]
send_password = tmp["from"]["password"]
send_subject = tmp["from"]["subject"]
send_subject = f"{date.today().strftime('%B %d, %Y')} {send_subject}"
send_to = tmp["to"]["mail"]
dev_mail = tmp["dev"]["mail"]
print(send_subject)
dataframes = []
file_names = []
error_message = ""
try:
log.info(f"Trying to scrape linkedin")
linked_df = linkedin()
dataframes.append(linked_df)
file_names.append("linkedin")
except Exception as e:
log.info(f"Linkedin failed!!!, {e}")
error_message = f"{error_message}Linkedin Failed!!!\n{e}\n"
try:
log.info(f"Trying to scrape naukri")
naukri_df = naukri()
dataframes.append(naukri_df)
file_names.append("naukri")
except Exception as e:
log.info(f"Naukri failed!!!, {e}")
error_message = f"{error_message}Naukri Failed!!!\n{e}\n"
if len(error_message) == 0:
log.info(f"Sending scraped data")
send_email_with_df(
dataframes,
file_names,
send_from,
send_password,
send_to,
send_subject,
)
log.info(f"Sent data. Good Bye for now!")
else:
log.info(f"Sending Error message to dev, {dev_mail}")
send_email(
send_from,
send_password,
dev_mail,
f"{date.today().strftime('%B %d, %Y')} Scrape Failed",
error_message,
)
log.info(f"Sent mail to dev, killing myself to be fixed soon!")