Author Topic: Horoscope script  (Read 9613 times)

0 Members and 1 Guest are viewing this topic.

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 744
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Horoscope script
« on: 27 July, 2007, 01:40:18 »
It gets the daily horoscope from a site and fetches it.

It will open a DOS window at the script startup and every
24 hour afterwards. It counts the 24 hours from the startup.
I suppose that sites are updated every 24 hours.

Note that updating blocks the hub for 10 or more seconds.
This is currently unavoidable because there is nothing that
supports coding async socket operations.

Enjoy!
« Last Edit: 30 July, 2007, 01:10:38 by bastya_elvtars »
Everything could have been anything else and it would have just as much meaning.

PtokaX forum

Horoscope script
« on: 27 July, 2007, 01:40:18 »

Offline jack_port1000

  • Fulll Member
  • ****
  • Posts: 67
  • Karma: +4/-0
Re: Horoscope script
« Reply #1 on: 27 July, 2007, 07:45:15 »
tanx a lot
[10:55] Syntax ...T.JAGIRDAR\Desktop\New Folder (2)\scripts\zodiac.lua:39: bad argument #1 to 'gsub' (string expected, got nil)

little bugs there canu add right clike command like horoscope and all zodiac

sorry i prees by mistake notyfi tab sorry for tat

Offline sphinx_spb

  • Member
  • ***
  • Posts: 47
  • Karma: +10/-3
Re: Horoscope script
« Reply #2 on: 27 July, 2007, 10:35:18 »
It's already done by russians  ;)
I personally made allinone script for fetching info: weather (for all cities), goroscope, news, anecdots, bash.org.ru quotes, and currency rates. You can familiarize with this script on my hub, but of course all this info is russian. And it not blocks the hub and not opens DOS window.  ;D

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 744
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: Horoscope script
« Reply #3 on: 27 July, 2007, 10:43:22 »
tanx a lot
[10:55] Syntax ...T.JAGIRDAR\Desktop\New Folder (2)\scripts\zodiac.lua:39: bad argument #1 to 'gsub' (string expected, got nil)

little bugs there canu add right clike command like horoscope and all zodiac

That error should only occur if you intentionally closed the DOS window or deleted files from the zodiac directory manually.

It's already done by russians  ;)
I personally made allinone script for fetching info: weather (for all cities), goroscope, news, anecdots, bash.org.ru quotes, and currency rates. You can familiarize with this script on my hub, but of course all this info is russian. And it not blocks the hub and not opens DOS window.  ;D

How could you achieve that it doesn't block the hub?
Everything could have been anything else and it would have just as much meaning.

Offline sphinx_spb

  • Member
  • ***
  • Posts: 47
  • Karma: +10/-3
Re: Horoscope script
« Reply #4 on: 27 July, 2007, 13:32:34 »
How could you achieve that it doesn't block the hub?
Because my script uses PxWSA and fetching info from RSS pages (also possible from html, but more difficult).

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 744
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: Horoscope script
« Reply #5 on: 27 July, 2007, 15:00:50 »
Because my script uses PxWSA and fetching info from RSS pages (also possible from html, but more difficult).

I had problems with non-blocking socket features of PXWSA and its license disallows incorporation into script packs.
Everything could have been anything else and it would have just as much meaning.

Offline jack_port1000

  • Fulll Member
  • ****
  • Posts: 67
  • Karma: +4/-0
Re: Horoscope script
« Reply #6 on: 29 July, 2007, 10:25:26 »
bastya great work its working great but can u please add right clicke for this thing

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 744
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: Horoscope script
« Reply #7 on: 30 July, 2007, 01:11:00 »
bastya great work its working great but can u please add right clicke for this thing

Sure, gimme 20 more minutes.
Updated the archive in the first post.
Everything could have been anything else and it would have just as much meaning.

Offline elgee

  • Junior Member
  • **
  • Posts: 24
  • Karma: +12/-1
Re: Horoscope script
« Reply #8 on: 07 February, 2008, 16:18:28 »
is it possible to get the script updated to remove most of it in this lines:

Quote
Copyright (c)2008 Free Horoscope Daily * About Aquarius * Contact Us   var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));   var pageTracker = _gat._getTracker("UA-1984878-3"); pageTracker._initData(); pageTracker._trackPageview();   

