News:

VoxCommando supports plugins for a wide variety of programs and devices. Contact us if you want to create your own.

Main Menu

trim data being written to file.write

Started by IKROWNI, April 18, 2018, 09:30:01 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

IKROWNI

I'm trying to use robobrowser to scrape info from my electric provider and create a sensor that monitor my electric use and payment owed.

right now ive got it to write

<strong>Payment: $195.17</strong>

to the text file. How do i trim this part before it gets printed?

Payment:

All i want is $195.17 to be saved into the text file.

PegLegTV

you would need to use regex to get just the dollar amount from that string.

use action Results.Regex

<strong>Payment:\s(.*?)</strong>

example command;
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.4.0-->
<command id="674" name="Regex" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Results.SetLastResult</cmdType>
    <params>
      <param>&lt;strong&gt;Payment: $195.17&lt;/strong&gt;</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>&lt;strong&gt;Payment:\s(.*?)&lt;/strong&gt;</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{Match.1.1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>

IKROWNI


IKROWNI

Quote from: PegLegTV on April 18, 2018, 09:44:20 PM

use action Results.Regex

<strong>Payment:\s(.*?)</strong>

Okay i got that working but when i try to use the same thing with the due date im getting this

<div class="gwt-Label ce-contentHeadingBolder">05/02/2018</div>

so i tried using Results.Regex like this

<div class="gwt-Label ce-contentHeadingBolder">(.*?)</div>/

but im not getting the same kind of results where i should just get 05/02/2018 in the new txt file.
Is there some reason why this wouldn't work the same as the other?

PegLegTV

Looking at what you posted you need to replace spaces with

\s

In the regex tool there is a help button that has links to working with regex. Regex has a learning curve, but worth learning. And very powerful

IKROWNI

replaced all of the spaces with \s like so

<div\sclass="gwt-Label\sce-contentHeadingBolder">(.*?)</div>/

still doesnt seem to be working properly. I checked out the regex cheat sheet but its still very confusing.


PegLegTV

in your regex pattern you have a trailing "/" at the end of your Regex, if you remove that / then your regex pattern should work

Old Regex
<div\sclass="gwt-Label\sce-contentHeadingBolder">(.*?)</div>/

New Regex
<div\sclass="gwt-Label\sce-contentHeadingBolder">(.*?)</div>

IKROWNI

Awesome i just wanna say thanks again. I was able to get all of my bills nicely displayed in my home assistant using this.



Wish i could clean up those dates and make them all use the same formatting but im not gonna be picky.

Next up is to add my wifes car stats using this.

PegLegTV

cleaning up the dates is simple, use Results.RegExReplace to replace the - with /

example date clean up
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.4.0-->
<command id="675" name="date cleen up" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Results.RegExReplace</cmdType>
    <params>
      <param>-</param>
      <param>/</param>
      <param>04-09-2018</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>