LUA and internet connection
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

LUA and internet connection

Started by bastya_elvtars, 05 September, 2004, 16:35:24

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bastya_elvtars

Suppose I wanna DL a web page and apply pattern matching to it... The DLing part is what i am interested in... If anyone helped me id be grateful
Everything could have been anything else and it would have just as much meaning.

Herodes

Look in this thread similar problem ....

I am happy to see you back here ;)
I hope you had a good summertime ..

bastya_elvtars

Thank you, mate, but i wanted someone to EXPLAIN me this stuff, cause if i do not understand what it is, i cannot (and are not willing to) write a script using it. I hope you understand me.
Everything could have been anything else and it would have just as much meaning.

Herodes

Like how do you mean ..a sciprt that streams a code from a html page into a file ?

bastya_elvtars

OK

So, i need a bit info on how lua can made 2 connect 2 internet and download a page. After the page is downloaded, i need no help, i can do pattern matching alone hehe :P
Everything could have been anything else and it would have just as much meaning.

bastya_elvtars

Sorry but i havent found this part in lua4 book... am i st00pid or it really is not there? ?(
Everything could have been anything else and it would have just as much meaning.

bastya_elvtars

Let's get this script, i wanna know what are these socket, err  and other stuff. If u explain me what is the process then i can go on.

-- IMDBBOT By [NL]Pur and GoldMember 
-- last updated: 8 juni 2003


MainBotName = "[bot]Security" -- Rename to match your Main hub bot
BotName = "[bot]iMDb" 
TimeSpanInMinutes = 30

-- Commands --
cmd1 = "?search"             -- 
cmd2 = "?topmovies"          -- no arguments
cmd4 = "?restrict"           -- arguments   
cmd5 = "?settings"           -- no arguments
cmd6 = "?sort"               -- arguments   - best search matches first
                             --             - alphabetically
                             --            - chronologically
cmd7 = "?type"               -- arguments  - Regular expression
                             --             - fuzzy search
                             --              - word(s)
cmd8 = "?fromyear"           -- argument search from which year
cmd9 = "?toyear"             -- argument search to which year
cmda = "?help" 

-- Default Settings --
RegisterBot = "PM"           -- PM = Results in PM , MainChat = Results in Main Chat
usetimer = "0"               -- 1 = Updates of Top15 with use of the timer , 0 = Updates when command ?topmovies is used
searchfor = '&tv=only'
sorts = '&sort=smart'
type = '&type=substring'
fromyear = '&from_year1890'
toyear = '&to_year2010'


function Main()
  if (RegisterBot=="PM") then
    frmHub:RegBot(BotName)
  else
    frmHub:UnregBot(BotName)
  end

  SendPmToOps(MainBotName,date("iMDb Activated [%d %B %Y  l %X] ("..RegisterBot.." Mode)"))
  SetTimer(TimeSpanInMinutes*60000) 
  StartTimer() 
end

function OnTimer() 
  if (usetimer=="1") then
    getNews1()
  end
end 


function Get1Arg(data)  
  s,e,cmd,arg = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
  return arg
end

function wr(target,text)
  target:SendPM(BotName,text)
end

function DataArrival(curUser,data) 
if (strsub(data, 1, 1) == "<") then 
    data = strsub(data,1,strlen(data)-1) 

    if (strfind(strlower(data), strlower(cmd1))) then 
      arg = Get1Arg(data)
      if (arg==nil) then       
      else
        sp = strchar(32)
        arg = gsub(arg, sp, '+')
        findNews(curUser,arg..sorts..type..searchfor..fromyear..toyear)
      end
    end

    if (strfind(strlower(data), strlower(cmd2))) then 
      if (usetimer=="0") then 
         getNews1()
      end
      headpm(curUser)
      readfile(curUser,"top15.txt")
    end
 
    if (strfind(strlower(data), strlower(cmda))) then 
      readfile(curUser,"helpimdb.txt")
    end
  
    if (getcmd(data,cmd4)==1) and (curUser.bOperator) then
       if (arg=='movie') then searchfor='&tv=off' end
       if (arg=='both') then searchfor='&tv=both' end
       if (arg=='tv') then searchfor='&tv=only' end
    end

    if (getcmd(data,cmd6)==1) and (curUser.bOperator)then
        if (arg=='smart') then sorts='&sort=smart' end
        if (arg=='alpha') then sorts='&sort=alpha' end
        if (arg=='chrono') then sorts='&sort=chrono' end
    end  

    if (getcmd(data,cmd7)==1) and (curUser.bOperator) then
      if (arg=='regexp') then type='&type=regexp' end
      if (arg=='fuzzy') then type='&type=fuzzy' end
      if (arg=='word') then type='&type=substring' end
    end

    if (getcmd(data,cmd8)==1) and (curUser.bOperator) then
      toyear = "&from_year"..arg
    end

    if (getcmd(data,cmd9)==1) and (curUser.bOperator) then
      toyear = "&to_year"..arg
    end
   
    if (strfind(strlower(data), strlower(cmd5))) then sett(curUser) end   
end
end

function getcmd(data,md)
  getmd=0
  if (strfind(strlower(data), strlower(md))) then 
      arg = Get1Arg(data)
      if (arg==nil) then       
      else     
        getmd=1
        return getmd
      end
    end
end

function sett(target)
     readfile(target,"settings.txt")

     if (searchfor=='&tv=off') then 
       res = "			Movie"
     elseif (searchfor=='&tv=both') then
       res = "			Both"
     elseif (searchfor=='&tv=only') then
       res = "			Tv"
     end
     wr(target,"Restrict is set for: "..res)

     if (sorts=='&sort=smart') then 
       sort = "		Best search matches first"
     elseif (sorts=='&sort=alpha') then
       sort = "		Alphabetically"
     elseif (sorts=='&sort=chrono') then
       sort = "		Chronologically"
     end
     wr(target,"Sort method is set for: "..sort)

     if (type=='&type=regexp') then 
       typed = "			Regular expression"
     elseif (type=='&type=fuzzy') then
       typed = "			Fuzzy search"
     elseif (type=='&type=substring') then
       typed = "			Word(s)"
     end
     wr(target,"Type of search is: "..typed)
     
      fyear = gsub(fromyear, '&from_year','')
      tyear = gsub(toyear, '&to_year','')
     wr(target, "Bot searches from the year:		"..fyear.."  until  "..tyear)
     wr(target,'')
     wr(target,"ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ") 
end


send = " HTTP/1.1"..strchar(13, 10).."Host: us.imdb.com"..strchar(13, 10).."Connection: Close"..strchar(13, 10)..
       "User-Agent: Mozilla/4.0 (blah blah blah whatever blah)"..strchar(13, 10)..strchar(13, 10)

function findNews(target,find)
wr(target,"_____________")
wr(target," Find something!")
wr(target,"ŻŻŻŻŻŻŻŻŻŻŻŻŻ")
wr(target,"Results for: "..find)
wr(target,"ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ")

file = ""..find..".txt"
if (openfile("imdb/"..file,"r")==nil) then
  local line
  local socket, err = connect("www.us.imdb.com",80) 
  writedonce=0
  tob=nil
    if not err then 
      socket:timeout(2) 
      err = socket:send("GET [URL]http://us.imdb.com/Tfuzzy?type=fuzzy&...rono&title=[/URL]"..find..send)
        if not err then 
          writeto("imdb/"..find..".txt") 
          while not(line == "") do 
          line, err = socket:receive("*l") 
           if err then break end
           s,e = strfind(line,"
  1. ','') tob = gsub(tob, '','') tob = gsub(tob, '
    ','') tob = gsub(tob, '
    ','') tob = gsub(tob, '
  2. ','') tob = gsub(tob, '','') tob = gsub(tob, '','') tob = gsub(tob, '&#[i];','') tob = gsub(tob, '','') tob = gsub(tob, '','') tob = gsub(tob, '','') tob = gsub(tob, '','') tob = gsub(tob, '','') for i = 160, 255 do n=stripchar(i) tob = gsub(tob, n,'') end return tob end function stripchar(num) n = '&#'..num..';' return n end function headpm(target) wr(target,"_________________") wr(target,"IMDb Top 15 Movies!") wr(target,"ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ") wr(target,"Rank was Title (YEAR)") wr(target,"ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ") end function getNews1() local line local socket, err = connect("www.us.imdb.com",80)   if not err then     socket:timeout(2)     err = socket:send("GET [URL]http://www.us.imdb.com/Charts/top-titles-week.html[/URL]"..send)       if not err then         writeto("imdb/top15.txt")         while not(line == "") do         line, err = socket:receive("*l")         s,e = strfind(line,"ALIGN=CENTER>")         if (s~=nil) then tob = strip(line,33)end         o,p = strfind(line,"ALIGN=CENTER>")         if (o~=nil) then toc = strip(line,30)end         c,v = strfind(line,"/Title?")         if (c~=nil) then         url = strsub(line,c,c+13) top = strip(line,38)           if strfind(top,'?">') then             top = strip(line,41)                     else             top = strip(line,48)                     end         end         if (tob~=nil) and (toc~=nil) and (top~=nil) then           url =  "http://www.us.imdb.com"..url   write(" "..tob.." "..toc.." [ "..url.." ] "..top..strchar(13)..strchar(10))                                                         tob=nil           toc=nil           top=nil         end       end       writeto()     end   end   socket:close() end function checkfile(file)  readfrom ("imdb/"..file)  n=1 while 1 do      local line = read()         e,g = strfind(line,"rating")     if (e ~= nil) then       n = 1     else       n = 0       break     end     return n end   readfrom() end function readfile(target,file)   readfrom("imdb/"..file)   while 1 do     local line = read()         if (line ~= nil) then       wr(target,line)     else       break     end   end   readfrom() end
Everything could have been anything else and it would have just as much meaning.

bastya_elvtars

Many thx, i will try it.
Everything could have been anything else and it would have just as much meaning.

BottledHate

thanks for the info Mutor! this is great stuff!

-BH
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

SMF spam blocked by CleanTalk