forked from hamishgibbs/pull_facebook_data_for_good
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pull.py
executable file
·90 lines (51 loc) · 2.19 KB
/
pull.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
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 23 13:07:41 2020
@author: hamishgibbs
"""
#update unittests
import os
import sys
from getpass import getpass
from utils import get_download_variables
from pull_mobility import pull_mobility
from pull_colocation import pull_colocation
from pull_population import pull_population
def main():
argv = sys.argv
#access user credential
try:
import dotenv
dotenv.load_dotenv()
username = os.getenv("FB_USERNAME")
password = os.getenv("FB_PASSWORD")
outdir = os.getenv("FB_OUTDIR")
if username is None or password is None:
raise ValueError('File .env is missing credentials FB_USERNAME and/or FB_PASSWORD.')
else:
print('Using credentials in .env file.')
except:
print('No credentials found. You can configure the FB_USERNAME, FB_PASSWORD, and FB_OUTDIR variables in a .env file.')
username = input("Username: ")
password = getpass()
outdir = input("Output directory: ")
keys = [username, password]
if argv[2] not in ['TilePopulation', 'TileMovement', 'AdminMovement', 'Colocation']:
raise ValueError("Dataset type not recognized. Currently supporting 'TilePopulation', 'TileMovement', and 'Colocation' datasets")
dl_variables = get_download_variables(argv[1], argv[2])
update = input("Updating an existing data collection? (y/n): ")
if update == 'y':
update = True
elif update == 'n':
update = False
else:
raise ValueError('Unknown update input. Choose "y", "n".')
if argv[2] in ['TileMovement', 'AdminMovement']:
pull_mobility(outdir, keys, argv[1], dl_variables, update, argv[2])
elif argv[2] == 'Colocation':
pull_colocation(outdir, keys, argv[1], dl_variables, update)
elif argv[2] == 'TilePopulation':
pull_population(outdir, keys, argv[1], dl_variables, update, argv[2])
if __name__ == '__main__':
main()