summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-11-11 22:06:06 -0800
committerFuwn <[email protected]>2024-11-11 22:06:06 -0800
commitf5c58acbd352942f3fa97108adf364fbb9bf7d1f (patch)
tree7fc8a0c8eb8925801a70348707bd80a7379dfd41
parentfeat: initial release (diff)
downloadami-f5c58acbd352942f3fa97108adf364fbb9bf7d1f.tar.xz
ami-f5c58acbd352942f3fa97108adf364fbb9bf7d1f.zip
feat: enhance location definitions
-rw-r--r--ami.py60
-rw-r--r--shell.nix1
2 files changed, 41 insertions, 20 deletions
diff --git a/ami.py b/ami.py
index cac4c33..21062b5 100644
--- a/ami.py
+++ b/ami.py
@@ -8,15 +8,18 @@ import json
import time
import requests
from datetime import datetime, timedelta
+from geopy.geocoders import Nominatim
dotenv.load_dotenv()
client = graphqlclient.GraphQLClient(environ.get("API"))
locale = environ.get("LOCALE")
+geolocator = Nominatim(user_agent="ami")
+location = geolocator.geocode(environ.get("LOCATION"), addressdetails=True)
client.inject_token(environ.get("AUTHORIZATION"), "authorization")
-city = environ.get("CITY")
+target_cities = environ.get("TARGET_CITIES") or ""
def log_response(data):
@@ -48,6 +51,26 @@ def notify(title, body, job_id=None):
def print_job_table():
+ contain_filters = [
+ {
+ "key": "state",
+ "val": [location.raw.get("address").get("ISO3166-2-lvl4").split("-")[1]],
+ },
+ {"key": "isPrivateSchedule", "val": ["false"]},
+ ]
+
+ if environ.get("SEARCH_CITIES") is not None:
+ contain_filters.append({"key": "city", "val": environ.get("SEARCH_CITIES")})
+
+ equal_filters = [
+ {"key": "scheduleRequiredLanguage", "val": locale},
+ ]
+
+ if environ.get("SHIFT_TYPE") is not None:
+ equal_filters.append({"key": "shiftType", "val": environ.get("SHIFT_TYPE")})
+ else:
+ equal_filters.append({"key": "shiftType", "val": "All"})
+
json_api_data = json.loads(
client.execute(
"""
@@ -103,17 +126,10 @@ def print_job_table():
{
"searchJobRequest": {
"locale": locale,
- "country": environ.get("COUNTRY"),
+ "country": location.raw.get("address").get("country"),
"keyWords": environ.get("KEYWORDS"),
- "equalFilters": [
- {"key": "shiftType", "val": environ.get("SHIFT_TYPE")},
- {"key": "scheduleRequiredLanguage", "val": locale},
- ],
- "containFilters": [
- # {"key": "city", "val": environ.get("CITIES")},
- {"key": "state", "val": [environ.get("STATE")]},
- {"key": "isPrivateSchedule", "val": ["false"]},
- ],
+ "equalFilters": equal_filters,
+ "containFilters": contain_filters,
"rangeFilters": [
{"key": "hoursPerWeek", "range": {"minimum": 0, "maximum": 80}}
],
@@ -131,8 +147,8 @@ def print_job_table():
"sorters": [],
"pageSize": 100,
"geoQueryClause": {
- "lat": environ.get("LATITUDE"),
- "lng": environ.get("LONGITUDE"),
+ "lat": location.latitude,
+ "lng": location.longitude,
"unit": environ.get("DISTANCE_UNIT"),
"distance": environ.get("DISTANCE"),
},
@@ -176,14 +192,17 @@ def print_job_table():
)
for job in json_api_data["data"]["searchJobCardsByLocation"]["jobCards"]:
- if job["city"] == city:
- notify(
- f"Found job in {city}",
- f"Job ID: {job['jobId']}\nTitle: {job['jobTitle']}\nCity: {job['city']}\nState: {job['state']}\nPay Rate: ${job['totalPayRateMin']} to ${job['totalPayRateMax']} {job['currencyCode']}\nEmployment Type: {job['employmentTypeL10N']}\nDistance: {job['distanceL10N']}",
- job["jobId"],
- )
+ for city in target_cities.split(","):
+ fixed_city = city.strip()
+
+ if job["city"].lower() == fixed_city.lower():
+ notify(
+ f"Found job in {fixed_city}",
+ f"Job ID: {job['jobId']}\nTitle: {job['jobTitle']}\nCity: {job['city']}\nState: {job['state']}\nPay Rate: ${job['totalPayRateMin']} to ${job['totalPayRateMax']} {job['currencyCode']}\nEmployment Type: {job['employmentTypeL10N']}\nDistance: {job['distanceL10N']}",
+ job["jobId"],
+ )
- break
+ break
while True:
@@ -192,3 +211,4 @@ while True:
interval_string = environ.get("INTERVAL")
time.sleep(int(interval_string) if interval_string is not None else 60)
+ print()
diff --git a/shell.nix b/shell.nix
index 1517095..2bfccb1 100644
--- a/shell.nix
+++ b/shell.nix
@@ -9,6 +9,7 @@ pkgs.mkShell {
python-dotenv
tabulate
requests
+ geopy
]
))
];