It is currently April 19th, 2024, 9:50 am

Webparser problem? and weird conditional problem.

Get help with creating, editing & fixing problems with skins
User avatar
Codger
Posts: 97
Joined: May 29th, 2017, 3:16 pm

Webparser problem? and weird conditional problem.

Post by Codger »

I have a setup where a utility changes my IP at random intervals.
The purpose of this skin is to display the current IP and its location.
Also makes not (via color) if the VPN is not active.

All single states are functioning correctly. However when the IP changes it does not update unless you do a refresh.

I think what is happening is there is a period of a couple seconds where rainmeter thinks it is online but it isn't and webparser is doing that thing where it gets all confused. That's my guess. Several of these routines at the bottom were an attempt to get around this.

Weirdly in the second to last routine when written as Match or NotMatch it does not trigger.

Lastly this can be tested without a VPN simply by interrupting the internet. When restored it will remain without data.

And lastly lastly, the overuse of dynamicvariables=1 and IfMatchMode=1 is just how I debug. The removable ones will be removed after it works.

Thanks for your time.

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
MiddleMouseDownAction=!RainmeterDeactivateConfig
Group=RackMaster

[Metadata]
Name=IP
Author=Codger
Information=My system changes it's location at random intervals. This skin is to display my current location. It also displays a warning if the VPN goes down.
Version=0.0.4
License=License=Creative Commons Attribution - Non - Commercial - Share Alike 3.0

[Variables]
; Static Variables
BackPadding=15
BarWidth=330
BackColor=25,25,25,200
BackBorder=255,255,0,50
PureRed=255,0,0
PureWhite=255,255,255
FontFace=Microsoft Sans Serif
FontColor=#PureWhite#,240
FontSize=10

BackHeight=53

OfflineColor=255,210,0
WarningColor=255,100,0

;-- Location of External IP
IPLocationSite="http://ipinfo.io/"
;-- IP to continuously Ping
PingSite=8.8.4.4

;---
; dynamic variables
IPlast=XXX.XXX.XXX.XXX
OnlineStatusLast=Unknown