:)

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 744
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: Horoscope script
« Reply #9 on: 07 February, 2008, 18:11:30 »
Updated zodiac.lua with my new HTML parser code. It works here.

Code: Lua
  1. --[[
  2. Zodiac bot by bastya_elvtars
  3. It gets the daily horoscope from a site and fetches it.
  4.  
  5. It will open a DOS window at the script startup and every
  6. 24 hour afterwards. It counts the 24 hours from the startup.
  7. I suppose that sites are updated every 24 hours.
  8.  
  9. Note that updating blocks the hub for 10 or more seconds.
  10. This is currently unavoidable because there is nothing that
  11. supports coding async socket operations.
  12.  
  13. You can configure the command and the bot below.
  14. ]]
  15.  
  16. command="horoscope"
  17.  
  18. Bot=
  19.   {
  20.     name="Zodiac",
  21.     email="zodiac@localhost",
  22.     desc="Horoscope bot"
  23.   }
  24.  
  25. -- Source follows. Do not edit below.
  26.  
  27. nl = "\n"
  28.  
  29. function HTML_ToText (file)
  30.   -- Declare variables, load the file. Make tags lowercase.
  31.   local text
  32.   local f=io.open (file)
  33.   if f then
  34.     if f:seek("end") <= 0 then return end
  35.     f:seek("set")
  36.     text = f:read ("*a")
  37.     f:close()
  38.   end
  39.   text = string.gsub (text,"(<([^>]-)>)",function (str) return str:lower() end)
  40.   --[[
  41.   First we kill the developer formatting (tabs, CR, LF)
  42.   and produce a long string with no newlines and tabs.
  43.   We also kill repeated spaces as browsers ignore them anyway.
  44.   ]]
  45.   local devkill=
  46.     {
  47.       ["("..string.char(10)..")"] = " ",
  48.       ["("..string.char(13)..")"] = " ",
  49.       ["("..string.char(15)..")"] = "",
  50.       ["(%s%s+)"]=" ",
  51.     }
  52.   for pat, res in pairs (devkill) do
  53.     text = string.gsub (text, pat, res)
  54.   end
  55.   -- Then we remove the header. We do this by stripping it first.
  56.   text = string.gsub (text, "(<%s*head[^>]*>)", "<head>")
  57.   text = string.gsub (text, "(<%s*%/%s*head%s*>)", "</head>")
  58.   text = string.gsub (text, "(<head>,*<%/head>)", "")
  59.   -- Kill all scripts. First we nuke their attribs.
  60.   text = string.gsub (text, "(<%s*script[^>]*>)", "<script>")
  61.   text = string.gsub (text, "(<%s*%/%s*script%s*>)", "</script>")
  62.   text = string.gsub (text, "(<script>,*<%/script>)", "")
  63.   -- Ok, same for styles.
  64.   text = string.gsub (text, "(<%s*style[^>]*>)", "<style>")
  65.   text = string.gsub (text, "(<%s*%/%s*style%s*>)", "</style>")
  66.   text = string.gsub (text, "(<style>.*<%/style>)", "")
  67.  
  68.   -- Replace <td> and <th> with tabulators.
  69.   text = string.gsub (text, "(<%s*td[^>]*>)","\t")
  70.   text = string.gsub (text, "(<%s*th[^>]*>)","\t")
  71.  
  72.   -- Replace <br> with linebreaks.
  73.   text = string.gsub (text, "(<%s*br%s*%/%s*>)",nl)
  74.  
  75.   -- Replace <li> with an asterisk surrounded by spaces.
  76.   -- Replace </li> with a newline.
  77.   text = string.gsub (text, "(<%s*li%s*%s*>)"," *  ")
  78.   text = string.gsub (text, "(<%s*/%s*li%s*%s*>)",nl)
  79.  
  80.   -- <p>, <div>, <tr>, <ul> will be replaced to a double newline.
  81.   text = string.gsub (text, "(<%s*div[^>]*>)", nl..nl)
  82.   text = string.gsub (text, "(<%s*p[^>]*>)", nl..nl)
  83.   text = string.gsub (text, "(<%s*tr[^>]*>)", nl..nl)
  84.   text = string.gsub (text, "(<%s*%/*%s*ul[^>]*>)", nl..nl)
  85.    
  86.   -- Some petting with the <a> tags. :-P
  87. --   local addresses,c = {},0
  88. --   text=string.gsub(text,"<%s*a.-href=[\'\"](%S+)[\'\"][^>]*>(.-)<%s*%/*%s*a[^>]->", -- gets URL from a tag, and the enclosed name
  89. --   function (url,name)
  90. --     c = c + 1
  91. --     name = string.gsub (name, "<([^>]-)>","") -- strip name from tags (e. g. images as links)
  92. --    
  93. --     -- We only consider the URL valid if the name contains alphanumeric characters.
  94. --     if name:find("%w") then print(url, name, c) table.insert (addresses, {url, name}) return name.."["..#addresses.."]" else return "" end    
  95. --   end)
  96.  
  97.   -- Nuke all other tags now.
  98.   text = string.gsub (text, "(%b<>)","")
  99.  
  100.   -- Replace entities to their correspondant stuff where applicable.
  101.   -- C# is owned badly here by using a table. :-P
  102.   -- A metatable secures entities, so you can add them natively as keys.
  103.   -- Enclosing brackets also get added automatically (capture!)
  104.   local entities = {}
  105.   setmetatable (entities,
  106.   {
  107.     __newindex = function (tbl, key, value)
  108.       key = string.gsub (key, "(%#)" , "%%#")
  109.       key = string.gsub (key, "(%&)" , "%%&")
  110.       key = string.gsub (key, "(%;)" , "%%;")
  111.       key = string.gsub (key, "(.+)" , "("..key..")")
  112.       rawset (tbl, key, value)
  113.     end
  114.   })
  115.   entities =
  116.   {
  117.     ["&nbsp;"] = " ",
  118.     ["&bull;"] = " *  ",
  119.     ["&lsaquo;"] = "<",
  120.     ["&rsaquo;"] = ">",
  121.     ["&trade;"] = "(tm)",
  122.     ["&frasl;"] = "/",
  123.     ["&lt;"] = "<",
  124.     ["&gt;"] = ">",
  125.     ["&copy;"] = "(c)",
  126.     ["&reg;"] = "(r)",
  127.     -- Then kill all others.
  128.     -- You can customize this table if you would like to,
  129.     -- I just got bored of copypasting. :-)
  130.     -- http://hotwired.lycos.com/webmonkey/reference/special_characters/
  131.     ["%&.+%;"] = "",
  132.   }
  133.   for entity, repl in pairs (entities) do
  134.     text = string.gsub (text, entity, repl)
  135.   end
  136.   text = text..nl..nl..("-"):rep(27)..nl..nl
  137.  
  138. --   for k,v in ipairs (addresses) do
  139. --     text = text.."["..k.."] "..v[1]..nl
  140. --   end
  141. --   if #addresses > 0 then
  142. --     text=text..nl:rep(2)..("-"):rep(2)..nl
  143. --     for key, tbl in ipairs(addresses) do
  144. --       text = text..nl.."["..key.."]"..tbl[1]
  145. --     end
  146. --   end
  147.  
  148.   return text
  149.  
  150. end
  151.  
  152. zodiac=
  153.   {
  154.     "aquarius",
  155.     "aries",
  156.     "cancer",
  157.     "capricorn",
  158.     "gemini",
  159.     "leo",
  160.     "libra",
  161.     "pisces",
  162.     "sagittarius",
  163.     "scorpio",
  164.     "taurus",
  165.     "virgo"
  166.   }
  167.  
  168. zodtbl={}
  169.  
  170. function FetchZodiacForToday()
  171.   local loc=string.gsub(frmHub:GetPtokaXLocation(),"%/",[[\]]) -- We replace the / to \. Works around a PXLUA bug. :-P
  172.   local x=os.clock()
  173.   SendToAll(Bot.name,"Getting the fresh horoscope. This slows down the hub, so please be patient.") -- Get the batchfile created
  174.   local f=io.open("zodiac/getpages.cmd","w+")
  175.   f:write("@echo off\nREM This batch file is generated by the zodiac script.\nREM It will be overwritten on every update.\r\n")
  176.   for _,val in ipairs (zodiac) do
  177.     f:write(loc.."scripts\\zodiac\\wget.exe -O"..loc.."scripts\\zodiac\\"..val..".html http://www.freehoroscopedaily.com/"..val.."/\n")
  178.   end
  179.   f:close()
  180.  
  181.   os.execute (loc.."scripts\\zodiac\\getpages.cmd") -- Run it
  182.  
  183.   for _,sign in ipairs(zodiac) do -- Parse the HTML files. It is faster to do it right away.
  184.     zodtbl[sign]=1
  185.     local f=io.open("zodiac/"..sign..".txt","w+")
  186.     f:write(HTML_ToText("zodiac/"..sign..".html"))
  187.     f:close()
  188.   end
  189.  
  190.   SendToAll(Bot.name,"\r\nHoroscope fetched. It took "..os.clock()-x.." seconds. Check your horoscope with "..frmHub:GetPrefixes()[1]..command.." <sign>\r\nType "..frmHub:GetPrefixes()[1]..command.." for help!")
  191. end
  192.  
  193. function Main()
  194.   frmHub:RegBot(Bot.name, 1, Bot.desc, Bot.email )
  195.   FetchZodiacForToday() -- Get the thing.
  196.   zodiac_rc=""
  197.   for k, v in ipairs(zodiac) do
  198.     zodiac_rc=zodiac_rc.."$UserCommand 1 3 Horoscope\\"..v.."$<%[mynick]> !"..command.." "..v.."&#38;#124;|"
  199.   end
  200.   zodiac_rc=zodiac_rc:sub(1,-2)
  201.   SetTimer (3600*60000) -- Fire a timer, it will tick every day.
  202.   StartTimer()
  203. end
  204.  
  205. OnTimer = FetchZodiacForToday -- OK, another day passed by, get the stuff again.
  206.  
  207. function ChatArrival(user,data) -- Usual stuff: command processing, sending the results
  208.   local prf="[%"..table.concat(frmHub:GetPrefixes(), "%").."]"
  209.   data = data:sub(1,-2)
  210.   local cmd,sign = data:match("%b<>%s+"..prf.."(%S*)%s*(%S*)")
  211.   if cmd == command then
  212.     if not zodtbl[sign] then
  213.       user:SendPM(Bot.name,"Usage: "..frmHub:GetPrefixes()[1]..command.." <sign>\r\nAvailable signs:\r\n"..("-"):rep(25).."\r\n"..table.concat(zodiac,"\r\n"))
  214.     else
  215.       local f=io.open("zodiac/"..sign..".txt","r")
  216.       local contents = string.gsub(f:read("*a"),string.char(10), "\r\n")
  217.       f:close()
  218.       user:SendPM(Bot.name,"\r\n"..contents)
  219.     end
  220.     return 1
  221.   end
  222. end
  223.  
  224. function NewUserConnected(user)
  225.   user:SendData(zodiac_rc)
  226. end
  227.  
  228. OpConnected = NewUserConnected
  229.  
  230. --[[
  231. Copyright (c) 2007, bastya_elvtars
  232.  
  233. All rights reserved.
  234.  
  235. Redistribution and use in source and binary forms, with or without modification,
  236. are permitted provided that the following conditions are met:
  237.  
  238.     * Redistributions of source code must retain the above copyright notice, this
  239.       list of conditions and the following disclaimer.
  240.     * Redistributions in binary form must reproduce the above copyright notice,
  241.       this list of conditions and the following disclaimer in the documentation
  242.       and/or other materials provided with the distribution.
  243.     * Neither the name of the author nor the names of contributors may be used
  244.       to endorse or promote products derived from this code without specific
  245.       prior written permission.
  246.  
  247. THIS CODE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  248. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  249. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  250. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  251. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  252. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  253. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  254. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  255. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  256. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  257. CODE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  258.  
  259. ----------------------------------------------------------------------------------
  260.  
  261. This bot utilizes the GNU wget utiliy. That program is
  262. licensed under the GPL. It is bundled with the script
  263. and its source can be downloaded from:
  264.  
  265. http://www.gnu.org/software/wget/wget.html
  266.  
  267. The original binary is from:
  268.  
  269. http://users.ugent.be/~bpuype/wget/
  270. ]]
