Ignore:
Timestamp:
03/15/23 19:03:03 (14 months ago)
Author:
István Váradi <ivaradi@…>
Branch:
python3
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

SimBrief handling via CEF is reinstated optionally

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gui/cef.py

    r1083 r1084  
    5757class SimBriefHandler(object):
    5858    """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)
    6068
    6169    _querySettings = {
     
    8795
    8896        self._browser = \
    89           cefpython.CreateBrowserSync(windowInfo, browserSettings = {},
    90                                       navigateUrl = SimBriefHandler._formURL)
     97          cefpython.CreateBrowserSync(windowInfo, browserSettings = {})
    9198        self._browser.SetClientHandler(OffscreenRenderHandler())
    9299        self._browser.SetFocus(True)
     
    107114        self._htmlFilePath = htmlFilePath
    108115
    109         self._browser.LoadUrl(SimBriefHandler._formURL)
     116        self._browser.LoadUrl(SimBriefHandler.getFormURL(plan))
    110117        self._updateProgress(SIMBRIEF_PROGRESS_LOADING_FORM,
    111118                             SIMBRIEF_RESULT_NONE, None)
     
    123130            self._updateProgress(self._lastProgress,
    124131                                 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,
    130134                                 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();"
    145137            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?"):
    147139            (user, password) = self._getCredentials(self._getCredentialsCount)
    148140            if user is None or password is None:
     
    152144
    153145            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();"
    158151            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"):
    160153            self._updateProgress(SIMBRIEF_PROGRESS_WAITING_RESULT,
    161154                                 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):
    177156            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)
    186158
    187159    def _onLoadError(self, browser, frame, error_code, error_text_out,
     
    215187
    216188        return False
    217 
    218     def _getResults(self, link):
    219         """Get the result from the given link."""
    220         availableInfo = {}
    221         ## Holds analysis data to be used
    222         flightInfo = {}
    223 
    224         # Obtaining the xml
    225         response = urllib.request.urlopen(link)
    226         xmlContent = response.read()
    227         # Processing xml
    228         content = etree.iterparse(StringIO(xmlContent))
    229 
    230         for (action, element) in content:
    231             # Processing tags that occur multiple times
    232             if element.tag == "weather":
    233                 weatherElementList = list(element)
    234                 for weatherElement in weatherElementList:
    235                     flightInfo[weatherElement.tag] = weatherElement.text
    236             else:
    237                 availableInfo[element.tag] = element.text
    238 
    239         # Processing plan_html
    240         ## Obtaining chart links
    241         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"] = imageLinks
    248         print((sorted(availableInfo.keys())))
    249         htmlFilePath = "simbrief_plan.html" if self._htmlFilePath is None \
    250           else self._htmlFilePath
    251         with open(htmlFilePath, 'w') as f:
    252             f.write(availableInfo["plan_html"])
    253 
    254         GObject.idle_add(self._resultsAvailable, flightInfo)
    255189
    256190#------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.