MCPcopy Create free account
hub / github.com/adobe/Marinus / main

Function main

python3_cron_scripts/get_azure_data.py:85–171  ·  view source on GitHub ↗

Begin main...

(logger=None)

Source from the content-addressed store, hash-verified

83
84
85def main(logger=None):
86 """
87 Begin main...
88 """
89 if logger is None:
90 logger = LoggingUtil.create_log(__name__)
91
92 now = datetime.now()
93 print("Starting: " + str(now))
94 logger.info("Starting...")
95
96 mongo_connector = MongoConnector.MongoConnector()
97 jobs_manager = JobsManager.JobsManager(mongo_connector, "get_azure_data")
98 jobs_manager.record_job_start()
99
100 headers = {
101 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.3",
102 "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
103 "Accept-Language": "en-US,en;q=0.9",
104 "Accept-Encoding": "gzip, deflate, br",
105 }
106
107 # Find the JSON file location
108 try:
109 req = requests_retry_session().get(JSON_LOCATION, timeout=120, headers=headers)
110 except Exception as ex:
111 logger.error(
112 "FATAL: Azure HTTP request for HTML page failed multiple attempts!"
113 )
114 logger.error(str(ex))
115 exit(1)
116
117 if req.status_code != 200:
118 logger.error(
119 "FATAL: Unexpected response for Azure HTML page: " + str(req.status_code)
120 )
121 jobs_manager.record_job_error()
122 exit(1)
123
124 parser = MyHTMLParser()
125 parser.feed(req.text)
126
127 if parser.URL == "":
128 logger.error("FATAL: Unable to identify URL in Microsoft HTML")
129 jobs_manager.record_job_error()
130 exit(1)
131
132 # Download the XML file
133 try:
134 req = requests_retry_session().get(parser.URL, timeout=120, headers=headers)
135 except Exception as ex:
136 logger.error("Azure request for JSON data failed multiple attempts!")
137 logger.error(str(ex))
138 return None
139
140 if req.status_code != 200:
141 logger.error(
142 "FATAL: Unexpected response for Azure JSON data: " + str(req.status_code)

Callers 1

get_azure_data.pyFile · 0.70

Calls 8

record_job_startMethod · 0.95
record_job_errorMethod · 0.95
record_job_completeMethod · 0.95
create_logMethod · 0.80
perform_insertMethod · 0.80
requests_retry_sessionFunction · 0.70
MyHTMLParserClass · 0.70

Tested by

no test coverage detected