mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2013
Posts: 779
N
Nillen Offline OP
Hoopy frood
OP Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
I'm currently using an alias to single out some lines from a textfile created. I succeeded in printing the entire line which was over 25.000 letters long by using the $noHTML alias. - Now, my question is: How do I filter out a single word from the variable that contains all the text since $1- will mean what I wrote after the /alias.

Will I have to use a regex to find what I'm looking for right now and then regsubex the stuff I don't want which is around it? Or can I create another alias which will return $1- in %t and a specified amount of letters afterwards? - I'm clueless.

Relevant info
Code:
Code:
alias test {
  echo -ag Searching for $1-
  if ($read(test.txt,nw,* $+ $1- $+ *)) { 
    echo -ag Found $1-, it was at $readn
    var %t $noHTML($read(test.txt, $+ $readn))
    echo -ag %t 
  }
}
Echo:
Quote:
Searching for Win Rate
Found Win Rate, it was at 39
window.showAds = trueDOTABUFFHeroesItemsMatchesPlayersTeamsBlogForumsPlusSign in with SteamNillenLast MatchApr 11, 2014 16:10 UTCRecord909 - 913Win Rate49.89%OverviewMatchesHeroesItemsRecordsMatchupsTrendsPlayed With MeYou need to enable the "Share Match History" setting in the Dota 2 client in order to have your statistics appear on Dotabuff. Learn Moregoogletag.cmd.push(function() googletag.display('div-gpt-ad-1396029281698-0'); });Most Played HeroesAll TimeHeroMatches PlayedWin RateKDA RatioRubick12650.79%2.10


Note: This line is actually 25000 letters long, only reduced by $noHTML
Code:
alias noHTML return $regsubex($1, /<[^>]+(?:>|$)|^[^<>]+>/g, $null)



Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Apr 2014
Posts: 191
B
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191

I'm not sure but i think this issue deal with <br> that you just stripped out with $nohtml. Try replace <br> with something like linefeed/cr/special char to make it more easy to parsed.


Joined: Dec 2013
Posts: 779
N
Nillen Offline OP
Hoopy frood
OP Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
Not sure what you meant, but this is how I interpret it:
Make a new alias that doesn't remove as much as $noHTML does:
Code:
alias test {
  echo -ag Searching for $1-
  if ($read(test.txt,nw,* $+ $1- $+ *)) { 
    echo -ag Found $1-, it was at $readn
    var %x $ParseTest($read(test.txt, $+ $readn))
    if (*Win Rate* iswm %x) {
      tokenize 32 %x
      echo -ag %x
    }    
  }
}

Code:
alias ParseTest return $regsubex($1,/<[^>]|^[^<>]+>/g, $null)
Since I've never worked with regex or regsubex before, all I did was remove some parts of the $noHTML.

