jobdraft 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. jobdraft/__init__.py +3 -0
  2. jobdraft/__main__.py +3 -0
  3. jobdraft/checks.py +239 -0
  4. jobdraft/cli.py +230 -0
  5. jobdraft/constants.py +57 -0
  6. jobdraft/db.py +287 -0
  7. jobdraft/demo/__init__.py +79 -0
  8. jobdraft/demo/samples.py +141 -0
  9. jobdraft/export.py +49 -0
  10. jobdraft/fingerprint.py +88 -0
  11. jobdraft/flow.py +328 -0
  12. jobdraft/letter.py +327 -0
  13. jobdraft/llm/__init__.py +1 -0
  14. jobdraft/llm/client.py +216 -0
  15. jobdraft/llm/presets.py +89 -0
  16. jobdraft/llm/prompts.py +353 -0
  17. jobdraft/llm/schemas.py +236 -0
  18. jobdraft/llm/tasks.py +103 -0
  19. jobdraft/locations.py +87 -0
  20. jobdraft/mail.py +137 -0
  21. jobdraft/modal_server.py +75 -0
  22. jobdraft/modal_setup.py +81 -0
  23. jobdraft/resume.py +66 -0
  24. jobdraft/scoring.py +78 -0
  25. jobdraft/security.py +124 -0
  26. jobdraft/settings.py +206 -0
  27. jobdraft/uninstall.py +45 -0
  28. jobdraft/util.py +68 -0
  29. jobdraft/web/__init__.py +1 -0
  30. jobdraft/web/app.py +514 -0
  31. jobdraft/web/static/app.css +70 -0
  32. jobdraft/web/static/app.js +64 -0
  33. jobdraft/web/static/favicon.svg +1 -0
  34. jobdraft/web/templates/base.html +35 -0
  35. jobdraft/web/templates/error.html +4 -0
  36. jobdraft/web/templates/job.html +113 -0
  37. jobdraft/web/templates/jobs.html +37 -0
  38. jobdraft/web/templates/login.html +14 -0
  39. jobdraft/web/templates/new.html +21 -0
  40. jobdraft/web/templates/settings.html +147 -0
  41. jobdraft/wording.py +121 -0
  42. jobdraft-0.1.0.dist-info/METADATA +189 -0
  43. jobdraft-0.1.0.dist-info/RECORD +47 -0
  44. jobdraft-0.1.0.dist-info/WHEEL +5 -0
  45. jobdraft-0.1.0.dist-info/entry_points.txt +2 -0
  46. jobdraft-0.1.0.dist-info/licenses/LICENSE +21 -0
  47. jobdraft-0.1.0.dist-info/top_level.txt +1 -0
