-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjits.py
67 lines (56 loc) · 1.84 KB
/
jits.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
import argparse, sys, glob
from orgs import common
class Jits:
def __init__(self):
# Getting the list of sites from the filenames in the "orgs" folder
self.website_list = [s[5:-3] for s in glob.glob("orgs/*.py")]
self.website_list.remove("common")
parser = argparse.ArgumentParser(
description="Scrape IT job offers",
usage="""jits.py <command> [<args>]
The most commonly used commands are:
scrape Run the scraping
display Display job offers
info Display the implemented websites
""")
parser.add_argument("command", help="Subcommand to run")
args = parser.parse_args(sys.argv[1:2])
if args.command == "scrape":
self.scrape()
elif args.command == "display":
self.display()
elif args.command == "info":
print("Implemented websites :")
for e in self.website_list:
print(f"- {e}")
else:
print("Unrecognized command")
parser.print_help()
exit(1)
def scrape(self):
parser = argparse.ArgumentParser(description="Run the scraping")
parser.add_argument("--site", "-s", type=str, help="Target a specific website")
args = parser.parse_args(sys.argv[2:])
if args.site in self.website_list:
try:
common.scrape(args.site)
except:
print(f"An error occured while scraping {args.site}")
else:
for s in self.website_list:
try:
common.scrape(s)
except:
print(f"An error occured while scraping {s}")
def display(self):
parser = argparse.ArgumentParser(description="Display job offers")
parser.add_argument("--site", "-s", type=str, help="Target a specific website")
parser.add_argument("--keyword", "-k", type=str, help="Filter on a keyword")
args = parser.parse_args(sys.argv[2:])
if args.site in self.website_list:
common.display(args.site, args.keyword)
else:
for s in self.website_list:
common.display(s, args.keyword)
if __name__ == "__main__":
Jits()