Everything could have been anything else and it would have just as much meaning.

Offline elgee

  • Junior Member
  • **
  • Posts: 24
  • Karma: +12/-1
Re: Horoscope script
« Reply #10 on: 07 February, 2008, 22:58:23 »
It's working here as well.
Looking much better now so thank you for this :)

Offline massive

  • Newbie
  • *
  • Posts: 9
  • Karma: +1/-5
Re: Horoscope script
« Reply #11 on: 11 October, 2012, 17:33:53 »
Hi, I have an error in my ptokax 0.4.1, shows me its:
Syntax ... ttrashe \ New Folder \ Ekzecutor \ scripts \ zodiac.lua: 226: attempt to call method 'SendData' (a nil value)

One solution, if you like it?

Offline ATAG

  • Scripter
  • Double Ace
  • ******
  • Posts: 111
  • Karma: +14/-0
  • secret things
    • Metin2 Hungarian Forum
Re: Horoscope script
« Reply #12 on: 14 October, 2012, 22:45:30 »
Quote
Horoscope script
? on: July 27, 2007, 01:40:18 am ?
You have to rewrite it, PtokaX has got new Lua API for years...

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 479
  • Karma: +209/-22
  • PtokaX developer
Re: Horoscope script
« Reply #13 on: 03 November, 2012, 10:42:32 »
 :P

