-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
81 lines (65 loc) · 2.85 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
78
79
80
81
import csv
from dotenv import load_dotenv
from seek_scraper_utils import *
from datetime import datetime
load_dotenv()
"""
List of countries url.
"""
australia = 'https://www.seek.com.au'
new_zealand = 'https://www.seek.co.nz/'
hong_kong = 'https://hk.jobsdb.com/'
indonesia = 'https://id.jobstreet.com/'
malaysia = 'https://my.jobstreet.com/'
philippines = 'https://www.jobstreet.com.ph/'
singapore = 'https://sg.jobstreet.com/'
thailand = 'https://th.jobsdb.com/'
def main():
driver = configure_webdriver()
country = australia
job_position = 'Banker'
job_location = 'Melbourne'
date_posted = 5
# Create a subdirectory named 'csv_files' if it doesn't exist
csv_dir = os.path.join(os.path.dirname(__file__), 'csv_files')
os.makedirs(csv_dir, exist_ok=True)
sorted_df = None
try:
job_position, total_jobs = search_jobs(driver, country, job_position, job_location, date_posted)
df = scrape_job_data(driver, country, job_position, total_jobs)
if df.empty or df.shape[0] == 1:
print("No results found. Something went wrong.")
subject = 'No Jobs Found on Indeed'
body = """
No jobs were found for the given search criteria.
Please consider the following:
1. Try adjusting your search criteria.
2. If you used English search keywords for non-English speaking countries,
it might return an empty result. Consider using keywords in the country's language.
3. Try more general keyword(s), check your spelling or replace abbreviations with the entire word
Feel free to try a manual search with this link and see for yourself:
Link {}
""".format(driver.current_url)
# You might want to send an email here with the subject and body
else:
sorted_df = sort_data(df)
# Check if there are any jobs before saving the CSV
if not sorted_df.empty:
# Get current date
current_date = datetime.now().strftime("%Y-%m-%d")
# Create filename with date
filename = f"Seek_{job_position}_{job_location}_{current_date}.csv"
# Full path for the CSV file
csv_file = os.path.join(csv_dir, filename)
# Save the CSV file with specific parameters to prevent URL truncation
sorted_df.to_csv(csv_file, index=False, quoting=csv.QUOTE_ALL, escapechar='\\', encoding='utf-8-sig')
print(f"CSV file saved as {csv_file}")
else:
print("No valid data to save.")
finally:
try:
driver.quit()
except Exception as e:
print(f"Error quitting the driver: {e}")
if __name__ == "__main__":
main()