mIRC Home    About    Download    Register    News    Help

Print Thread
#242302 01/07/13 08:50 PM
Joined: Jun 2013
Posts: 43
G
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jun 2013
Posts: 43
Hello, I'm looking or a bit of help using sockets and data retrieval from a website but I don't know if what I want is possible. It would be kind of complicated to explain what I want in one forum post so if anyone would be kind enough to add me on Skype at: gamingtomftw (yes I know the name sucks) I would greatly appreciate it. I would only be able to talk with text and no voice and only between the hours of 5 and 10 GMT.
Many thanks, Tom.

GamingTom #242304 01/07/13 09:14 PM
Joined: Jul 2006
Posts: 4,172
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,172
Hello, not only you want to be helped, it has to be private, we have to add you on skype, and we have to wait for you? That's not really a nice way to ask for help, if you want to be helped privately, do not ask on a public forum.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #242309 02/07/13 07:35 AM
Joined: Jun 2013
Posts: 43
G
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jun 2013
Posts: 43
Well, thanks for the reply, but the thing is, the script isn't private. I just thought it would be a lot easier to explain what I wanted through a chat instead of sending a reply and then a few minutes/hours later being told that it doesn't make sense and that I need to try and make it more understandable. And even through Skype, it wouldn't mean you would have to wait for me, you would have to wait for me on a forum and I was just stating they would be the best times to talk as I have work during the hours of 10 till 5.

I will try and explain through here the idea that I have and maybe you could be kind enough to help me.
This script will be used on a Twitch chat and is based around the game 'The Binding of Isaac'. If you don't know that game you could check out the wiki here.

What I would like to happen is when a user enters a command, for example, '!boiitems Anarchist Cookbook' it will such through the items page and retrieve the information for that specific items and send it back to the twitch/irc chat. I don't know if this makes sense or is possible but that is what I wanted to ask.

GamingTom #242311 02/07/13 08:06 PM
Joined: Jan 2004
Posts: 1,359
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,359
Suffice it to say that parsing the information from the html could be somewhat complex and that using the API would ease the load on their server and your parsing methods (and is presumably the appropriate way to get the data). I couldn't find the call to get the content from the page, you're welcome to take a look:

http://www.mediawiki.org/wiki/API:Main_page
http://bindingofisaac.wikia.com/api.php

Using sockets to do this is entirely possible, but if this content isn't very dynamic you'd be better off skipping the sockets completely and just saving the information to file.

If you're set on using the sockets to retrieve the HTML, this will do it, but I highly suggest you look into using the API or disregarding the sockets completely. When the socket is complete you can trigger a signal or call a function to check the header for the status code and to begin parsing the file. You should also not need to open the socket every time you want to look something up. Keep the file cached and let it expire every few days, or when the header says to.

Code:
alias isaac {
  .sockclose isaac
  write -c isaac.header.txt
  write -c isaac.txt
  sockopen isaac testbindingofisaac.wikia.com 80
}

on *:sockopen:isaac:{
  sockwrite -nt $sockname GET /wiki/Items HTTP/1.0
  sockwrite -nt $sockname Host: bindingofisaac.wikia.com
  sockwrite -nt $sockname
}

on *:sockread:isaac:{
  var %header, %chunk
  var %headerfile = isaac.header.txt
  var %datafile = isaac.txt

  if ($sock($sockname).mark != header.complete) {
    sockread %header
    while (%header != $null) {
      write %headerfile %header
      sockread %header
    }
    if ($sockbr) sockmark $sockname header.complete
  }
  if ($sock($sockname).mark == header.complete) {
    while ($sock($sockname).rq) {
      sockread &read
      bwrite %datafile -1 -1 &read
    }
  }
}

Last edited by Loki12583; 02/07/13 08:43 PM.
Loki12583 #242312 02/07/13 10:02 PM
Joined: Jun 2013
Posts: 43
G
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jun 2013
Posts: 43
How would you suggest saving the information to a file? Is there an easier way to save all the items and information to a file than typing it all up because there are hundreds or items in that game? And how would you go about retrieving the information from the text file? Anyway, thanks for your help, Tom.

Last edited by GamingTom; 02/07/13 10:03 PM.

Link Copied to Clipboard