Code: [Select]
--[[
Zodiac bot by bastya_elvtars
It gets the daily horoscope from a site and fetches it.

It will open a DOS window at the script startup and every
24 hour afterwards. It counts the 24 hours from the startup.
I suppose that sites are updated every 24 hours.

Note that updating blocks the hub for 10 or more seconds.
This is currently unavoidable because there is nothing that
supports coding async socket operations.

You can configure the command and the bot below.
]]

command="horoscope"

Bot=
  {
    name="Zodiac",
    email="zodiac@localhost",
    desc="Horoscope bot"
  }

-- Source follows. Do not edit below.

nl = "\n"

function HTML_ToText (file)
  -- Declare variables, load the file. Make tags lowercase.
  local text
  local f=io.open (file)
  if f then
    if f:seek("end") <= 0 then return end
    f:seek("set")
    text = f:read ("*a")
    f:close()
  end
  text = string.gsub (text,"(<([^>]-)>)",function (str) return str:lower() end)
  --[[
  First we kill the developer formatting (tabs, CR, LF)
  and produce a long string with no newlines and tabs.
  We also kill repeated spaces as browsers ignore them anyway.
  ]]
  local devkill=
    {
      ["("..string.char(10)..")"] = " ",
      ["("..string.char(13)..")"] = " ",
      ["("..string.char(15)..")"] = "",
      ["(%s%s+)"]=" ",
    }
  for pat, res in pairs (devkill) do
    text = string.gsub (text, pat, res)
  end
  -- Then we remove the header. We do this by stripping it first.
  text = string.gsub (text, "(<%s*head[^>]*>)", "<head>")
  text = string.gsub (text, "(<%s*%/%s*head%s*>)", "</head>")
  text = string.gsub (text, "(<head>,*<%/head>)", "")
  -- Kill all scripts. First we nuke their attribs.
  text = string.gsub (text, "(<%s*script[^>]*>)", "<script>")
  text = string.gsub (text, "(<%s*%/%s*script%s*>)", "</script>")
  text = string.gsub (text, "(<script>,*<%/script>)", "")
  -- Ok, same for styles.
  text = string.gsub (text, "(<%s*style[^>]*>)", "<style>")
  text = string.gsub (text, "(<%s*%/%s*style%s*>)", "</style>")
  text = string.gsub (text, "(<style>.*<%/style>)", "")
 
  -- Replace <td> and <th> with tabulators.
  text = string.gsub (text, "(<%s*td[^>]*>)","\t")
  text = string.gsub (text, "(<%s*th[^>]*>)","\t")
 
  -- Replace <br> with linebreaks.
  text = string.gsub (text, "(<%s*br%s*%/%s*>)",nl)
 
  -- Replace <li> with an asterisk surrounded by spaces.
  -- Replace </li> with a newline.
  text = string.gsub (text, "(<%s*li%s*%s*>)"," *  ")
  text = string.gsub (text, "(<%s*/%s*li%s*%s*>)",nl)
 
  -- <p>, <div>, <tr>, <ul> will be replaced to a double newline.
  text = string.gsub (text, "(<%s*div[^>]*>)", nl..nl)
  text = string.gsub (text, "(<%s*p[^>]*>)", nl..nl)
  text = string.gsub (text, "(<%s*tr[^>]*>)", nl..nl)
  text = string.gsub (text, "(<%s*%/*%s*ul[^>]*>)", nl..nl)
   
  -- Some petting with the <a> tags. :-P