jobdraft/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """jobdraft: paste a job, get an honest draft in Gmail. You press Send."""
2
+
3
+ __version__ = "0.1.0"
jobdraft/__main__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ raise SystemExit(main())
jobdraft/checks.py ADDED
@@ -0,0 +1,239 @@
1
+ """Checks on the model's part of a letter.
2
+
3
+ Your facts are copied into the letter word for word, so what the model writes —
4
+ the sentence about the posting and the choice of facts — is where a letter can go
5
+ wrong. These checks are plain text comparison, so they do not depend on which
6
+ model wrote the text.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import re
12
+ from dataclasses import dataclass
13
+
14
+ #: Words in a row that two parts of one letter may share before it reads as
15
+ #: repeating itself. Six is longer than any shared noun phrase ("client
16
+ #: engineering organisations") and shorter than a restated outcome.
17
+ REPEAT_RUN = 6
18
+
19
+ _WORD = re.compile(r"[a-z0-9]+")
20
+ #: Multi-digit numbers and percentages; a lone "8" or "3" is too common to mean anything.
21
+ _FIGURE = re.compile(r"\d[\d,.]*\d%?|\d%")
22
+ #: Acronyms and letter-digit names (RAG, J2EE, S3): the terms a model most
23
+ #: often imports from the resume into a description of the job.
24
+ _TERM = re.compile(r"\b(?:[A-Z]{2,}[A-Za-z0-9+#]*|[A-Za-z]+\d[A-Za-z0-9]*)\b")
25
+
26
+
27
+ @dataclass(frozen=True, slots=True)
28
+ class Problem:
29
+ index: int # 0 is the opening, then each picked fact from 1
30
+ what: str # a clause: 'repeats "…", which the letter already says'
31
+ label: str # "The opening", "Pick 1", "Ask 2"
32
+
33
+
34
+ def _words(text: str) -> list[str]:
35
+ return _WORD.findall(text.lower())
36
+
37
+
38
+ def _figures(text: str) -> set[str]:
39
+ return {m.group(0).rstrip(".,") for m in _FIGURE.finditer(text)}
40
+
41
+
42
+ def _shared_run(words: list[str], other: list[str], n: int = REPEAT_RUN) -> str | None:
43
+ seen = {tuple(other[i : i + n]) for i in range(len(other) - n + 1)}
44
+ for i in range(len(words) - n + 1):
45
+ gram = tuple(words[i : i + n])
46
+ if gram in seen:
47
+ return " ".join(gram)
48
+ return None
49
+
50
+
51
+ def _in_text(term: str, text: str) -> bool:
52
+ return re.search(rf"(?<![A-Za-z0-9]){re.escape(term)}(?![A-Za-z0-9])", text, re.I) is not None
53
+
54
+
55
+ def retry_feedback(problems: list[Problem]) -> list[str]:
56
+ """The faults, worded for the model's second attempt."""
57
+ return [f"{p.label} {p.what}. Write it again without that, or return an empty string." for p in problems]
58
+
59
+
60
+ def notes_for(problems: list[Problem]) -> list[str]:
61
+ """For the draft's note, so text that was dropped is never silent."""
62
+ grouped: dict[tuple[int, str], list[str]] = {}
63
+ for p in problems:
64
+ grouped.setdefault((p.index, p.label), []).append(p.what)
65
+
66
+ def lead(label: str) -> str:
67
+ if label.startswith("Ask"):
68
+ return f"Left out {label.lower()} and the fact it went with"
69
+ return f"Left out {label.lower()}"
70
+
71
+ return [lead(label) + f": it {' and '.join(whats)}." for (_, label), whats in sorted(grouped.items())]
72
+
73
+
74
+ # -- the opening, and what the posting asks for beside each fact --------------
75
+
76
+ #: Words too common to show that a phrase really comes from the posting.
77
+ _COMMON = frozenset(
78
+ "with that this from your have their they will into across over such also than them been "
79
+ "more most able each both other about which where what when while these those should would "
80
+ "could within using ensure strong build lead drive work team".split()
81
+ )
82
+ #: Share of a phrase's content words that must appear in the posting for it to count as quoted from it.
83
+ _MIN_QUOTED = 0.6
84
+ #: "Acme Corp is seeking a Director ..." — the reader already knows who is hiring for what.
85
+ _RESTATES_ROLE = re.compile(
86
+ r"^\s*[\w&.,'’()\- ]{1,60}?\s(?:is|are)\s+(?:currently\s+)?(?:seeking|hiring|looking\s+for|recruiting)\b",
87
+ re.I,
88
+ )
89
+ #: The email's own first sentence is "I came across your posting ..."; the model must not say it again.
90
+ _REPEATS_LEAD = re.compile(r"^\s*I\s+(?:came\s+across|saw|noticed|found|spotted|read)\b", re.I)
91
+ #: The prompt asks for at most 45; a few more is tolerated before a retry is spent on it.
92
+ _OPENING_MAX_WORDS = 60
93
+ _NOWHERE = "which is in neither the posting nor the facts picked"
94
+
95
+
96
+ def _norm_figure(figure: str) -> str:
97
+ return figure.rstrip("%.,")
98
+
99
+
100
+ def _not_in_posting(phrase: str, job_text: str) -> list[str]:
101
+ """Content words of `phrase` that the posting never uses (matched on a 5-letter stem,
102
+ so "managing" finds "management")."""
103
+ stems = {w[:5] for w in re.findall(r"[a-z]{4,}", job_text.lower())}
104
+ words = [w for w in re.findall(r"[a-z]{4,}", phrase.lower()) if w not in _COMMON]
105
+ return [w for w in words if w[:5] not in stems]
106
+
107
+
108
+ def check_dynamic(
109
+ opening: str,
110
+ picks: list[tuple[int, str]],
111
+ facts: list[str],
112
+ note: str,
113
+ job_text: str,
114
+ ) -> list[Problem]:
115
+ """What is wrong with the model's part of a dynamic letter, if anything.
116
+
117
+ The facts arrive unchanged, so the model's own words are where a letter can go
118
+ wrong: repeating a fact, bringing in a figure, tool or acronym that is in neither
119
+ the posting nor a fact it picked, or giving as "what the posting asks for"
120
+ something the posting never says. `picks` is (fact number, asks phrase) in the
121
+ order the model gave them; indexes count the opening as 0 and the first ask as 1.
122
+ """
123
+ problems: list[Problem] = []
124
+ chosen: list[tuple[int, int, str]] = [] # (position, fact number, asks)
125
+ taken: set[int] = set()
126
+ for position, (number, asks) in enumerate(picks, start=1):
127
+ if not 1 <= number <= len(facts):
128
+ problems.append(Problem(position, f"names fact {number}, which does not exist", f"Pick {position}"))
129
+ elif number in taken:
130
+ problems.append(Problem(position, f"picks fact {number} a second time", f"Pick {position}"))
131
+ else:
132
+ taken.add(number)
133
+ chosen.append((position, number, asks))
134
+
135
+ chosen_facts = [facts[number - 1] for _, number, _ in chosen]
136
+ allowed = " ".join([job_text, *chosen_facts])
137
+ allowed_figures = {_norm_figure(f) for f in _figures(allowed)}
138
+
139
+ if _RESTATES_ROLE.match(opening):
140
+ problems.append(
141
+ Problem(0, "begins by saying the company is hiring, which the reader knows; "
142
+ "start with what the posting asks for", "The opening")
143
+ )
144
+ if _REPEATS_LEAD.match(opening):
145
+ problems.append(
146
+ Problem(0, "begins by saying where the posting was seen, which the email's first "
147
+ "sentence already says", "The opening")
148
+ )
149
+ if len(opening.split()) > _OPENING_MAX_WORDS:
150
+ problems.append(
151
+ Problem(0, f"is {len(opening.split())} words; keep it to one or two short sentences",
152
+ "The opening")
153
+ )
154
+
155
+ pieces = [(0, "The opening", opening)] + [(pos, f"Ask {pos}", asks) for pos, _, asks in chosen]
156
+ for i, (index, label, text) in enumerate(pieces):
157
+ text = text.strip()
158
+ if not text:
159
+ continue
160
+ words = _words(text)
161
+ # An opening is printed, so it must not repeat a fact, the note, or an earlier piece. An
162
+ # `asks` phrase is never printed: it quotes the posting, as the opening does, so sharing
163
+ # words with the opening is expected. It is only checked against the facts, to catch
164
+ # a model that wrote the fact's wording where the posting's belongs.
165
+ earlier = [t for _, _, t in pieces[:i]]
166
+ compared = chosen_facts if label.startswith("Ask") else (*chosen_facts, *earlier, note)
167
+ for other in compared:
168
+ run = _shared_run(words, _words(other))
169
+ if run:
170
+ problems.append(Problem(index, f'repeats "{run}", which the letter already says', label))
171
+ break
172
+ stray = sorted(f for f in _figures(text) if _norm_figure(f) not in allowed_figures)
173
+ if stray:
174
+ problems.append(Problem(index, f"states {', '.join(stray)}, {_NOWHERE}", label))
175
+ unsupported = sorted({t for t in _TERM.findall(text) if not _in_text(t, allowed)})
176
+ if unsupported:
177
+ problems.append(Problem(index, f"names {', '.join(unsupported)}, {_NOWHERE}", label))
178
+ if label.startswith("Ask"):
179
+ content = [w for w in re.findall(r"[a-z]{4,}", text.lower()) if w not in _COMMON]
180
+ absent = _not_in_posting(text, job_text)
181
+ if content and 1 - len(absent) / len(content) < _MIN_QUOTED:
182
+ problems.append(
183
+ Problem(index, f"is not what the posting says ({', '.join(absent[:4])} are not in it)", label)
184
+ )
185
+ return problems
186
+
187
+
188
+ def clean_dynamic(
189
+ opening: str, picks: list[tuple[int, str]], problems: list[Problem]
190
+ ) -> tuple[str, list[tuple[int, str]]]:
191
+ """Drop what is still wrong: a flawed opening is emptied; a bad pick, or a pick
192
+ whose "asks" is flawed, is removed with its fact.
193
+
194
+ A fact whose link to the posting cannot be trusted goes too: that link is what
195
+ makes the fact about THIS posting, and a fact left standing without one is
196
+ exactly the unrelated content a dynamic letter exists to avoid. A missing
197
+ opening is replaced in code.
198
+ """
199
+ bad_labels = {p.label for p in problems}
200
+ if "The opening" in bad_labels:
201
+ opening = ""
202
+ kept = [
203
+ pick
204
+ for position, pick in enumerate(picks, start=1)
205
+ if f"Pick {position}" not in bad_labels and f"Ask {position}" not in bad_labels
206
+ ]
207
+ return opening, kept
208
+
209
+
210
+ _SENTENCE_END = re.compile(r"(?<=[.!?])\s+")
211
+
212
+
213
+ def without_echo(text: str, other: str, run: int = 4) -> str:
214
+ """`text` minus any sentence that repeats `other` (the candidate's note, or one of their facts).
215
+
216
+ The model sometimes writes the note into its opening as well as into the note
217
+ sentence, or restates a fact there. Throwing the whole opening away for that would
218
+ lose the part that is about the posting, so only the echoing sentence goes. `run` is
219
+ how many words in a row count as an echo.
220
+ """
221
+ if not other.strip():
222
+ return text
223
+ theirs = _words(other)
224
+ kept = [s for s in _SENTENCE_END.split(text.strip()) if not _shared_run(_words(s), theirs, run)]
225
+ return " ".join(kept)
226
+
227
+
228
+ _FIRST_PERSON = re.compile(r"^\s*(?:I|I'm|I’m|I've|I’ve|My|We|Our)\b")
229
+
230
+
231
+ def only_about_the_posting(text: str) -> str:
232
+ """`text` minus any sentence that speaks as the candidate.
233
+
234
+ An opening says what the posting asks for. What the candidate has done is the facts that
235
+ follow it, and what they offer is their note, so a sentence beginning "I have led…" in
236
+ the opening is a restated fact, in the model's words rather than yours. It goes; the
237
+ sentences about the posting stay.
238
+ """
239
+ return " ".join(s for s in _SENTENCE_END.split(text.strip()) if s and not _FIRST_PERSON.match(s))
jobdraft/cli.py ADDED
@@ -0,0 +1,230 @@
1
+ """The `jobdraft` command."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import logging
7
+ import os
8
+ import socket
9
+ import sys
10
+ import tempfile
11
+ import threading
12
+ import webbrowser
13
+ from pathlib import Path
14
+
15
+ from . import __version__, export, mail, security
16
+ from .constants import MIN_FACTS
17
+ from .flow import App, FlowError
18
+ from .settings import Home, SettingsError
19
+
20
+ DEFAULT_PORT = 8420
21
+
22
+
23
+ def _env_flag(name: str) -> bool:
24
+ return os.getenv(name, "").strip().lower() in ("1", "true", "yes", "on")
25
+
26
+
27
+ def _port_taken(host: str, port: int) -> bool:
28
+ family = socket.AF_INET6 if ":" in host else socket.AF_INET
29
+ target = {"0.0.0.0": "127.0.0.1", "::": "::1"}.get(host, host)
30
+ with socket.socket(family) as probe:
31
+ probe.settimeout(0.5)
32
+ return probe.connect_ex((target, port)) == 0
33
+
34
+
35
+ def _is_jobdraft(url: str) -> bool:
36
+ import httpx
37
+
38
+ try:
39
+ reply = httpx.get(f"{url}/health", timeout=2, trust_env=False)
40
+ return reply.json() == {"status": "ok"} and "frame-ancestors" in reply.headers.get(
41
+ "content-security-policy", ""
42
+ )
43
+ except (httpx.HTTPError, ValueError):
44
+ return False
45
+
46
+
47
+ def set_new_password(home: Home) -> str:
48
+ password = security.new_password()
49
+ home.set_secret("password_hash", security.hash_password(password))
50
+ return password
51
+
52
+
53
+ def run_server(
54
+ app_core: App, host: str, port: int, *, server_mode: bool = False,
55
+ allowed_hosts: list[str] | None = None, open_browser: bool = False, demo: bool = False,
56
+ ) -> int:
57
+ import uvicorn
58
+
59
+ from .web.app import create_app
60
+
61
+ shown = "localhost" if host in ("127.0.0.1", "0.0.0.0", "::", "::1") else host
62
+ url = f"http://{shown}:{port}"
63
+ if _port_taken(host, port):
64
+ if open_browser and _is_jobdraft(url):
65
+ print(f"jobdraft is already running at {url}")
66
+ webbrowser.open(url)
67
+ return 0
68
+ print(f"Port {port} is in use by another program. Choose another with --port.", file=sys.stderr)
69
+ return 2
70
+
71
+ # Anything reachable from another machine needs a password.
72
+ server_mode = server_mode or not security.is_loopback(host)
73
+ if server_mode and not app_core.home.secret("password_hash"):
74
+ password = set_new_password(app_core.home)
75
+ print(f"\n Sign-in password (shown only now): {password}\n", flush=True)
76
+
77
+ allowed = list(allowed_hosts or [])
78
+ if host not in ("0.0.0.0", "::"):
79
+ allowed.append(host.strip("[]"))
80
+ web = create_app(app_core, server_mode=server_mode, allowed_hosts=allowed, demo=demo)
81
+ print(f"jobdraft {__version__} on {url} (Ctrl+C stops it)")
82
+ if server_mode:
83
+ print(f"From your own computer: ssh -L {port}:127.0.0.1:{port} user@your-server, then open http://localhost:{port}")
84
+ if open_browser:
85
+ threading.Timer(1.0, webbrowser.open, args=(url,)).start()
86
+ uvicorn.run(web, host=host, port=port, access_log=False, log_level="warning", proxy_headers=False)
87
+ return 0
88
+
89
+
90
+ def cmd_start(args: argparse.Namespace) -> int:
91
+ return run_server(App(Home(args.home)), "127.0.0.1", args.port, open_browser=not args.no_browser)
92
+
93
+
94
+ def cmd_serve(args: argparse.Namespace) -> int:
95
+ extra = [*args.allow_host, *os.getenv("JOBDRAFT_ALLOWED_HOSTS", "").split(",")]
96
+ return run_server(
97
+ App(Home(args.home)), args.host, args.port,
98
+ server_mode=args.server or _env_flag("JOBDRAFT_SERVER"), allowed_hosts=extra,
99
+ )
100
+
101
+
102
+ def cmd_demo(args: argparse.Namespace) -> int:
103
+ from . import demo
104
+
105
+ # A throwaway folder: the demo can never touch your real data.
106
+ with tempfile.TemporaryDirectory(prefix="jobdraft-demo-") as folder:
107
+ app_core = demo.seed(Home(folder))
108
+ return run_server(
109
+ app_core, "127.0.0.1", args.port, open_browser=not args.no_browser, demo=True
110
+ )
111
+
112
+
113
+ def cmd_doctor(args: argparse.Namespace) -> int:
114
+ home = Home(args.home)
115
+ app_core = App(home)
116
+ settings = app_core.settings()
117
+ problems = 0
118
+
119
+ def report(ok: bool, text: str) -> None:
120
+ nonlocal problems
121
+ problems += not ok
122
+ print(f" {'ok ' if ok else 'FIX '} {text}")
123
+
124
+ print(f"jobdraft {__version__} data folder: {home.root}")
125
+ try:
126
+ report(True, app_core.test_model())
127
+ except FlowError as exc:
128
+ report(False, f"model: {exc}")
129
+ report(home.resume_path(settings) is not None, "resume uploaded")
130
+ report(len(settings.letter.facts) >= MIN_FACTS, f"{len(settings.letter.facts)} facts approved (need {MIN_FACTS})")
131
+ password = home.gmail_password(settings.gmail)
132
+ if settings.gmail.address and password:
133
+ try:
134
+ folder = mail.GmailDrafts(
135
+ settings.gmail.address, password, settings.gmail.host, settings.gmail.port
136
+ ).check()
137
+ report(True, f"Gmail sign-in works; drafts folder: {folder}")
138
+ except mail.MailError as exc:
139
+ report(False, f"Gmail: {exc}")
140
+ else:
141
+ print(" -- Gmail not set up (optional)")
142
+ return 1 if problems else 0
143
+
144
+
145
+ def cmd_export(args: argparse.Namespace) -> int:
146
+ target = Path(args.output)
147
+ if target.exists():
148
+ print(f"{target} already exists. Choose another name with -o.", file=sys.stderr)
149
+ return 2
150
+ target.write_bytes(export.export_zip(Home(args.home)))
151
+ print(f"Wrote {target}. It holds personal data; keys and passwords are not in it.")
152
+ return 0
153
+
154
+
155
+ def cmd_password(args: argparse.Namespace) -> int:
156
+ home = Home(args.home)
157
+ if args.if_missing and home.secret("password_hash"):
158
+ print("A sign-in password is already set. Run `jobdraft password` to replace it.")
159
+ return 0
160
+ password = set_new_password(home)
161
+ print(f"New sign-in password (shown only now): {password}")
162
+ return 0
163
+
164
+
165
+ def cmd_modal(args: argparse.Namespace) -> int:
166
+ from . import modal_setup
167
+
168
+ return modal_setup.run(Home(args.home))
169
+
170
+
171
+ def cmd_uninstall(args: argparse.Namespace) -> int:
172
+ from . import uninstall
173
+
174
+ return uninstall.run(Home(args.home), delete_data=args.delete_data)
175
+
176
+
177
+ def build_parser() -> argparse.ArgumentParser:
178
+ port = int(os.getenv("JOBDRAFT_PORT") or DEFAULT_PORT)
179
+ parser = argparse.ArgumentParser(
180
+ prog="jobdraft", description="Paste a job. Get an honest draft in Gmail. You press Send."
181
+ )
182
+ parser.add_argument("--version", action="version", version=__version__)
183
+ parser.add_argument("--home", help="data folder (default: ~/.jobdraft, or JOBDRAFT_HOME)")
184
+ parser.add_argument("--port", type=int, default=port, help=f"default {DEFAULT_PORT}")
185
+ parser.add_argument("--no-browser", action="store_true", help="do not open the browser")
186
+ parser.set_defaults(func=cmd_start)
187
+ sub = parser.add_subparsers(metavar="command")
188
+
189
+ def command(name: str, func, help_text: str) -> argparse.ArgumentParser:
190
+ p = sub.add_parser(name, help=help_text, description=help_text)
191
+ p.set_defaults(func=func)
192
+ return p
193
+
194
+ serve = command("serve", cmd_serve, "run without opening a browser, for servers")
195
+ serve.add_argument("--host", default=os.getenv("JOBDRAFT_HOST") or "127.0.0.1")
196
+ serve.add_argument("--port", type=int, default=argparse.SUPPRESS)
197
+ serve.add_argument("--server", action="store_true", help="require a password")
198
+ serve.add_argument("--allow-host", action="append", default=[], metavar="NAME",
199
+ help="also answer to this host name (repeatable)")
200
+
201
+ demo = command("demo", cmd_demo, "try it with sample data: no key, no network")
202
+ demo.add_argument("--port", type=int, default=argparse.SUPPRESS)
203
+ demo.add_argument("--no-browser", action="store_true", default=argparse.SUPPRESS)
204
+
205
+ command("doctor", cmd_doctor, "check the settings, the model and Gmail")
206
+ out = command("export", cmd_export, "save your data to a zip file")
207
+ out.add_argument("-o", "--output", default="jobdraft-export.zip")
208
+ password = command("password", cmd_password, "set a new sign-in password for server mode")
209
+ password.add_argument("--if-missing", action="store_true", help="only if none is set yet")
210
+ modal = command("modal", cmd_modal, "set up your own model on Modal")
211
+ modal.add_argument("action", choices=["setup"])
212
+ remove = command("uninstall", cmd_uninstall, "remove the shortcut or service")
213
+ remove.add_argument("--delete-data", action="store_true", help="also delete your data")
214
+ return parser
215
+
216
+
217
+ def main(argv: list[str] | None = None) -> int:
218
+ args = build_parser().parse_args(argv)
219
+ logging.basicConfig(level=logging.WARNING, format="%(levelname)s %(name)s: %(message)s")
220
+ try:
221
+ return int(args.func(args))
222
+ except SettingsError as exc:
223
+ print(exc, file=sys.stderr)
224
+ return 2
225
+ except KeyboardInterrupt:
226
+ return 0
227
+
228
+
229
+ if __name__ == "__main__":
230
+ raise SystemExit(main())
jobdraft/constants.py ADDED
@@ -0,0 +1,57 @@
1
+ """Shared vocabulary. Anything that appears in more than one module lives here."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Final
6
+
7
+ #: Scoring dimensions, in the order they are shown.
8
+ #:
9
+ #: `role_alignment` leads because it answers the question the others assume: is
10
+ #: this even the same kind of job? Without it a posting for a different function
11
+ #: can score high because the skills, years, city and seniority all happen to match.
12
+ DIMENSIONS: Final[tuple[str, ...]] = (
13
+ "role_alignment",
14
+ "must_have_skills",
15
+ "nice_to_have_skills",
16
+ "experience_fit",
17
+ "location_fit",
18
+ "seniority_fit",
19
+ )
20
+
21
+ DIMENSION_LABELS: Final[dict[str, str]] = {
22
+ "role_alignment": "Same kind of role",
23
+ "must_have_skills": "Required skills",
24
+ "nice_to_have_skills": "Preferred skills",
25
+ "experience_fit": "Years of experience",
26
+ "location_fit": "Location",
27
+ "seniority_fit": "Seniority",
28
+ }
29
+
30
+ DEFAULT_WEIGHTS: Final[dict[str, float]] = {
31
+ "role_alignment": 0.20,
32
+ "must_have_skills": 0.30,
33
+ "nice_to_have_skills": 0.10,
34
+ "experience_fit": 0.15,
35
+ "location_fit": 0.15,
36
+ "seniority_fit": 0.10,
37
+ }
38
+
39
+ #: Below this score the letter is still available, with a notice.
40
+ LOW_SCORE: Final[int] = 75
41
+
42
+ JOB_STATUSES: Final[tuple[str, ...]] = (
43
+ "new", "scored", "needs_review", "drafted", "applied", "dismissed",
44
+ )
45
+
46
+ #: Company-name legal suffixes stripped before fingerprinting.
47
+ LEGAL_SUFFIXES: Final[tuple[str, ...]] = (
48
+ "pvt", "private", "ltd", "limited", "llp", "llc", "inc", "incorporated",
49
+ "corp", "corporation", "co", "company", "gmbh", "plc", "technologies",
50
+ "technology", "solutions", "services", "labs",
51
+ )
52
+
53
+ MIN_POSTING_CHARS: Final[int] = 40
54
+ MAX_POSTING_CHARS: Final[int] = 12_000
55
+ MAX_IMAGE_BYTES: Final[int] = 8 * 1024 * 1024
56
+ MAX_RESUME_BYTES: Final[int] = 5 * 1024 * 1024
57
+ MIN_FACTS: Final[int] = 3