[Help Needed] Reading info from a website ..
 

[Help Needed] Reading info from a website ..

Started by Snooze, 16 February, 2004, 22:34:14

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Snooze

Well.. this is what i used to have running in my NMDCH hub.

Its a script that would read from a php file.


QuoteDim sBotName
Dim sNewsArray(10)
dim iGetPerHour, iPostPerHour, iLinesToPost, iNewsArrayCount, sNewsURL

Sub Main()
   tmrScriptTimer.interval=60000 '1 minute
   tmrScriptTimer.enabled=true

   iGetPerHour = 2 ' How many times an hour to Get news
   iPostPerHour = 1 ' How many times an hour to post news to main
   iLinesToPost = 2 ' How many Lines to show in main
   iNewsArrayCount = 10 ' How many in Array Above
   sNewsURL = "http://www.snooze.no-ip.com/sk/rdf.php"

   sBotName = "News-Bot"
   frmHub.RegisterBotName(sBotName)

   MakeTheFile()
End sub

Sub tmrScriptTimer_Timer()
   If tmrScriptTimer.tag="" then
      tmrScriptTimer.tag="0"
   End If
   tmrScriptTimer.tag=clng(tmrScriptTimer.tag)+1
   If (clng(tmrScriptTimer.tag) mod (60 / iGetPerHour)) = 0 Then
      MakeTheFile() 'Refresh sknews.tmp
   End If
   If (clng(tmrScriptTimer.tag) mod (60 / iPostPerHour)) = 0 Then
      PostNews()
   End If
   If clng(tmrScriptTimer.tag)=>60 then 'Reset every hour
      tmrScriptTimer.tag=0
   End If
End Sub

Sub DataArival(index, sCurData)
   dim tNews, newsCnt
   if left(sCurData, 1) = "<" then
      newsCnt = 0
      sTheText = AfterFirst(sCurData, "> ")
      If lCase(left(sTheText, 7)) = "!sknews" then
         iCount = 5
         If len(sTheText) > 8 Then
            If isnumeric(trim(AfterFirst(lCase(sTheText),"news"))) Then
               iCount = cInt(trim(AfterFirst(lCase(sTheText),"news")))
               If iCount < 1 Then Exit Sub
               If iCount > iNewsArrayCount then iCount = iNewsArrayCount - 1
            End If
         End If
         news=""
         For newsCnt = 0 to iCount
            news = news & sNewsArray(newsCnt) & vbCrLf
         Next
         index.PrivateMessage cStr(sBotName), cStr(news)
      End If
      If lCase(left(sTheText,8)) = "!getnews" Then
         MakeTheFile()
         PostNews()
      End If
   End if
End sub

Function AfterFirst(sIn, sFirst)
   AfterFirst = RightB(sIn, LenB(sIn) - InStrB(1, sIn, sFirst) - (LenB(sFirst) - 1))
End Function

Function Between2First(sIn, sFirst, sSecond)
   Dim iStartPos
   iStartPos = InStrB(sIn, sFirst) + LenB(sFirst)
   Between2First = MidB(sIn, iStartPos, InStrB(iStartPos, sIn, sSecond) - iStartPos)
End Function


'

Function MakeTheFile()
   Dim Http, tNews, newsCnt
   iCount = iNewsArrayCount
   newsCnt = 0
   Set Http = CreateObject("Microsoft.XMLHttp")
   Http.Open "GET", sNewsURL, false
   Http.Send
   HtmlResult = Http.ResponseText
   Set Http = Nothing
   extract = Between2First(HtmlResult, "", "")
   head = Between2First(HtmlResult, "", "")
   head1 = "Forum Results For: " & Between2First(head,"", "")
   head1 = head1 & " - " & Between2First(head,"","") & vbCrLf
   sNewsArray(newsCnt) = head1
   newsCnt = newsCnt + 1
   newsArray = split(extract, "", -1, 1)
   news = vbCrLf
   If iCount > uBound(newsArray) then iCount = uBound(newsArray)
   for i = 0 to iCount -1
      If inStr(newsArray(i),"") Then
         tnews = Between2First(newsArray(i),"","")
         tnews = tnews & " - " & Between2First(newsArray(i),"","") & vbCrLf
         news = news & tnews
         if newsCnt < iNewsArrayCount Then
            sNewsArray(newsCnt) = tnews
            newsCnt=newsCnt + 1
         End If
      End If
   Next
   news = head1 & news
   MakeTheFile = "Done"
End Function

Function PostNews()
   dim newsCnt
   news = vbCrLf & sNewsArray(0) & vbCrLf
   For newsCnt = 1 to iLinesToPost
      news = news & sNewsArray(newsCnt)
   next
   colUsers.SendChatToAll cstr(sBotName), cstr(news)
End Function

I would love to get this one working in Ptokax, so once again im asking for your help ..

**Snooze

Snooze

I understand that this is a bigger job than what ive posted before, but as there is no reply so far, i have to wonder if ive posted enough info ?

