foiaghost/src/example.py

32 lines
810 B
Python
Raw Normal View History

2023-05-07 23:39:46 +00:00
import httpx
from beakers.recipe import Recipe, Beaker
2023-04-27 06:25:07 +00:00
async def add_response(obj_with_url):
2023-05-07 23:39:46 +00:00
print(obj_with_url["url"])
2023-04-27 06:25:07 +00:00
url = obj_with_url["url"]
response = await httpx.get(url)
return {
"url": url,
"status_code": response.status_code,
"response_body": response.text,
}
2023-05-07 23:39:46 +00:00
# current thinking, beakers exist within a recipe
2023-04-27 06:25:07 +00:00
recipe = Recipe("fetch urls")
2023-05-08 00:17:28 +00:00
recipe.add_beaker("agencies")
recipe.add_beaker("responses")
recipe.add_beaker("good_urls", temp=True)
recipe.add_beaker("missing_urls", temp=True)
recipe.add_conditional(
2023-05-07 23:39:46 +00:00
"agencies",
lambda x: x["url"].startswith("http"),
if_true="good_urls",
if_false="missing_urls",
)
recipe.add_pour("good_urls", "responses", add_response)
2023-04-27 06:25:07 +00:00
2023-05-08 00:34:12 +00:00
recipe.csv_to_beaker("agencies.csv", "agencies")
2023-05-08 00:17:28 +00:00
recipe.solve_dag()