forked from PrefectHQ/prefect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaily_github_stats_to_airtable.py
48 lines (37 loc) · 1.13 KB
/
daily_github_stats_to_airtable.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
"""
This ETL-style flow retrieves the number of GitHub "stargazers" and "watchers" for the Prefect repo and writes them to an
Airtable document every day.
"""
import datetime
import pendulum
from prefect import Flow, task
from prefect.schedules import CronSchedule
from prefect.tasks.airtable import WriteAirtableRow
from prefect.tasks.github import GetRepoInfo
from prefect.triggers import any_failed
repo_stats = GetRepoInfo(
name="Pull star counts",
repo="PrefectHQ/prefect",
info_keys=["stargazers_count", "subscribers_count"],
max_retries=1,
retry_delay=datetime.timedelta(minutes=1),
)
@task
def process_stats(stats):
data = {
"Stars": stats["stargazers_count"],
"Watchers": stats["subscribers_count"],
"Date": pendulum.now("utc").isoformat(),
}
return data
airtable = WriteAirtableRow(
base_key="XXXXXXX",
table_name="Stars",
max_retries=1,
retry_delay=datetime.timedelta(minutes=1),
)
daily_schedule = CronSchedule("0 8 * * *")
with Flow("Collect Repo Stats", schedule=daily_schedule) as flow:
data = process_stats(repo_stats)
final = airtable(data)
flow.run()