Author Topic: trim data being written to file.write  (Read 1973 times)

0 Members and 1 Guest are viewing this topic.

IKROWNI

  • $upporter
  • Sr. Member
  • *****
  • Posts: 146
  • Karma: 2
    • View Profile
trim data being written to file.write
« on: April 18, 2018, 09:30:01 PM »
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

Code: [Select]
<strong>Payment: $195.17</strong>
to the text file. How do i trim this part before it gets printed?

<strong>Payment: </strong>

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

PegLegTV

  • $upporter
  • Hero Member
  • *****
  • Posts: 500
  • Karma: 43
    • View Profile
Re: trim data being written to file.write
« Reply #1 on: April 18, 2018, 09:44:20 PM »
you would need to use regex to get just the dollar amount from that string.

use action Results.Regex

Code: [Select]
<strong>Payment:\s(.*?)</strong>
example command;
Code: [Select]
<?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

  • $upporter
  • Sr. Member
  • *****
  • Posts: 146
  • Karma: 2
    • View Profile
Re: trim data being written to file.write
« Reply #2 on: April 18, 2018, 10:18:53 PM »
hey thanks i appreciate the help.

IKROWNI

  • $upporter
  • Sr. Member
  • *****
  • Posts: 146
  • Karma: 2
    • View Profile
Re: trim data being written to file.write
« Reply #3 on: April 18, 2018, 11:49:43 PM »

use action Results.Regex

Code: [Select]
<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

Code: [Select]
<div class="gwt-Label ce-contentHeadingBolder">05/02/2018</div>
so i tried using Results.Regex like this

Code: [Select]
<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

  • $upporter
  • Hero Member
  • *****
  • Posts: 500
  • Karma: 43
    • View Profile
Re: trim data being written to file.write
« Reply #4 on: April 19, 2018, 12:45:13 AM »
Looking at what you posted you need to replace spaces with

Code: [Select]
\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

  • $upporter
  • Sr. Member
  • *****
  • Posts: 146
  • Karma: 2
    • View Profile
Re: trim data being written to file.write
« Reply #5 on: April 19, 2018, 02:34:46 PM »
replaced all of the spaces with \s like so

Code: [Select]
<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

  • $upporter
  • Hero Member
  • *****
  • Posts: 500
  • Karma: 43
    • View Profile
Re: trim data being written to file.write
« Reply #6 on: April 19, 2018, 02:57:58 PM »
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
Code: [Select]
<div\sclass="gwt-Label\sce-contentHeadingBolder">(.*?)</div>/
New Regex
Code: [Select]
<div\sclass="gwt-Label\sce-contentHeadingBolder">(.*?)</div>

IKROWNI

  • $upporter
  • Sr. Member
  • *****
  • Posts: 146
  • Karma: 2
    • View Profile
Re: trim data being written to file.write
« Reply #7 on: April 19, 2018, 08:08:47 PM »
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

  • $upporter
  • Hero Member
  • *****
  • Posts: 500
  • Karma: 43
    • View Profile
Re: trim data being written to file.write
« Reply #8 on: April 19, 2018, 10:10:26 PM »
cleaning up the dates is simple, use Results.RegExReplace to replace the - with /

example date clean up
Code: [Select]
<?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>