Unfortunately I can't find any spoiler or similar to hide this massive quote incoming right now, so apologies for the mess.
Quote:
Searching for Win Rate
Found Win Rate, it was at 39
cript type="text/javascript">window.showAds = truescript>head>ody>iv id="container-header">iv id="page-header">iv id="logo"> href="/">DOTABUFFa>div>av id="page-nav">l>i> href="/heroes">Heroesa>li>i> href="/items">Itemsa>li>i> href="/matches">Matchesa>li>i> href="/players">Playersa>li>i> href="/teams">Teamsa>li>i> href="/blog">Bloga>li>i> href="/forums/general">Forumsa>li>i> href="/plus" class="premium">Plusa>li>ul>nav>iv id="search-nav">orm accept-charset="UTF-8" action="/search" method="get">iv style="margin:0;padding:0;display:inline">nput name="utf8" type="hidden" value="&#x2713;" />div>nput autocomplete="off" id="search-input" name="q" placeholder="Search for heroes, items, players, teams..." type="text" value="" />form>iv id="search-hints">div>div>av id="session-nav">l>i> href="/signin">Sign in with Steama>li>ul>nav>iv id="content-header">iv id="content-header-primary">iv class="content-header-avatar">iv class="image-container image-container-avatar image-container-player"> href="/players/35434359">mg alt="Nillen" class="image-avatar image-player" data-tooltip-url="/players/35434359/tooltip" rel="tooltip-remote" src="http://media.steampowered.com/steamcommunity/public/images/avatars/e4/e4e81cd88b4b582b87b71c8f3a77c266aa677420_full.jpg" title="Nillen" />a>div>div>iv class="content-header-title">1>Nillenh1>div>div>iv id="content-header-secondary">l>t>Last Matchdt>d>iv>ime class="timeago" datetime="2014-04-11T16:10:22Z" title="Apr 11, 2014 16:10 UTC">Apr 11, 2014 16:10 UTCtime>div>dd>dl>l>t>Recorddt>d>iv>pan class="won">909span> - pan class="lost">913span>div>dd>dl>l>t>Win Ratedt>d>iv>49.89%div>dd>dl>div>div>iv id="content-interactive">div>av id="content-nav">l class="">i class="active"> href="/players/35434359">Overviewa>li>i class=""> href="/players/35434359/matches">Matchesa>li>i class=""> href="/players/35434359/heroes">Heroesa>li>i class=""> href="/players/35434359/items">Itemsa>li>i class=""> href="/players/35434359/records">Recordsa>li>i class="premium unavailable"> href="#plus-feature" data-toggle="modal">Matchupsa>li>i class="premium unavailable"> href="#plus-feature" data-toggle="modal">Trendsa>li>i class="premium unavailable"> href="#plus-feature" data-toggle="modal">Played With Mea>li>ul>nav>div>div>iv id="container-content">iv id="page-content">iv class="notifications" id="notifications">iv class="notification announce">You need to enable the "Share Match History" setting in the Dota 2 client in order to have your statistics appear on Dotabuff. href='/pages/enabling-statistics'>Learn Morea>div>div>iv class="leaderboard" id="leaderboard_a">iv id="div-gpt-ad-1396029281698-0" style="width: 728px; height: 90px">cript type="text/javascript">googletag.cmd.push(function() googletag.display('div-gpt-ad-1396029281698-0'); });script>div>div>iv class="player-show">iv class="primary">ection>eader>Most Played Heroesmall>All Timesmall>header>rticle>able>head>r>h colspan="2">Heroth>h class="cell-large">Matches Playedth>h class="cell-large">Win Rateth>h class="cell-large">KDA Ratioth>tr>thead>body>r>d class="cell-icon">iv class="image-container image-container-icon image-container-hero"> href="/heroes/rubick">mg alt="Rubick" class="image-icon image-hero" data-tooltip-url="/heroes/rubick/tooltip" rel="tooltip-remote" src="http://cdn.dotabuff.net/assets/heroes/rubick-dcecff0ee5d7dd815997b742807fb02d.png" title="Rubick" />a>div>td>d> href="/heroes/rubick" class="hero-link">Rubicka>td>d>126iv class="bar bar-default">iv class="segment segment-game" style="width: 100.0%">div>div>td>d>50.79%iv class="bar bar-default">iv class="segment segment-win" style="width: 50.79%">div>div>td>d>2.10iv class="bar bar-default">iv class="segment segment-score" style="width:
I highlighted my current interest, that I want to single out.
If you want to know the source I'm working with, check this out: view-source:http://dotabuff.com/players/35434359


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Apr 2014
Posts: 191
B
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
It seems there is no <br> in the source, so i tried to manipulate <dl> and </dl>.

This is how i do it:
1. replace <dl> and </dl> in data with $chr(215)
2. do $nohtml for the rest
3. parse with $wildtok

Code:
alias dotabuff {
  sockclose dotabuff
  sockopen dotabuff dotabuff.com 80
}

on *:sockopen:dotabuff:{
  if $sockerr { echo -ag Error: $v1 | return }
  var %write sockwrite -n dotabuff

  %write GET /players/35434359 HTTP/1.1
  %write Host: dotabuff.com
  %write User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:28.0) Gecko/20100101 Firefox/28.0
  %write $crlf
}

on *:sockread:dotabuff:{
  var %raw
  sockread %raw
  var %data $replace(%raw,<dl>,$chr(215),</dl>,$chr(215))
  var %data $nohtml(%data)

  if $wildtok(%data,*Win Rate*,1,215) { echo -ag $v1 }
}

