def curl_cmd(url: str, fname: str) -> str: """ The curl command we wish to execute. """ if os.path.exists(fname): raise SKIP("Image data file already exists.") return "curl -fL -o {fname} {url}".format(fname=fname, url=url)
def curl_cmd(url: str, file: str) -> str: """ The curl command we wish to execute. """ prefect.context.get("logger") if Path(file).exists(): raise SKIP("Image data file already exists.") return f"curl -fL -o {file} {url}"
def del_cmd(fname: str) -> str: """ The shell command we wish to execute. """ if not os.path.exists(fname): raise SKIP("Image data file does not exist.") return "rm {fname}".format(fname=fname)
def is_snowing_this_week(data): """ Given a list of hourly forecasts, returns a boolean specifying whether there is snow in this week's forecast. """ snow = [ forecast["snow"].get("3h", 0) for forecast in data["list"] if "snow" in forecast ] if not sum([s >= 1 for s in snow]) >= 8: raise SKIP("There is not much snow in the forecast.")
def is_raining_tomorrow(data): """ Given a list of hourly forecasts, returns a boolean specifying whether there is rain in tomorrow's forecast. """ pendulum.now("utc").add(days=1).strftime("%Y-%m-%d") rain = [ w for forecast in data["list"] for w in forecast["weather"] if w["main"] == "Rain" and forecast["dt_txt"].startswith(tomorrow) ] if not bool(rain): raise SKIP("There is no rain in the forecast for tomorrow.")
def insert_rows(rows): """ Given the cleaned data, inserts the new data into the DB. """ if not rows: raise SKIP("No rows to insert into database.") insert_cmd = "INSERT INTO SSHATTEMPTS VALUES (?, ?, ?, ?, ?, ?, ?)" values = [( row["timestamp"], row["username"], row["port"], row["city"], row["country"], row["latitude"], row["longitude"], ) for row in rows] with closing(sqlite3.connect("ssh.db")) as conn: with closing(conn.cursor()) as cursor: cursor.executemany(insert_cmd, values) conn.commit()
def run(self, timestamp): now = pendulum.now("utc") if timestamp <= now.add(hours=-1.95): raise SKIP("Report sent in the last 24 hours.") return super().run()
def run(self, x): if x == 2: raise SKIP("Skip this task execution") return [x]
def model_existence_check(obj): if obj.model_exists(): raise SKIP("Model has already been created.")
def test_pred_existance_check(obj): if obj.test_pred_exists(): raise SKIP("Test data has already been created.")