This repository has been archived by the owner on Apr 24, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
59 lines (43 loc) · 1.77 KB
/
main.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
# Step 1: go through each (or just the requested) source and run it through the appropriate fetcher to save the data to cache
# (get services URL (i.e. https://services.arcgis.com/njFNhDsUCentVYJW/arcgis/rest/services/MD_Vaccination_Locations/FeatureServer/0) and list of each layer to grab)
# Step 2: go through each source again and run the desired action on the data
# step 3. run the desired action through the desired output to generate usable output files
# TODO: create "program files" that are just configs that load in all the settings for decisions made above
import json
from models.config import Config
from models.source import Source
from fetchers.arcgis import Arcgis
from fetchers.json import JSONFetcher
from fetchers.googledrive import Googledrive
# import argparse
import logging
import datetime
def select_fetcher_for_source(source):
fname = source.get_fetcher_name()
fetcher = None
if fname == 'arcgis':
fetcher = Arcgis()
elif fname == 'googledrive':
fetcher = Googledrive()
elif fname == 'json':
fetcher = JSONFetcher()
else:
raise ValueError('Bad message type {}'.format(message_type))
return fetcher
if __name__ == "__main__":
# set up argparse
# parser.add_argument('-v', '--verbose', action='count', default=0)
# set up logging
loglevel = logging.INFO # default loglevel
# if args.verbose == 1:
# loglevel = logging.INFO
# elif args.verbose >= 2:
# loglevel = logging.DEBUG
logging.basicConfig(level=loglevel)
logger = logging.getLogger(__name__)
logger.info("starting up")
configfile = Config.from_file('./config.json')
for source in configfile.get_sources():
logger.info("Checking source " + str(source))
fetcher = select_fetcher_for_source(source)
fetcher.fetch(source, if_since=(datetime.datetime.now() - datetime.timedelta(1)))