-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArchdailyCapture.py
56 lines (46 loc) · 1.58 KB
/
ArchdailyCapture.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
from ArchdailyCaptor import ArchdailyCaptor
from ArchdailyGeojsonBuilder import ArchdailyGeojsonBuilder
from FileManager import FileManager
from LoggerBuilder import LoggerBuilder
import logging
from ExitLogger import ExitLogger
from datetime import datetime
import sys
import requests
source = 'archdaily'
logger = LoggerBuilder(source, logging.WARNING, logging.INFO).get_logger()
class InitError(Exception):
pass
def main():
try:
logger.warning("Capting Archdaily...")
now = datetime.now().strftime('%y-%m-%d')
loaded_json = ArchdailyCaptor().get_data()
logger.info("Building the GeoJSON...")
loaded_geojson = ArchdailyGeojsonBuilder().build_geojson(loaded_json)
logger.info("Writing GeoJSON...")
file_manager = FileManager()
try:
file_manager.write_geojson(loaded_geojson, source, None, now)
file_manager.write_js_geojson(loaded_geojson, source, None, now)
except IOError:
raise InitError("The folder %s is missing"% file_manager.get_folder_path(source))
logger.warning("New GeoJSON written for Archdaily: %d locations"% len(loaded_json))
return 0
except InitError as e:
logger.critical("%s: %s"% (type(e).__name__, e))
return 1
except requests.exceptions.RequestException as e:
logger.critical(e, exc_info=True)
return 2
except Exception as e:
logger.critical(e, exc_info=True)
return 3
if __name__ == "__main__":
start = datetime.now().strftime('%y-%m-%d %H:%M:%S')
logger.critical("START")
res = main()
logger.critical("STOP (%d)"% res)
stop = datetime.now().strftime('%y-%m-%d %H:%M:%S')
ExitLogger(source).log(start, stop, res)
sys.exit(res)