[Background]
Meter=Shape
Shape=Rectangle 0,0,(#BarWidth# + (#BackPadding#*2) + 1),#BackHeight# | Fill Color #BackColor# | StrokeWidth 1 | Stroke Color #BackBorder#
UpdateDivider=-1

;
;
;Ping > 0 means truly online

[DetectInternet]
; Offline
; Online
Measure=Plugin
Plugin=SysInfo
SysInfoType=INTERNET_CONNECTIVITY
SysInfoData=Best
Substitute="-1":"Offline", "1":"Online"

; Location

[MeasureWebParseLocation]
Measure=Plugin
Plugin=WebParser
URL=#IPLocationSite#
RegExp="(?siU)<h1 id="heading">(.*)</h1>.*<td>City</td>.*<a class=".*" href=".*"></a>(.*)</td>.*</tr>.*<tr>.*<td>Latitude/Longitude</td>.*<td data-loc=".*,.*">.*,.*</td>.*</tr>.*(?(?=.*<tr>.*<td>Postal).*<td>Postal Code</td>.*<td>(.*)</td>.*</tr>).*</table>"
OnChangeAction=[!UpdateMeasure "MeasureIP"][!UpdateMeasure "MeasureLocation"][!UpdateMeasure "MeasurePostalCode"]
DynamicVariables=1
UpdateRate=1
UpdateDivider=-1

[MeasureIP]
Measure=Plugin
Plugin=WebParser
URL=[MeasureWebParseLocation]
StringIndex=1
DecodeCharacterReference=1
RegExpSubstitute=1
Substitute="^\s+":""
UpdateDivider=-1

[MeasureLocation]
Measure=Plugin
Plugin=WebParser
URL=[MeasureWebParseLocation]
StringIndex=2
DecodeCharacterReference=1
RegExpSubstitute=1
Substitute="^\s+":""
UpdateDivider=-1

[MeasurePostalCode]
Measure=Plugin
Plugin=WebParser
URL=[MeasureWebParseLocation]
StringIndex=3
UpdateDivider=-1

[MeterIP]
Meter=String
MeasureName=MeasureIP
X=#BackPadding#
Y=3
FontSize=#FontSize#
StringStyle=Bold
FontColor=#PureWhite#
Text="Ext IP: %1"
DynamicVariables=1

[MeterInternetStatus]
Meter=String
MeasureName=DetectInternet
X=(#BarWidth#+#BackPadding#)
Y=3
MeterStyle=MeterIP
StringAlign=Right
InlineSetting=Color | #OfflineColor#
InlinePattern=Offline
Text="Status: %1"
DynamicVariables=1
Hidden=0

[MeterLocation]
Meter=String
MeasureName=MeasureLocation
Y=2R
MeterStyle=MeterIP
Text="%1 "
DynamicVariables=1

[MeterPostalCode]
Meter=String
MeasureName=MeasurePostalCode
Y=16r
MeterStyle=MeterIP
Text="Zip Code: %1"
DynamicVariables=1

[SetWarningColor]
Measure=String
String=[MeasurePostalCode]
IfMatch=02346|02347
IfMatchAction=[!SetOption MeterIP FontColor #WarningColor#]
IfNotMatchAction=[!SetOption MeterIP FontColor #PureWhite#]
DynamicVariables=1

;
;
; Update Everything on Switch in Online/Offline Status
;    This Section Should Remain Last

;
[ReallyOnline]
; Offline = 0
; Blocked = 0
; Limited = 0
; Online > 0
Measure=Plugin
Plugin=PingPlugin
DestAddress=#PingSite#
UpdateRate=3

[MeasureConnectionChangeActions]
Measure=String
String=[DetectInternet]
IfMatch=Online
IfMatchAction=[!ShowMeter "MeterIP"]
IfNotMatchAction=[!HideMeter "MeterIP"][!CommandMeasure "MeasureWebParseLocation" "Reset"]
IfMatchMode=1
DynamicVariables=1
UpdateDivider=-1

[MeasureConnectionChangeCheck]
Measure=String
String=[DetectInternet]
IfMatch=#OnlineStatusLast#
IfNotMatchAction=[!SetVariable OnlineStatusLast [DetectInternet]][!UpdateMeter "MeterInternetStatus"][!UpdateMeasure "MeasureConnectionChangeActions"][!UpdateMeasure "MeasureWebParseLocation"]
IfMatchAction=[!UpdateMeasure "DetectInternet"]
DynamicVariables=1

[ReloadLocation]
Measure=String
String=[MeasureIP]
IfMatch=""
IfMatchAction=[!SetOption MeterInternetStatus Text "Got Here"][!CommandMeasure "MeasureWebParseLocation" "Update"]
DynamicVariables=1
UpdateDivider=-1

[MeasureOnlineForLocationUpdate]
Measure=String
String=[ReallyOnline]
IfMatch="0"
IfNotMatchAction=[!UpdateMeasure "ReloadLocation"]
DynamicVariables=1


[hr][/hr][hr][/hr]
"If you are the smartest one in the room, you are in the wrong room."
User avatar
Codger
Posts: 97
Joined: May 29th, 2017, 3:16 pm

Re: Webparser problem? and weird conditional problem.

Post by Codger »

Okay I found the first part of my problem:
IfMatch="" on an emply string results in a condition which is neither true or false. An error condition I'm guessing.
IfMatch=^(?![\s\S]) is the correct command.

This leads to proof that WebParser is being corrupted by:

Code: Select all

RegExp="(?siU)<h1 id="heading">(.*)</h1>.*<td>City</td>.*<a class=".*" href=".*"></a>(.*)</td>.*</tr>.*<tr>.*<td data-loc=".*,.*">.*,.*</td>.*</tr>.*(?(?=.*<tr>.*<td>Postal).*<td>Postal Code</td>.*<td>(.*)</td>.*</tr>).*</table>"
The dump file from the web site being parsed is this:

Code: Select all

<!DOCTYPE html>
<html>

<head>
    <title>IP Address Details - ipinfo.io</title>


    <meta charset="utf-8">
    <meta name="apple-itunes-app" content="app-id=917634022">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="IP Geolocation, Hostname, Network Owner and More. Comprehensive IP Address Information and REST API from ipinfo.io">

    <link rel="manifest" href="/static/manifest.json">

    <link href="/static/favicon.ico?v2" rel="shortcut icon" type="image/x-icon">
    <link href="/static/favicon.ico?v2" rel="icon" type="image/x-icon">

    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600|Montserrat|Droid+Sans+Mono" rel="stylesheet">
    <!-- <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Droid+Sans+Mono' rel='stylesheet' type='text/css'> -->
    <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css' rel='stylesheet' type='text/css'>
    <link href='/static/dist/index.css' rel='stylesheet' type='text/css'>
    <link href='/static/flags.css' rel='stylesheet' type='text/css'>
    <link href='/static/banner.css' rel='stylesheet' type='text/css'>

    <link href='/static/layout-styles.css' rel='stylesheet' type='text/css'>

    <script src="/static/dist/index.js"></script>

    
</head>

<body>
    <div id="banner" class="banner" style="display: none">
        <span>
          <div id = "extension-image"></div>
          <span id="banner-title"></span>
        <a id="banner-link" href>Install</a>
        <a id="banner-close" href class="close">[close]</a>
        </span>
    </div>

    <header>
        <div id="map-wrapper">
            <h1 id="heading">
  196.52.39.36
</h1>
            <div id="map" class="mountainview"></div>
        </div>

        <div id="navbar">

            <div id="nav-logo-holder">
                <a href="/" id="nav-logo">
              <img id = "logoImg" src="/static/dist/images/navbarLogo.svg" />
            </a>
            </div>

            <div id="menu-options">
                <a href="/developers">Developers</a>
                <a href="/pricing">Pricing</a>
                <a href="/about">About</a>
                <a href="/customers">Customers</a>
                <a href="https://twitter.com/ipinfoio" target="_blank">Twitter</a>
            </div>

            <div class="nav-signup-search-container">
                <div class="signup-container">
                    <img class="sign-in-icon" src="/static/images/person-icon.png" />  
                    <a href="/account/login" class="sign-in">Sign In</a> 
                </div>

                
                <div id="search-holder">
                    <form method="post" action="/" id="ip-search-form">
                        <span>
                    <input type="text" name="ip" placeholder="Look up any IP…" tabindex="1" id ="search-input">
                    <input type='submit' value="GO" />
                  </span>
                    </form>
                </div>
                
            </div>

        </div>

    </header>

    <div id="content" class="text-center">
        
<section class="centered-container side-padding">

  
    <p id = "google-map-holder">
        <img class="map" src="https://maps.googleapis.com/maps/api/staticmap?center=33.4484,-112.0740&zoom=9&size=640x200&sensor=false" alt="Phoenix, Arizona, United States Map" title="Phoenix, Arizona, United States Map"/>
    </p>
  

  


  <table class="table table-striped">
    
    

    
      <tr>
        <td>Hostname</td>
        <td>ip-36-39-52-196.chicago.us.northamericancoax.com</td>
      </tr>
    

    
      <tr>
        <td>Network</td>
        <td><a href="/AS46562">AS46562</a> Total Server Solutions L.L.C.</td>
      </tr>
    

    
      <tr>
        <td>City</td>
        <td>
          <a class="flag flag-us" href="/countries/us"></a>
          Phoenix, Arizona, United States
        </td>
      </tr>
    

    
      <tr>
        <td>Latitude/Longitude</td>
        <td data-loc="33.4484,-112.0740">33.4484,-112.0740</td>
      </tr>
    

    

    
      <tr>
        <td>Postal Code</td>
        <td>85001</td>
      </tr>
    

    
    
      <tr>
        <td>Route</td>
        <td><a href="/AS46562/196.52.39.0/24">196.52.39.0/24</a></td>
      </tr>
    
  </table>

  

  
  <h2>Network Speed</h2>
  <table class="table table-striped" style="text-align: center;" id="block-table">
    <tr>
      <th style="width: 33%;">Download Speed</th>
      <th style="width:34%;">Upload Speed</th>
      <th style="width: 33%;">Ping</th>
    </tr>
    <tr>
        <td>20.17 Mbps</td>
        <td>9.65 Mbps</td>
        <td>65.86 ms</td>
    </tr>
    </table>
    <p>The average network speed for <b>Total Server Solutions L.L.C.</b> in <b>Phoenix</b> is shown above. See how your own network speed compares at <a rel="nofollow" href="/speedtest">speedsmart.net</a>.</p> 
  

  

</section>

<div id = "banner-section">
  <div id = "feature-centered">
    <div class = "feature">
      <div class = "banner-item-header varying-height-header">Try our JSON API from the command line.</div>
      <div class = "reliability-description">Get started with <code>curl ipinfo.io</code> or see our <a href="/developers">developer documentation</a> for more details.</div>
    </div>

    <div class = "feature">
      <div class = "banner-item-header varying-height-header">Free for small projects. Pay as you grow.</div>
      <div class = "reliability-description">Our API is free for up to 1,000 requests per day. See our <a href="/pricing">pricing</a> details if you need more.</div>
    </div>

    <div class = "feature">
      <div class = "banner-item-header varying-height-header">A million uses.</div>
      <div class = "reliability-description">You can use ipinfo to
          <a href="/developers/filtering-out-bot-traffic">filter out bot traffic</a>,
          <a href="/developers/customize-content-based-on-country">customize content based on visitor's location</a>,
          <a href="/developers/full-country-name">display full country names</a>,
          <a href="/developers/bulk-lookup">perform bulk IP geolocation</a>, and more.</div>
    </div>
  </div>
</div>


    </div>

    <footer class="text-center">
        <div class="footer-holder">
            <div class="footer-row row-one">
                <div class="footer-column"><a href="/developers">Developers</a></div>
                <div class="footer-divider"></div>
                <div class="footer-column footer-middle"><a href="/pricing">Pricing</a></div>
                <div class="footer-divider"></div>
                <div class="footer-column"><a href="/about">About</a></div>
            </div>
            <div id="footer-icon"></div>
            <div class="footer-row row-two">
                <div class="footer-column"><a href="/terms">Terms</a></div>
                <div class="footer-divider"></div>
                <div class="footer-column footer-middle"><a href="/contact">Contact</a></div>
                <div class="footer-divider"></div>
                <div class="footer-column"><a href="https://twitter.com/ipinfoio">Twitter</a></div>
            </div>
        </div>
    </footer>
    <script type="text/javascript">
        (function(i, s, o, g, r, a, m) {
            i['GoogleAnalyticsObject'] = r;
            i[r] = i[r] || function() {
                (i[r].q = i[r].q || []).push(arguments)
            }, i[r].l = 1 * new Date();
            a = s.createElement(o),
                m = s.getElementsByTagName(o)[0];
            a.async = 1;
            a.src = g;
            m.parentNode.insertBefore(a, m)
        })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
        ga('create', 'UA-2336519-21', 'ipinfo.io');
        ga('send', 'pageview');
    </script>

    <script type="text/javascript">
        (function() {
            window._pa = window._pa || {};
            // _pa.orderId = "myOrderId"; // OPTIONAL: attach unique conversion identifier to conversions
            // _pa.revenue = "19.99"; // OPTIONAL: attach dynamic purchase values to conversions
            // _pa.productId = "myProductId"; // OPTIONAL: Include product ID for use with dynamic ads
            var pa = document.createElement('script');
            pa.type = 'text/javascript';
            pa.async = true;
            pa.src = ('https:' == document.location.protocol ? 'https:' : 'http:') + "//tag.marinsm.com/serve/561152017c2d2e055400003d.js";
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(pa, s);
        })();
    </script>

    <script type="text/javascript">
        function closeBanner(key) {
            $('#banner').hide();
            localStorage.setItem(key, true);
        }

        function openLinkInNewTab(url) {
            window.open(url, "_blank").focus();
        }

        function getMobileOperatingSystem() {
            var userAgent = navigator.userAgent || navigator.vendor || window.opera;
            if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i) || userAgent.match(/iPod/i)) {
                return 'iOS';
            } else if (userAgent.match(/Android/i)) {
                return 'Android';
            } else {
                return 'unknown';
            }
        }

        function onClick(id, fn) {
            $(id).click(function(e) {
                e.stopImmediatePropagation();
                e.preventDefault();
                fn();
            });
        }

        $(function() {
            var mobileOs = getMobileOperatingSystem();
            var isMobileVisible = !localStorage.getItem("mobile_showed");
            var isExtVisible = !localStorage.getItem("extension_showed");
            var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor) && !(typeof window.orientation !== 'undefined');

            var link = null;
            var text = null;
            var key = null;

            if (isExtVisible && isChrome) {
                link = 'https://chrome.google.com/webstore/detail/ipinfoio-website-ip-addre/dfdphlgjcfobnklpiiobcfmbdnmihjpo?hl=en';
                text = 'Try our browser extension!';
                key = 'extension_showed';
            }

            if (link && text && key) {
                $("#banner-title").text(text);

                onClick("#banner-link", function() {
                    openLinkInNewTab(link);
                    closeBanner(key);
                });

                onClick("#banner-close", function() {
                    closeBanner(key);
                });

                $("#banner").show();
            }

            $('#ip-search-form').on('submit', function(e) {
                location.href = '/' + $('#search-input').val();
                e.preventDefault();
            })
        });
    </script>
     
</body>

</html>
Anyone know what is wrong with the Regex expression?
It runs the first time upon refresh then refuses to run again whether set to just update by updaterate, an update bang or !commandmeasure.
[hr][/hr][hr][/hr]
"If you are the smartest one in the room, you are in the wrong room."