AutoHotkey Community

It is currently May 27th, 2012, 12:32 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 53 posts ]  Go to page Previous  1, 2, 3, 4
Author Message
 Post subject:
PostPosted: February 16th, 2011, 4:51 am 
Offline

Joined: June 27th, 2009, 2:40 am
Posts: 6
SKAN wrote:
Anonymous wrote:
when i use this function in the label and set a timer to the label , the strx() works only once


Use N := 1 before While() loop

Code:
urldownloadtofile,http://www.facebook.com/justinbieberasia/posts/137296876324001,facebookfile.htm
sleep 1000
fileread,facebookfile,facebookfile.htm
bos = <a class="actorName"
eos = </a>
while item := unhtm(StrX( facebookfile,  bos ,N,0, eos ,1,0, N ))
msgbox % item

fileread,facebookfile,facebookfile.htm
bos_ = <span class="actorName">
eos_ = </span>
N := 1
while item := unhtm(StrX( facebookfile,  bos_ ,N,0, eos_ ,1,0, N ))
msgbox % item


Hi SKAN thanks for this great utility. In the above example how is it possible to output this to a text file (with formatting between the return strings?) eg. instead of Msg % item have "FileAppend, item1 - item2 etc"


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 16th, 2011, 9:37 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
twinkletoes wrote:
how is it possible to output this to a text file (with formatting between the return strings?) eg. instead of Msg % item have "FileAppend, item1 - item2 etc"


Instead of calling FileAppend for each iteration of loop,
we may concatenate the output text into a single variable and then append the variable content
into a text file in one go.
.= operator can be used to concatenate the items into a single variable.

Code:
setworkingdir, %A_ScriptDir%
urldownloadtofile,http://www.facebook.com/justinbieberasia/posts/137296876324001,facebookfile.htm
sleep 1000
fileread,facebookfile,facebookfile.htm
bos = <a class="actorName"
eos = </a>

while item := unhtm(StrX( facebookfile,  bos ,N,0, eos ,1,0, N ))
 items .= item . "`r`n"

filedelete, test.txt
fileappend, %items%, test.txt
run notepad.exe test.txt


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 18th, 2011, 1:31 am 
I am completely new to AHK, so please bear with me. :)

I need only the list of files (paths) in a torrent, so I ran your Torrent_FilesList() example passing %fpath% as the fmt parameter. This is what I got:

Image

Excellent, except for that topmost line. So my first query is, how do I get rid of that first line which lists the torrent name and total size (indicated by the red box below)?

Image

Next, I ran the same example on this single file torrent, and the output was as follows:

Image

Now the problem is, when there's only a single file, the code is showing the lone file name as the torrent name itself. :? Why is this? So if the first line is removed, all torrents with single files will have no output at all! Shouldn't the output be like this so that the first line can be safely removed:

Code:
secret origins the story of dc comics.avi    ( 1.36 GB )

secret origins the story of dc comics.avi

So how do I remove the first line and make the code work properly for both single and multi-file torrents?

Thanks for your help!


Report this post
Top
  
Reply with quote  
 Post subject: Unicode support?
PostPosted: February 18th, 2011, 1:46 am 
Oh, one last thing I forgot to ask... If the torrent has files inside with foreign (non-English) characters, do I need to compile the program with AutoHotkey_L with Unicode support, or will AutoHotkey Basic suffice?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 18th, 2011, 3:51 pm 
Offline

Joined: June 27th, 2009, 2:40 am
Posts: 6
Quote:
Instead of calling FileAppend for each iteration of loop,
we may concatenate the output text into a single variable and then append the variable content
into a text file in one go.
.= operator can be used to concatenate the items into a single variable.

Thanks for getting back to me SKAN, the concatenation was the missing piece of the jigsaw! I hope you don't mind helping me with another question. Consider the following example...
Code:
<name>1st something</name>

<name>2nd something</name>

<name>3rd something</name>
   
<name>final something</name>

using these as variables;
Code:
bos_ = <name>
eos_ = </name>

if i use;
Code:
item := StrX( xml,  bos_ ,1,6, eos_ ,1,7, N )

it returns "1st something"

if i use;
Code:
item := StrX( xml,  bos_ ,0,6, eos_ ,0,7, N )


it returns "final something"

why doesn't...
Code:
item := StrX( xml,  bos_ ,2,6, eos_ ,2,7, N )

...return "2nd something" ?

How is it possible to return specific entries with identical tags?


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 2nd, 2011, 9:01 pm 
Offline

Joined: February 14th, 2011, 2:05 am
Posts: 27
With the different parameters of StrX being...
Code:
BS := "Begin_"
ES := "End_"
BO := 1
EO := true
BT := StrLen(BS)
ET := StrLen(ES)
N :=
H := BS ES "Whatever!"
B := StrX( H, BS, BO,BT, ES,EO,ET, N )
MsgBox, -"%B%"- %N%

returns...
Code:
-"End_Whatever!"- 33

wich doesnt remove the characters asked by ET, wich should remove End_ from the string. finally the offset is completely off the size of the original string (H) wich is 19...

OR

if I change EO...
Code:
...
EO := false
...
MsgBox, -"%B%"- %N%

returns
Code:
-""- 7

returns the wrong offset (N)...
returns 7, wich is right after BS, but should be 11, after ES according to my (possibly false) logic...
furthermore it "erase" the remaining part ("Whatever!") from the string

If someone could help me find a way to correct the script for this specific behavior that happens once in a while when I search within an XML file when the <name></name> are empty between the tags.

Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 19th, 2012, 5:46 pm 
Offline
User avatar