--   local addresses,c = {},0
--   text=string.gsub(text,"<%s*a.-href=[\'\"](%S+)[\'\"][^>]*>(.-)<%s*%/*%s*a[^>]->", -- gets URL from a tag, and the enclosed name
--   function (url,name)
--     c = c + 1
--     name = string.gsub (name, "<([^>]-)>","") -- strip name from tags (e. g. images as links)
--     
--     -- We only consider the URL valid if the name contains alphanumeric characters.
--     if name:find("%w") then print(url, name, c) table.insert (addresses, {url, name}) return name.."["..#addresses.."]" else return "" end   
--   end)
 
  -- Nuke all other tags now.
  text = string.gsub (text, "(%b<>)","")
 
  -- Replace entities to their correspondant stuff where applicable.
  -- C# is owned badly here by using a table. :-P
  -- A metatable secures entities, so you can add them natively as keys.
  -- Enclosing brackets also get added automatically (capture!)
  local entities = {}
  setmetatable (entities,
  {
    __newindex = function (tbl, key, value)
      key = string.gsub (key, "(%#)" , "%%#")
      key = string.gsub (key, "(%&)" , "%%&")
      key = string.gsub (key, "(%;)" , "%%;")
      key = string.gsub (key, "(.+)" , "("..key..")")
      rawset (tbl, key, value)
    end
  })
  entities =
  {
    ["&nbsp;"] = " ",
    ["&bull;"] = " *  ",
    ["&lsaquo;"] = "<",
    ["&rsaquo;"] = ">",
    ["&trade;"] = "(tm)",
    ["&frasl;"] = "/",
    ["&lt;"] = "<",
    ["&gt;"] = ">",
    ["&copy;"] = "(c)",
    ["&reg;"] = "(r)",
    -- Then kill all others.
    -- You can customize this table if you would like to,
    -- I just got bored of copypasting. :-)
    -- http://hotwired.lycos.com/webmonkey/reference/special_characters/
    ["%&.+%;"] = "",
  }
  for entity, repl in pairs (entities) do
    text = string.gsub (text, entity, repl)
  end
  text = text..nl..nl..("-"):rep(27)..nl..nl
 
