This repository has been archived by the owner on Aug 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeojobs_staging.py
51 lines (41 loc) · 1.75 KB
/
geojobs_staging.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
import pathlib
import modal
import subprocess
import urllib.request
from os import environ
import re
from sheet_to_yaml import make_yaml, get_companies
import hooks
stub = modal.Stub("geospatial-jobs-staging")
urlwatch_image = modal.Image.from_dockerfile("Dockerfile")
volume = modal.SharedVolume().persist("geospatial-jobs-urlwatch-cache-staging")
URLWATCH_DIR = "/urlwatch"
DB_PATH = pathlib.Path(URLWATCH_DIR, "geojobs.db")
URL_REMOTE_PATH = "https://raw.githubusercontent.com/dchirst/geospatialjobs/main/urls.yaml"
CONFIG_REMOTE_PATH = "https://raw.githubusercontent.com/dchirst/geospatialjobs/main/config.yaml"
URL_PATH = pathlib.Path(URLWATCH_DIR, "urls.yaml")
CONFIG_PATH = pathlib.Path(URLWATCH_DIR, "config.yaml")
@stub.function(schedule=modal.Cron("0 7 * * 1-5"),
image=urlwatch_image,
shared_volumes={URLWATCH_DIR: volume},
secrets=[modal.Secret.from_name("gmail")])
def run_geospatial_urlwatch():
# print(environ["PYPPETEER_HOME"])
# subprocess.run(Launcher().cmd)
df = get_companies()
make_yaml(df, filename=URL_PATH)
print("created urls")
with urllib.request.urlopen(urllib.request.Request(CONFIG_REMOTE_PATH)) as src:
with open(CONFIG_PATH, "w+") as dst:
config = src.read().decode("utf-8")
config_data = re.sub(r'\$\{password\}',
environ.get("EMAIL_PASSWORD"),
config)
config_data = re.sub(r'\$\{to_email\}',
environ.get("TO_EMAIL_STAGING"),
config_data)
dst.write(config_data)
subprocess.run(["webchanges", "--urls", URL_PATH, "--config", CONFIG_PATH, "--hooks", "hooks.py", "--cache", DB_PATH])
if __name__ == '__main__':
with stub.run():
run_geospatial_urlwatch.call()