-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
39 lines (28 loc) · 1.17 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
from selenium import webdriver
from dotenv import load_dotenv
import os
import sys
from scrapers import AmazonScraper, CostcoScraper
from InvalidLinkError import InvalidLinkError
from sendEmail import sendEmail
from FileWriter import CsvWriter
if(__name__ == "__main__"):
load_dotenv()
driver = webdriver.Chrome(os.environ['DRIVER_PATH'])
records = []
costcoScraper = CostcoScraper()
amazonScraper = AmazonScraper()
with open(sys.argv[1], "r") as file:
for line in file.readlines():
line = line.strip()
if ("www.costco.ca" in line):
record = costcoScraper.scrapeData(driver, line)
elif ("www.amazon.ca" in line):
record = amazonScraper.scrapeData(driver, line)
else:
raise InvalidLinkError(f"Invalid Link: {line}")
records.append(record);
driver.quit()
csvWriter = CsvWriter()
csvWriter.write(records, os.environ['OUTPUT_FILE_NAME']+".csv")
sendEmail(os.environ['EMAIL_FROM'], os.environ['EMAIL_TO'], os.environ['OUTPUT_FILE_NAME']+".csv", os.environ['EMAIL_SUBJECT'], os.environ["EMAIL_PWD"])