Please advise,


**Snooze

nErBoS

Hi,

Hell snooze, it's possible to do i think must be a expert on sockects to get a script working on that, other think don't put the script in VB here just tell us what you want on a script.

Best regards, nErBoS
--## nErBoS Spot ##--

Snooze

Well.. i thought that the VB script would explain it better than any words ;)


But here goes:


I have a php file that reads my forum and makes a nice little xml index (http://www.snooze.no-ip.com/sk/rdf.php) - what i want is a script that read this xml file and writes the result to a txt file on a timer.

This file can then be called to mainchat and PM by command.

A nice feature that i would love to have too, is the !getnews. It does the same as the timer function - reads the xml file and stores the result to the txt file.


I hope that helps - if not, pelase ask :)

**Snooze

c h i l l a

is your xml file local or not?

Snooze

#5
its running on a local server (running on a dedicated webserver connected via my LAN), C h i l l a.

So reading it would be nice and fast ..


**Snooze

c h i l l a

well.. okey we got then 2 ways of doing it.

either share the directory where the xml file is.. best solution, or connect to you webserver via a socket, but will stop the hub as long as the socket is open.

the rest is only parsing the xml file.

Snooze

#7
It would have to be done via the web server as the xml file is made realtime. Thats why i suggested that it would be written to a txt file so that the number of socket connections would be limited to a min :-)

That way when the file is requested from either a user (pm) or the script (to mainchat) it would only be the txt file being read :)

Thanks for you reply,

**Snooze

c h i l l a

#8
just thaught about it the socket, might even be faster anyways...

well okey, since I am not at your place and don't know about your LAN and stuff I'd give you  a script to read

http://board.univ-angers.fr/thread.php?threadid=691&boardid=12&styleid=1&sid=fc5dde1b9aef97cf974c63b9afddf7bb

so in short,

well you need to open a socket, to your webserver, send a /GET  request.

then parse the data it sends back to you.

Snooze

Chilla, i really need your help on this one - i've been trying but my skills just isnt good enough for this task.

Let me know what info you need to know and ill give em to you :-)

Snooze

#10
This is what my limited skills could manage ..

QuoteBot = "?News?"
sNews = "news.txt" -- In script folder

function Main()
frmHub:RegBot(Bot)
prefix = "!"
TimeMins = 60  --set timer in mins
SendC = SendToAll
sNewsUrl = "http://192.168.1.20/sk/rdf.php"
SetTimer(600000)
StartTimer()
end


function DataArrival(user,data)
   if strsub(data, 1, 1) == "<" then
      data=strsub(data,1,strlen(data)-1)
      s,e,cmd = strfind(data,"%b<>%s+(%S+)")
      if cmd == prefix.."news" then
   Readtextfile(user, sNews)
   elseif cmd == prefix.."getnews" then
   GetNews(http,ret)
   elseif cmd == prefix.."shownews" then
   SpamNews(user)
   end
    end
end

function NewUserConnected(user)
if (GetProfileName(user.iProfile) == "Reg" or GetProfileName(user.iProfile) == "Vip") then
   Readtextfile(user, sNews)
   end
end

function OpConnected(user)
   Readtextfile(user, sNews)
end

function Readtextfile(user, file)
      local filecontents = ""
   local handle = openfile(file, "r")
   if (handle ~= nil) then
      local line = read(handle)
      while line do
           filecontents = filecontents..line.."\r\n"
      line = read(handle)
      end
      closefile(handle)
         user:SendPM(Bot, filecontents)
   end
end

function SpamNews(user, data)
      readfrom(sNews)
      local sLine = read()
      local sFileContent = ""
      if sLine then
         sFileContent = sLine
         while 1 do
            sLine = read()
            if not sLine then
               break
            else
            sFileContent = sFileContent..sLine.."\r\n"
            end
         end
         readfrom()   -- close filehandle
         SendC(Bot,sFileContent)
         return 1
      else
         SendC(Bot,"Nothing in \"news.txt\" or no \"news.txt\"")
         return 1
      end
      readfrom()
end

function OnTimer()
   SendC(Bot, "---------------N-E-W-S---------------")
   SendC(Bot, "Type !news to read the latest news from the hub website.")
   SendC(Bot, "---------------N-E-W-S---------------")
end


But as you see im still missing the part that reads the http://192.168.1.20/sk/rdf.php (thats the local path) (http://www.snooze.no-ip.com/sk/rdf.php)site and writes it to the news.txt file ...

I hope that any of you skilled scripters will have the time and kindness to help me out :-)

**Snooze

Snooze

What would a script look like if i were to read the whole site (http://www.snooze.no-ip.com/sk/rdf.php) and then write it to a txt file ?

That part would be a HUGE help for me ...


**Snooze

nEgativE

Hi all, i'm looking for a script that could read a .xml from a website ? is that possible ? Thank U.

SMF spam blocked by CleanTalk