alias noHTML return $regsubex($1, /<[^>]+(?:>|$)|^[^<>]+>/g, $null)



Joined: Dec 2013
Posts: 779
N
Nillen Offline OP
Hoopy frood
OP Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
Your code something echoes unpredictable responses for me. Upon using the Dotabuff alias, it will echo the correct win rate once, and in most cases also echo again.

Quote:
Win Rate49.92%
603146743All Pick37:106 &#47; 13 &#47; 13TimbersawRanked MatchLost MatchApr 10, 2014 10:32 UTC603021131All Pick47:5513 &#47; 8 &#47; 14Lifetime StatsTypeMatchesWin RateReal Matches1,82349.92%googletag.cmd.push(function() { googletag.display('div-gpt-ad-1396029281698-2'); });AliasesSTEAM_0:1:17717179NameTimes UsedNillen1,146Nillen - &#12377;&#12409;&#12390; &#27578;&#12377;154DC | Nillen109Nillebjörnen59Alla glömmer Uffe :(5Nillen #PGN1
Win Rate49.92%
13 &#47; 8 &#47; 14Lifetime StatsTypeMatchesWin RateReal Matches1,82349.92%googletag.cmd.push(function() { googletag.display('div-gpt-ad-1396029281698-2'); });AliasesSTEAM_0:1:17717179NameTimes UsedNillen1,146Nillen - &#12377;&#12409;&#12390; &#27578;&#12377;154DC | Nillen109Nillebjörnen59Alla glömmer Uffe :(5Nillen #PGN1Ruski Pruski1Nillen sblad1Report PlayerReport PlayerPlease report players for inappropriate comments, avatars or game exploiting. Our staff will investigate and take appropriate action.
Win Rate49.92%
>13 &#47; 8 &#47; 14Lifetime StatsTypeMatchesWin RateReal Matches1,82349.92%googletag.cmd.push(function() { googletag.display('div-gpt-ad-1396029281698-2'); });AliasesSTEAM_0:1:17717179NameTimes UsedNillen1,146Nillen - &#12377;&#12409;&#12390; &#27578;&#12377;154DC | Nillen109Nillebjörnen59Alla glömmer Uffe :(5Nillen #PGN1Ruski Pruski1Nillen sblad1Report PlayerReport PlayerPlease report players for inappropriate comments, avatars or game exploiting. Our staff will investigate and take appropriate action.
Win Rate49.92%
Win Rate49.92%
603146743All Pick37:106 &#47; 13 &#47; 13TimbersawRanked MatchLost MatchApr 10, 2014 10:32 UTC603021131All Pick47:5513 &#47; 8 &#47; 14Lifetime StatsTypeMatchesWin RateReal Matches1,82349.92%googletag.cmd.push(function() { googletag.display('div-gpt-ad-1396029281698-2'); });AliasesSTEAM_0:1:17717179NameTimes UsedNillen1,146Nillen - &#12377;&#12409;&#12390; &#27578;&#12377;154DC | Nillen109Nillebjörnen59Alla glömmer Uffe :(5Nillen #PGN1
Win Rate49.92%

While also filling my status window with
Quote:
* /set: line too long (line 29, remote.ini)

This was the reason I initially saved the entire response as a binary file and tried using $read for it.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Apr 2014
Posts: 191
B
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
Here is binary version with more strict parsing, so it will just echo the correct one.

Code:
on *:sockread:dotabuff:{
  sockread &raw
  var %raw $bvar(&raw,1,$bvar(&raw,0)).text
  var %data $replace(%raw,<dl>,$chr(215),</dl>,$chr(215))
  var %data $nohtml(%data)

  if $chr(215) isin %data {
    if $wildtok(%data,*Win Rate*,1,215) { echo -ag $v1 }
  }
}

Joined: Dec 2013
Posts: 779
N
Nillen Offline OP
Hoopy frood
OP Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
Sorry, forgot to reply earlier!

Thank you kindly good sir! This is exactly what I was looking for, I applied this to some other parts as well and got the result I wanted straight away! smile


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net

Link Copied to Clipboard