--   for k,v in ipairs (addresses) do
--     text = text.."["..k.."] "..v[1]..nl
--   end
--   if #addresses > 0 then
--     text=text..nl:rep(2)..("-"):rep(2)..nl
--     for key, tbl in ipairs(addresses) do
--       text = text..nl.."["..key.."]"..tbl[1]
--     end
--   end
 
  return text
 
end

zodiac=
  {
    "aquarius",
    "aries",
    "cancer",
    "capricorn",
    "gemini",
    "leo",
    "libra",
    "pisces",
    "sagittarius",
    "scorpio",
    "taurus",
    "virgo"
  }
 
zodtbl={}
 
function FetchZodiacForToday()
  local loc=string.gsub(Core.GetPtokaXPath(),"%/",[[\]]) -- We replace the / to \. Works around a PXLUA bug. :-P
  local x=os.clock()
  Core.SendToAll("<"..Bot.name.."> Getting the fresh horoscope. This slows down the hub, so please be patient.|") -- Get the batchfile created
  local f=io.open(Core.GetPtokaXPath().."scripts/zodiac/getpages.cmd","w+")
  f:write("@echo off\nREM This batch file is generated by the zodiac script.\nREM It will be overwritten on every update.\r\n")
  for _,val in ipairs (zodiac) do
    f:write(loc.."scripts\\zodiac\\wget.exe -O"..loc.."scripts\\zodiac\\"..val..".html http://www.freehoroscopedaily.com/"..val.."/\n")
  end
  f:close()

  os.execute (loc.."scripts\\zodiac\\getpages.cmd") -- Run it

  for _,sign in ipairs(zodiac) do -- Parse the HTML files. It is faster to do it right away.
    zodtbl[sign]=1
    local f=io.open(Core.GetPtokaXPath().."scripts/zodiac/"..sign..".txt","w+")
    f:write(HTML_ToText("scripts/zodiac/"..sign..".html"))
    f:close()
  end
 
  Core.SendToAll("<"..Bot.name.."> \r\nHoroscope fetched. It took "..os.clock()-x.." seconds. Check your horoscope with "..string.sub(SetMan.GetString(29),1,1)..command.." <sign>\r\nType "..
      string.sub(SetMan.GetString(29),1,1)..command.." for help!|")
