Changeset 1084:4d1bce6fff23 for src/mlx/gui/cef.py
- Timestamp:
- 03/15/23 19:03:03 (13 months ago)
- Branch:
- python3
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/gui/cef.py
r1083 r1084 57 57 class SimBriefHandler(object): 58 58 """An object to store the state of a SimBrief query.""" 59 _formURL = "http://flare.privatedns.org/mava_simbrief/simbrief_form.html" 59 _formURLBase = MAVA_BASE_URL + "/simbrief_form.php" 60 61 _resultURLBase = MAVA_BASE_URL + "/simbrief_briefing.php" 62 63 @staticmethod 64 def getFormURL(plan): 65 """Get the form URL for the given plan.""" 66 return SimBriefHandler._formURLBase + "?" + \ 67 urllib.parse.urlencode(plan) 60 68 61 69 _querySettings = { … … 87 95 88 96 self._browser = \ 89 cefpython.CreateBrowserSync(windowInfo, browserSettings = {}, 90 navigateUrl = SimBriefHandler._formURL) 97 cefpython.CreateBrowserSync(windowInfo, browserSettings = {}) 91 98 self._browser.SetClientHandler(OffscreenRenderHandler()) 92 99 self._browser.SetFocus(True) … … 107 114 self._htmlFilePath = htmlFilePath 108 115 109 self._browser.LoadUrl(SimBriefHandler. _formURL)116 self._browser.LoadUrl(SimBriefHandler.getFormURL(plan)) 110 117 self._updateProgress(SIMBRIEF_PROGRESS_LOADING_FORM, 111 118 SIMBRIEF_RESULT_NONE, None) … … 123 130 self._updateProgress(self._lastProgress, 124 131 SIMBRIEF_RESULT_ERROR_OTHER, None) 125 elif url.startswith("http://flare.privatedns.org/mava_simbrief/simbrief_form.html"): 126 if self._plan is None: 127 return 128 129 self._updateProgress(SIMBRIEF_PROGRESS_FILLING_FORM, 132 elif url.startswith(SimBriefHandler._formURLBase): 133 self._updateProgress(SIMBRIEF_PROGRESS_WAITING_LOGIN, 130 134 SIMBRIEF_RESULT_NONE, None) 131 132 js = "form=document.getElementById(\"sbapiform\");" 133 for (name, value) in self._plan.items(): 134 js += "form." + name + ".value=\"" + value + "\";" 135 for (name, value) in SimBriefHandler._querySettings.items(): 136 if isinstance(value, bool): 137 js += "form." + name + ".checked=" + \ 138 ("true" if value else "false") + ";" 139 elif isinstance(value, str): 140 js += "form." + name + ".value=\"" + value + "\";" 141 142 js += "form.submitform.click();" 143 js += "window.formFilled();" 144 135 elif url.startswith("https://www.simbrief.com/system/login.api.sso.php"): 136 js = "document.getElementsByClassName(\"login_option navigraph\")[0].click();" 145 137 frame.ExecuteJavascript(js) 146 elif url.startswith("http ://www.simbrief.com/system/login.api.php"):138 elif url.startswith("https://identity.api.navigraph.com/login?"): 147 139 (user, password) = self._getCredentials(self._getCredentialsCount) 148 140 if user is None or password is None: … … 152 144 153 145 self._getCredentialsCount += 1 154 js = "form=document.forms[0];" 155 js += "form.user.value=\"" + user + "\";" 156 js += "form.pass.value=\"" + password + "\";" 157 js += "form.submit();" 146 147 js = "form=document.getElementsByName(\"form\")[0];" 148 js +="form.username.value=\"" + user + "\";" 149 js +="form.password.value=\"" + password + "\";" 150 js +="form.submit();" 158 151 frame.ExecuteJavascript(js) 159 elif url.startswith("http ://www.simbrief.com/ofp/ofp.loader.api.php"):152 elif url.startswith("https://www.simbrief.com/ofp/ofp.loader.api.php"): 160 153 self._updateProgress(SIMBRIEF_PROGRESS_WAITING_RESULT, 161 154 SIMBRIEF_RESULT_NONE, None) 162 elif url.startswith("http://flare.privatedns.org/mava_simbrief/simbrief_briefing.php"): 163 js = "form=document.getElementById(\"hiddenform\");" 164 js += "window.briefingData(form.hidden_is_briefing_available.value, form.hidden_link.value);"; 165 frame.ExecuteJavascript(js) 166 167 def _formFilled(self): 168 """Called when the form has been filled and submitted.""" 169 self._updateProgress(SIMBRIEF_PROGRESS_WAITING_LOGIN, 170 SIMBRIEF_RESULT_NONE, None) 171 172 def _briefingDataAvailable(self, available, link): 173 """Called when the briefing data is available.""" 174 if available: 175 link ="http://www.simbrief.com/ofp/flightplans/xml/" + link + ".xml" 176 155 elif url.startswith(SimBriefHandler._resultURLBase): 177 156 self._updateProgress(SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING, 178 SIMBRIEF_RESULT_NONE, None) 179 180 thread = threading.Thread(target = self._getResults, args = (link,)) 181 _thread.daemon = True 182 _thread.start() 183 else: 184 self._updateProgress(SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING, 185 SIMBRIEF_RESULT_ERROR_OTHER, None) 157 SIMBRIEF_RESULT_OK, None) 186 158 187 159 def _onLoadError(self, browser, frame, error_code, error_text_out, … … 215 187 216 188 return False 217 218 def _getResults(self, link):219 """Get the result from the given link."""220 availableInfo = {}221 ## Holds analysis data to be used222 flightInfo = {}223 224 # Obtaining the xml225 response = urllib.request.urlopen(link)226 xmlContent = response.read()227 # Processing xml228 content = etree.iterparse(StringIO(xmlContent))229 230 for (action, element) in content:231 # Processing tags that occur multiple times232 if element.tag == "weather":233 weatherElementList = list(element)234 for weatherElement in weatherElementList:235 flightInfo[weatherElement.tag] = weatherElement.text236 else:237 availableInfo[element.tag] = element.text238 239 # Processing plan_html240 ## Obtaining chart links241 imageLinks = []242 for imageLinkElement in lxml.html.find_class(availableInfo["plan_html"],243 "ofpmaplink"):244 for imageLink in imageLinkElement.iterlinks():245 if imageLink[1] == 'src':246 imageLinks.append(imageLink[2])247 flightInfo["image_links"] = imageLinks248 print((sorted(availableInfo.keys())))249 htmlFilePath = "simbrief_plan.html" if self._htmlFilePath is None \250 else self._htmlFilePath251 with open(htmlFilePath, 'w') as f:252 f.write(availableInfo["plan_html"])253 254 GObject.idle_add(self._resultsAvailable, flightInfo)255 189 256 190 #------------------------------------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.