Joined: July 17th, 2008, 12:58 am
Posts: 270
SKAN wrote:
:arrow: ListView for http://www.google.com/movies

Image


Code:
#SingleInstance, Force
Gui, Font, S9, Arial
Gui, Add, ListView, w675 r30 +Grid, Theater|Movie|Detail|Timing
LV_ModifyCol(1,"150"), LV_ModifyCol(2,"200"), LV_ModifyCol(3,"100"), LV_ModifyCol(4,"200")
Gui, Show,, Google/Movies - Downloading Please wait....

htmf := A_Temp "\GoogleMovies.htm", City := "Chennai"
UrlDownloadToFile, http://www.google.com/movies?near=%city%&num=1000, %htmf%
FileRead, htm, %htmf%
Gui, Show,, Google/Movies - Now Showing in %City%

While tData := StrX( htm, "<div class=theater>",N,0, "<p class=clear></div>",1,0, N ) {
 Theater := StrX( tData, "<span dir=ltr>",1,14, "</span>",1,7, T )
 While mData := StrX( tData, "<div class=movie>",T,0, "</div></div>",1,0, T ) {
      Movie  := StrX( mData, "<span dir=ltr>",1,14, "</span>",1,7 )
      Detail := Chr(1) . UnHTM( StrX( mData, "<span class=info>",1,17, "<",1,1 ) )
      Timing := UnHTM( StrX( mData, "<div class=times>",1,17, "<",1,1 ) )
      Loop, Parse, Detail, % Chr(1), %A_Space%-
        Detail := A_LoopField
      LV_Add( "", Theater, Movie, Detail, Timing )
}}
Return ;;                                                 / end of auto-execute section //

StrX( HBS="",BO=0,BT=1,   ES="",EO=0,ET=1,  ByRef N="" ) { ;    | by Skan | 19-Nov-2009
Return SubStr(H,P:=(((Z:=StrLen(ES))+(X:=StrLen(H))+StrLen(BS)-Z-X)?((T:=InStr(H,BS,0,((BO
 <0)?(1):(BO))))?(T+BT):(X+1)):(1)),(N:=P+((Z)?((T:=InStr(H,ES,0,((EO)?(P+1):(0))))?(T-P+Z
 +(0-ET)):(X+P)):(X)))-P) ; v1.0-196c 21-Nov-2009 www.autohotkey.com/forum/topic51354.html
}

UnHTM( HTM ) { ; Remove HTML formatting / Convert to ordinary text     by SKAN 19-Nov-2009
 Static HT     ; Forum Topic: www.autohotkey.com/forum/topic51342.html
 IfEqual,HT,,   SetEnv,HT, % "&aacuteá&acircâ&acute´&aeligæ&agraveà&amp&aringå&atildeã&au"
 . "mlä&bdquo„&brvbar¦&bull•&ccedilç&cedil¸&cent¢&circˆ&copy©&curren¤&dagger†&dagger‡&deg"
 . "°&divide÷&eacuteé&ecircê&egraveè&ethð&eumlë&euro€&fnofƒ&frac12½&frac14¼&frac34¾&gt>&h"
 . "ellip…&iacuteí&icircî&iexcl¡&igraveì&iquest¿&iumlï&laquo«&ldquo“&lsaquo‹&lsquo‘&lt<&m"
 . "acr¯&mdash—&microµ&middot·&nbsp &ndash–&not¬&ntildeñ&oacuteó&ocircô&oeligœ&ograveò&or"
 . "dfª&ordmº&oslashø&otildeõ&oumlö&para¶&permil‰&plusmn±&pound£&quot""&raquo»&rdquo”&reg"
 . "®&rsaquo›&rsquo’&sbquo‚&scaronš&sect§&shy­&sup1¹&sup2²&sup3³&szligß&thornþ&tilde˜&tim"
 . "es×&trade™&uacuteú&ucircû&ugraveù&uml¨&uumlü&yacuteý&yen¥&yumlÿ
"
 TXT := RegExReplace( HTM,"<[^>]+>" )               ; Remove all tags between  "<" and ">"
 Loop, Parse, TXT, &`;                              ; Create a list of special characters
   L := "&" A_LoopField ";", R .= (!(A_Index&1)) ? ( (!InStr(R,L,1)) ? L:"" ) : ""
 StringTrimRight, R, R, 1
 Loop, Parse, R , `;                                ; Parse Special Characters
  If F := InStr( HT, A_LoopField )                  ; Lookup HT Data
    StringReplace, TXT,TXT, %A_LoopField%`;, % SubStr( HT,F+StrLen(A_LoopField), 1 ), All
  Else If ( SubStr( A_LoopField,2,1)="#" )
    StringReplace, TXT, TXT, %A_LoopField%`;, % Chr(SubStr(A_LoopField,3)), All
Return RegExReplace( TXT, "(^\s*|\s*$)")            ; Remove leading/trailing white spaces
}

GuiClose:
GuiEscape:
 ExitApp


this doesnt seem to work either anymore :?
does someone know how to fix it? i would like to use it

_________________
QuickSubs | Popcorn Movie Db
All my scripts are just in AutoHotkey v1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2012, 3:37 pm 
Offline

Joined: March 28th, 2010, 1:32 am
Posts: 681
Location: United States
How can variables automatically be created for all items using StrX? Is there a way to search the XML file and assign them without manually specifying each individually?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 53 posts ]  Go to page Previous  1, 2, 3, 4

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Bon, maul.esel, SKAN and 7 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group