forked from MODA-NYC/db-safegraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsg
executable file
·89 lines (77 loc) · 2.11 KB
/
sg
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python3
import typer
import os
app = typer.Typer()
env = '''
if [ -f .env ]
then
export $(cat .env | sed 's/#.*//g' | xargs)
fi
'''
def complete_name_run(incomplete: str):
current_path=os.path.dirname(os.path.abspath(__file__))
files=os.listdir(f'{current_path}/recipes')
valid_names=[i.split('.')[0] for i in files if '.py' in i]
completion = []
for name in valid_names:
if name.startswith(incomplete):
completion.append(name)
return completion
def complete_name_sync(incomplete: str):
current_path=os.path.dirname(os.path.abspath(__file__))
files=os.listdir(f'{current_path}/_sync')
valid_names=[i.split('.')[0] for i in files if '.sh' in i]
completion = []
for name in valid_names:
if name.startswith(incomplete):
completion.append(name)
return completion
@app.command()
def run(
name: str = typer.Option (
'daily_nyc_poivisits',
help="recipe name under ./recipes",
autocompletion=complete_name_run
)
):
"""
Running an Athena recipe in the ./recipes folder
"""
typer.echo(name)
command=f'''
{env}
python3 recipes/{name}.py
'''
os.system(command)
@app.command()
def setup():
"""
Install minio and set up the accounts we need
"""
command = f'''
{env}
curl -O https://dl.min.io/client/mc/release/linux-amd64/mc
chmod +x mc
sudo mv ./mc /usr/bin
mc config host add sg $SG_S3_ENDPOINT $SG_ACCESS_KEY_ID $SG_SECRET_ACCESS_KEY --api S3v4
mc config host add rdp $RDP_S3_ENDPOINT $RDP_ACCESS_KEY_ID $RDP_SECRET_ACCESS_KEY --api S3v4
'''
os.system(command)
@app.command()
def sync(
name: str = typer.Option (
'social_distancing',
help="bash script names under ./_sync",
autocompletion=complete_name_sync
)
):
"""
Syncing a safegraph data source, under the ./_sync folder
"""
command = f'''
{env}
(cd _sync && ./{name}.sh)
'''
os.system(command)
if __name__ == "__main__":
app()