end

function OnStartup()
  Core.RegBot(Bot.name, Bot.desc, Bot.email, true)
  FetchZodiacForToday() -- Get the thing.
  zodiac_rc=""
  for k, v in ipairs(zodiac) do
    zodiac_rc=zodiac_rc.."$UserCommand 1 3 Horoscope\\"..v.."$<%[mynick]> !"..command.." "..v.."&#124;|"
  end
  zodiac_rc=zodiac_rc:sub(1,-2)
  TmrMan.AddTimer(3600*60000) -- Fire a timer, it will tick every day.
end

OnTimer = FetchZodiacForToday -- OK, another day passed by, get the stuff again.

function ChatArrival(user,data) -- Usual stuff: command processing, sending the results
  local prf="[%"..SetMan.GetString(29).."]"
  data = data:sub(1,-2)
  local cmd,sign = data:match("%b<>%s+"..prf.."(%S*)%s*(%S*)")
  if cmd == command then
    if not zodtbl[sign] then
      Core.SendPmToUser(user, Bot.name,"Usage: "..string.sub(SetMan.GetString(29),1,1)..command.." <sign>\r\nAvailable signs:\r\n"..("-"):rep(25).."\r\n"..table.concat(zodiac,"\r\n"))
    else
      local f=io.open("scripts/zodiac/"..sign..".txt","r")
      local contents = string.gsub(f:read("*a"),string.char(10), "\r\n")
      f:close()
      Core.SendPmToUser(user, Bot.name,"\r\n"..contents)
    end
    return true
  end
end

function UserConnected(user)
  Core.SendToUser(user, zodiac_rc)
end

RegConnected = UserConnected
OpConnected = UserConnected

--[[
Copyright (c) 2007, bastya_elvtars

All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this
      list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of the author nor the names of contributors may be used
      to endorse or promote products derived from this code without specific
      prior written permission.

THIS CODE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
CODE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

----------------------------------------------------------------------------------

This bot utilizes the GNU wget utiliy. That program is
licensed under the GPL. It is bundled with the script
and its source can be downloaded from:

http://www.gnu.org/software/wget/wget.html

The original binary is from:

http://users.ugent.be/~bpuype/wget/
]]
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

Offline malhi

  • Junior Member
  • **
  • Posts: 17
  • Karma: +0/-1
Re: Horoscope script
« Reply #14 on: 29 November, 2014, 03:40:32 »
im getting all this when i type in hub not horoscope detail


[03:38] <Zodiac> Usage: !horoscope <sign>
Available signs:
-------------------------
aquarius
aries
cancer
capricorn
gemini
leo
libra
pisces
sagittarius
scorpio
taurus
virgo


nothing els i try to type all one by one nothing same thing open again how it will show daily update ?

Offline the-master

  • Triple Ace
  • **
  • Posts: 227
  • Karma: +10/-15
Re: Horoscope script
« Reply #15 on: 29 November, 2014, 11:08:28 »
Did you try !horoscope leo ?
Did you use the wget module?
« Last Edit: 29 November, 2014, 11:20:38 by the-master »
keep on sharing :)
dchub://kickincountryhub.no-ip.org

Offline malhi

  • Junior Member
  • **
  • Posts: 17
  • Karma: +0/-1
Re: Horoscope script
« Reply #16 on: 09 December, 2014, 23:38:19 »
i only run horoscore file nothing els. do i need anything els 2 ?

Offline the-master

  • Triple Ace
  • **
  • Posts: 227
  • Karma: +10/-15
Re: Horoscope script
« Reply #17 on: 10 December, 2014, 17:51:58 »
Yes, you need the wget part to be able to use it.
Download the zipfile from first post and use updated script, it works  :)
« Last Edit: 10 December, 2014, 17:54:52 by the-master »
keep on sharing :)
dchub://kickincountryhub.no-ip.org

PtokaX forum

Re: Horoscope script
« Reply #17 on: 10 December, 2014, 17:51:58 »