def ScrapeMainWebpage(self): if self.Error == False: result = {} Scrape = lib_WebScraping.WebScraping() URL = "http://" + self.IP + self.Port + "/index.shtml" Scrape.URLWithAuthenticate(self.User,self.Password,URL) if Scrape.soup == "": URL = "http://" + self.IP + self.Port + "/Main.shtml" Scrape.URLWithAuthenticate(self.User,self.Password,URL) result ["Type"] = Scrape.FindStringInTagWithKey(Tag = "input",Keyname = "name", KeyValue = "sArbVer",Attribute = "value") return result else: self.log.printWarning("%s skipped due to previous failure" % sys._getframe().f_code.co_name)
def ScrapeMainWebpage(self): if self.Error == False: result = {} Scrape = lib_WebScraping.WebScraping() URL = "http://" + self.IP + self.Port + "/index.shtml" Scrape.URLWithAuthenticate(self.User, self.Password, URL) if (Scrape.soup == "") or ("404 Not Found" in str(Scrape.soup)): URL = "http://" + self.IP + self.Port + "/Main.shtml" Scrape.URLWithAuthenticate(self.User, self.Password, URL) result["ACU"] = Scrape.FindStringInTagWithKey(Tag="input", Keyname="name", KeyValue="sAcuVer", Attribute="value") result["PCU"] = Scrape.FindStringInTagWithKey(Tag="input", Keyname="name", KeyValue="sPcuVer", Attribute="value") DVB = Scrape.FindStringInTagWithKey(Tag="input", Keyname="name", KeyValue="sDvbVer", Attribute="value") DVB = DVB.replace(result["ACU"], "") result["DVB"] = DVB.replace('>', '') result["CommIf"] = Scrape.FindStringInTagWithKey(Tag="input", Keyname="name", KeyValue="sIntro", Attribute="value") self.CommIf = result["CommIf"] return result else: self.log.printWarning("%s skipped due to previous failure" % sys._getframe().f_code.co_name)
def ScrapeParameters1Webpage(self): if self.Error == False: #URL = "http://" + self.User + ":" + self.Password + "@" + self.IP + self.Port + "/Main.shtml" URL = "http://" + self.IP + self.Port + "/parameters1.shtml" result = {} Scrape = lib_WebScraping.WebScraping() Scrape.URLWithAuthenticate(self.User, self.Password, URL) #value=" 4006 VER 2.45b" name="sPcuVer" # def FindStringInTagWithKey(self,Tag = "",Keyname = "id", KeyValue = "", Attribute = None): result["Elevation_Trim"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sElTrim", Attribute="value") result["Azimuth_Trim"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sAzTrim", Attribute="value") result["Elevaton_Step_Size"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sElStep", Attribute="value") result["Azimuth_Step_Size"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sAzStep", Attribute="value") result["AUTO_threshold"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sAgcT", Attribute="value") result["Sweep_Increment"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sStepD", Attribute="value") result["Search_Increment"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sSearchI", Attribute="value") result["Step_Integral"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sStepI", Attribute="value") result["Search_Limit"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sSearchL", Attribute="value") result["Polang_Type"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sPolT", Attribute="value") result["Search_Delay"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sSearchD", Attribute="value") result["Polang_Offset_24V"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sPolO24", Attribute="value") result["System_Type"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sSystemT", Attribute="value") result["Polang_Scale_24V"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sPolS24", Attribute="value") return result else: self.log.printWarning("%s skipped due to previous failure" % sys._getframe().f_code.co_name)
def ScrapeStatusWebpage(self): if self.Error == False: URL = "http://" + self.IP + self.Port + "/status.shtml" result = {} Scrape = lib_WebScraping.WebScraping() Scrape.URLWithAuthenticate(self.User, self.Password, URL) #value=" 4006 VER 2.45b" name="sPcuVer" # def FindStringInTagWithKey(self,Tag = "",Keyname = "id", KeyValue = "", Attribute = None): result["Latitude"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sLat", Attribute="value") result["LatitudeDirection"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sLatNS", Attribute="value") result["AbsoluteAz"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sAz", Attribute="value") result["Longitude"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sLon", Attribute="value") result["LongitudeDirection"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sLonEW", Attribute="value") result["Elevation"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sEl", Attribute="value") result["Satellite"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sSat", Attribute="value") result["SatelliteDirection"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sSatEW", Attribute="value") result["RelativeAz"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sRelA", Attribute="value") result["Local_Hdg"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sHdg", Attribute="value") result["Heading"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sHdgR", Attribute="value") result["Threshold"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sThrs", Attribute="value") result["AGC"] = Scrape.FindStringInTagWithKey(Tag="input", Keyname="name", KeyValue="sAgc", Attribute="value") result["Remote_AUX"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sRemA", Attribute="value") result["Remote_POL"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sRemP", Attribute="value") if self.CommIf == "Comm IF Ver 0.71 P": DishScan = Scrape.soup.find( "span", string=re.compile("DishScan")).parent.parent.find( "img")["src"] DishScan = DishScan.replace(".gif", "") result["DishScan"] = DishScan #Create own Status level with binary information Tracking = Scrape.soup.find( "span", string=re.compile("Tracking")).parent.parent.find( "img")["src"] Searching = Scrape.soup.find( "span", string=re.compile("Searching")).parent.parent.find( "img")["src"] Target = Scrape.soup.find("span", string=re.compile( "Target")).parent.parent.find("img")["src"] Blocked = Scrape.soup.find( "span", string=re.compile("Blocked")).parent.parent.find( "img")["src"] Initalizing = Scrape.soup.find( "span", string=re.compile( "Initalizing")).parent.parent.find("img")["src"] Error = Scrape.soup.find("span", string=re.compile( "Error")).parent.parent.find("img")["src"] #for version 1.11 else: DishScan = Scrape.soup.find( "td", string=re.compile("DishScan")).parent.find("img")["src"] DishScan = DishScan.replace(".gif", "") result["DishScan"] = DishScan #Create own Status level with binary information Tracking = Scrape.soup.find( "td", string=re.compile("Tracking")).parent.find("img")["src"] Searching = Scrape.soup.find( "td", string=re.compile("Searching")).parent.find("img")["src"] Target = Scrape.soup.find( "td", string=re.compile("Target")).parent.find("img")["src"] Blocked = Scrape.soup.find( "td", string=re.compile("Blocked")).parent.find("img")["src"] Initalizing = Scrape.soup.find( "td", string=re.compile("Initalizing")).parent.find("img")["src"] Error = Scrape.soup.find( "td", string=re.compile("Error")).parent.find("img")["src"] Number = 0 if Tracking != "clr.gif": Number += 1 if Searching != "clr.gif": Number += 2 if Target != "clr.gif": Number += 4 if Blocked != "clr.gif": Number += 8 if Initalizing != "clr.gif": Number += 16 if Error != "clr.gif": Number += 32 result["Status"] = Number return result else: self.log.printWarning("%s skipped due to previous failure" % sys._getframe().f_code.co_name)
def ScrapeParameters2Webpage(self): if self.Error == False: #URL = "http://" + self.User + ":" + self.Password + "@" + self.IP + self.Port + "/Main.shtml" URL = "http://" + self.IP + self.Port + "/parameters2.shtml" result = {} Scrape = lib_WebScraping.WebScraping() Scrape.URLWithAuthenticate(self.User, self.Password, URL) #value=" 4006 VER 2.45b" name="sPcuVer" # def FindStringInTagWithKey(self,Tag = "",Keyname = "id", KeyValue = "", Attribute = None): result["Satellite"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sSat", Attribute="value") result["Az_Limit_1"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sAzL1", Attribute="value") result["Frequency_MHz"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sMhz", Attribute="value") result["Az_Limit_2"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sAzL2", Attribute="value") result["Baudrate"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sKhz", Attribute="value") result["Az_Limit_3"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sAzL3", Attribute="value") result["Az_Limit_4"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sAzL4", Attribute="value") result["Az_Limit_5"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sAzL5", Attribute="value") result["Az_Limit_6"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sAzL6", Attribute="value") result["Target_NID"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sNid", Attribute="value") result["Tx_Polarity"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sPolTxT", Attribute="value") result["El_Limit_12"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sElL12", Attribute="value") result["El_Limit_34"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sElL34", Attribute="value") result["El_Limit_56"] = Scrape.FindStringInTagWithKey( Tag="input", Keyname="name", KeyValue="sElL56", Attribute="value") return result else: self.log.printWarning("%s skipped due to previous failure" % sys._getframe().f_code.co_name)
def ScrapeSetupWebpage(self): if self.Error == False: #URL = "http://" + self.User + ":" + self.Password + "@" + self.IP + self.Port + "/Main.shtml" URL = "http://" + self.IP + self.Port + "/setup.shtml" result = {} Scrape = lib_WebScraping.WebScraping() Scrape.URLWithAuthenticate(self.User,self.Password,URL) result ["IPAddress"] = Scrape.FindStringInTagWithKey(Tag = "input",Keyname = "name", KeyValue = "sArbIP",Attribute = "value") result ["IP_Antenna_A"] = Scrape.FindStringInTagWithKey(Tag = "input",Keyname = "name", KeyValue = "sAntAIP",Attribute = "value") result ["IP_Antenna_B"] = Scrape.FindStringInTagWithKey(Tag = "input",Keyname = "name", KeyValue = "sAntBIP",Attribute = "value") result ["Gateway"] = Scrape.FindStringInTagWithKey(Tag = "input",Keyname = "name", KeyValue = "sArbGW",Attribute = "value") result ["SubnetMask"] = Scrape.FindStringInTagWithKey(Tag = "input",Keyname = "name", KeyValue = "sArbNM",Attribute = "value") result ["TCP_Port"] = Scrape.FindStringInTagWithKey(Tag = "input",Keyname = "name", KeyValue = "uiTCPPort",Attribute = "value") result ["Serial_Baudrate"] = Scrape.FindStringInTagWithKey(Tag = "input",Keyname = "name", KeyValue = "ulArbSerBaud",Attribute = "value") selectionMode = Scrape.FindStringInTagWithKey(Tag = "input",Keyname = "id", KeyValue = "uiSelectedMode_sel",Attribute = "value") if selectionMode != None: if selectionMode == "1": selectionMode = "Manual" elif selectionMode == "0": selectionMode = "AUTO" result ["SwitchSelection"] = selectionMode result ["Telnet_Port"] = Scrape.FindStringInTagWithKey(Tag = "input",Keyname = "name", KeyValue = "uiArbTelnet",Attribute = "value") selectedAntenna = Scrape.FindStringInTagWithKey(Tag = "input",Keyname = "id", KeyValue = "uiSelectedAnt_sel",Attribute = "value") if selectedAntenna != None: if selectedAntenna == "1": selectedAntenna = "Antenna_B" elif selectedAntenna == "0": selectedAntenna = "Antenna_A" result ["RFPath"] = selectedAntenna result ["UDP_Port"] = Scrape.FindStringInTagWithKey(Tag = "input",Keyname = "name", KeyValue = "uiArbUDP",Attribute = "value") Ref10MHz = Scrape.FindStringInTagWithKey(Tag = "input",Keyname = "id", KeyValue = "ui10MhzRef_sel",Attribute = "value") if Ref10MHz != None: if Ref10MHz == "1": Ref10MHz = "ON" elif Ref10MHz == "0": Ref10MHz = "OFF" result ["Ref10MHz"] = Ref10MHz GPSSource = Scrape.FindStringInTagWithKey(Tag = "input",Keyname = "id", KeyValue = "uiGPSSource_sel",Attribute = "value") if GPSSource != None: if GPSSource == "0": GPSSource = "Active_Antenna" elif GPSSource == "1": GPSSource = "Antenna_A" elif GPSSource == "2": GPSSource = "Antenna_B" elif GPSSource == "3": GPSSource = "OBM" result ["GPS_Source"] = GPSSource MuteOutputPol = Scrape.FindStringInTagWithKey(Tag = "input",Keyname = "id", KeyValue = "uiMutePol_sel",Attribute = "value") if MuteOutputPol != None: if MuteOutputPol == "0": MuteOutputPol = "Low_Voltage_Mute" elif MuteOutputPol == "1": MuteOutputPol = "High_Voltage_Mute" result ["MuteOutputPol"] = MuteOutputPol return result else: self.log.printWarning("%s skipped due to previous failure" % sys._getframe().f_code.co_name)
def ScrapeAlarms(self): if self.Error == False: IP = self.INI.getOptionStr(self.deviceDescr, self.devNumber, "IP") if IP is None: self.log.printWarning("IP for %s%s not set" % (self.deviceDescr, self.devNumber)) return self.Port = self.INI.getOptionStr(self.deviceDescr, self.devNumber, "HTTPPORT") if self.Port is None: self.Port = "" else: self.Port = ":" + self.Port self.User = self.INI.getOptionStr(self.deviceDescr, self.devNumber, "USER") if self.User is None: self.User = "******" self.Password = self.INI.getOptionStr(self.deviceDescr, self.devNumber, "PASSWORD") if self.Password is None: self.Password = "******" URL = "https://" + IP + self.Port + "/vri.php/api/alarm-status?auth-user="******"&auth-pwd=" + self.Password result = {} Scrape = lib_WebScraping.WebScraping() #Scrape.URL("http://192.168.40.1/basic_status.ssi") Scrape.URL(URL) result["VesselInfo"] = {} vesselInfo = Scrape.DeepTagSearch( tagList=["alarm-response", "vessel-info"]) if vesselInfo: result["VesselInfo"]["VesselName"] = vesselInfo.find( "name").string.strip() result["VesselInfo"]["ImoNumber"] = vesselInfo.find( "imo-number").string.strip() else: result["VesselInfo"]["VesselName"] = "" result["VesselInfo"]["ImoNumber"] = "" result["AlarmInfo"] = {} activeAlarms = Scrape.DeepTagSearch( tagList=["alarm-response", "alarm-info"]) if activeAlarms: result["AlarmInfo"]["CurrentlyActive"] = activeAlarms.find( "currently_active").string.strip() result["AlarmInfo"]["OverallInstance"] = activeAlarms.find( "overall_instance").string.strip() else: result["AlarmInfo"]["CurrentlyActive"] = "" result["AlarmInfo"]["OverallInstance"] = "" alarmList = Scrape.DeepTagSearch( tagList=["alarm-response", "list"]) if alarmList: alarmList = alarmList.find_all('alarm') for word in alarmList: option = "Alarm_" + str(word["number"]).strip() result[option] = {} result[option]["AlarmTimestamp"] = word["timestamp"].strip( ) result[option]["AlarmType"] = word["type"].strip() result[option]["AlarmDescription"] = word.find( "text").string.strip() return result else: self.log.printWarning("%s skipped due to previous failure" % sys._getframe().f_code.co_name)
def ScrapeWebpage(self): if self.Error == False: IP = self.INI.getOptionStr(self.deviceDescr,self.devNumber,"IP") if IP is None: self.log.printWarning("IP for %s%s not set"%(self.deviceDescr,self.devNumber) ) return self.Port = self.INI.getOptionStr(self.deviceDescr,self.devNumber,"HTTPPORT") if self.Port is None: self.Port = "" else: self.Port = ":" + self.Port URL = "http://" + IP + self.Port + "/basic_status.ssi" result = {} Scrape = lib_WebScraping.WebScraping() #Scrape.URL("http://192.168.40.1/basic_status.ssi") Scrape.URL(URL) if Scrape: #result ["ACU"] = Scrape.FindStringInTagWithKey(Tag = "input",Keyname = "name", KeyValue = "sAcuVer",Attribute = "value") result ["Status"] = Scrape.FindStringInTagWithKey(Tag = "img",Keyname = "id", KeyValue = "ledstat", Attribute = "src") result ["Status"] = result ["Status"].replace(".gif","").strip() result ["Signal"] = Scrape.FindStringInTagWithKey(Tag = "img",Keyname = "id", KeyValue = "ledsig", Attribute = "src") result ["Signal"] = result ["Signal"].replace(".gif","").strip() result ["GPS"] = Scrape.FindStringInTagWithKey(Tag = "img",Keyname = "id", KeyValue = "ledgps", Attribute = "src") result ["GPS"] = result ["GPS"].replace(".gif","").strip() result ["Data"] = Scrape.FindStringInTagWithKey(Tag = "img",Keyname = "id", KeyValue = "leddata", Attribute = "src") result ["Data"] = result ["Data"].replace(".gif","").strip() result ["Handset1"] = Scrape.FindStringInTagWithKey(Tag = "img",Keyname = "id", KeyValue = "ledhs1", Attribute = "src") result ["Handset1"] = result ["Handset1"].replace(".gif","").strip() result ["Handset2"] = Scrape.FindStringInTagWithKey(Tag = "img",Keyname = "id", KeyValue = "ledhs2", Attribute = "src") result ["Handset2"] = result ["Handset2"].replace(".gif","").strip() result ["Handset3"] = Scrape.FindStringInTagWithKey(Tag = "img",Keyname = "id", KeyValue = "ledhs3", Attribute = "src") result ["Handset3"] = result ["Handset3"].replace(".gif","").strip() data = Scrape.FindStringInTagWithKey(Tag = "img",Keyname = "id", KeyValue = "sigstr", Attribute = "src") if data == "nobars.png": data = 0 elif data == "onebar.png": data = 1 elif data == "twobars.png": data = 2 elif data == "threebars.png": data = 3 elif data == "fourbars.png": data = 4 elif data == "fivebars.png": data = 5 else: data = None result ["Signal_Strength"] = data result ["Bandwidth"] = Scrape.FindStringInTagWithKey(Tag = "td",Keyname = "id", KeyValue = "bw") result ["Sim_Inserted"] = Scrape.FindStringInTagWithKey(Tag = "td",Keyname = "id", KeyValue = "siminst") result ["Sim_Error"] = Scrape.FindStringInTagWithKey(Tag = "td",Keyname = "id", KeyValue = "simerr") result ["GPS_Status"] = Scrape.FindStringInTagWithKey(Tag = "td",Keyname = "id", KeyValue = "gpsstat") Latitude = Scrape.FindStringInTagWithKey(Tag = "td",Keyname = "id", KeyValue = "gpslat") Latitude = Latitude.replace(":"," ") Latitude = Latitude.split() result ["Latitude"] = lib_GPS.dms2dd(Latitude[0],Latitude[1],0,"") Longitude = Scrape.FindStringInTagWithKey(Tag = "td",Keyname = "id", KeyValue = "gpslon") Longitude = Longitude.replace(":"," ") Longitude = Longitude.split() result ["Longitude"] = lib_GPS.dms2dd(Longitude[0],Longitude[1],0,"") result ["Connected"] = Scrape.FindStringInTagWithKey(Tag = "td",Keyname = "id", KeyValue = "connected") result ["Access_Denial_Cause"] = Scrape.FindStringInTagWithKey(Tag = "td",Keyname = "id", KeyValue = "condenial") result ["IP_White_List"] = Scrape.FindStringInTagWithKey(Tag = "td",Keyname = "id", KeyValue = "blockeden") result ["Voice_Number_1"] = Scrape.FindStringInTagWithKey(Tag = "td",Keyname = "id", KeyValue = "num1") result ["Voice_Number_2"] = Scrape.FindStringInTagWithKey(Tag = "td",Keyname = "id", KeyValue = "num2") result ["Voice_Number_3"] = Scrape.FindStringInTagWithKey(Tag = "td",Keyname = "id", KeyValue = "num3") del Scrape URL = "http://" + IP + self.Port + "/diagnostics.ssi" Scrape = lib_WebScraping.WebScraping() Scrape.URL(URL) if Scrape: # result ["IP"] = Scrape.FindStringInTagWithKey(Tag = "td",Keyname = "id", KeyValue = "num3") result ["IMEI"] = Scrape.soup.find("th",string ="Equipment ID (IMEI)").parent.find("td").string result ["IMSI"] = Scrape.soup.find("th",string ="IMSI").parent.find("td").string result ["MAC"] = Scrape.soup.find("th",string ="MAC Address").parent.find("td").string result ["IP"] = Scrape.soup.find("th",string ="IP Address").parent.find("td").string result ["firmware"] = Scrape.soup.find("th",string ="Firmware Revision").parent.find("td").string result ["hardware"] = Scrape.soup.find("th",string ="Hardware Revision").parent.find("td").string result ["bootloader"] = Scrape.soup.find("th",string ="Bootloader Revision").parent.find("td").string return result else: self.log.printWarning("%s skipped due to previous failure" % sys._getframe().f_code.co_name)