Wikepedia Search

By Gecko321 on Jun 22, 2012

Searches Wikipedia and displays result for search.

Based on FordLawnmower's version

bind pub - !wiki wiki

proc wiki {nick host hand chan arg} {
  package require http
  set arg [string map {{ } \%20} $arg]

  set url "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=large&q=$arg+site:en.wikipedia.org"
  set page [http::data [http::geturl $url]]
  if {[regexp {\"url\":\"([^\"]*)\"} $page a link]} {
    if {[regexp {wikipedia\.org} $link]} { putserv "PRIVMSG $chan :[wikipedia $link]" }
  } else { putserv "PRIVMSG $chan :Nothing found on Wikipedia! Please refine your search and check your spelling." }
}
proc wikipedia {url} {
  package require http  
  set page [http::data [http::geturl $url]]
  if {[regexp {may refer to:} $page] || [regexp {HTTP\/1\.0 403} $page]} {
    return "Nothing found on Wikipedia! Please refine your search and check your spelling."
  } elseif {[regexp -line {<b>(.*)</p>} $page a result] || [regexp -line {<p>(.*)</p>} $page a result]} {
    set result [dehex [strip $result]]
    set result [shorten $result 50]
    return "Wikipedia: $result : $url"
  }
}  

proc shorten {text limit} {
  foreach i $text { incr start 
    lappend wiki $i
    if {$start == $limit} { return $wiki }
  }
  return $wiki
}
proc dehex {string} {
  regsub -all {[\[\]]} $string "" string
  set string [subst [regsub -nocase -all {\&#([0-9]{3});} $string {[format %c \1]}]]
  return [string map {&quo\te; \"} $string]
}
proc strip {string} {
  regsub -all {<[^<>]+>} $string "" string
  regsub -all {\[\d+\]} $string "" string
  return $string
}

putlog "WikiPedia Search"

Comments

Sign in to comment.
FordLawnmower   -  Jan 24, 2013

Could you please post credits on the posts that you borrowed code from.

Just glancing at it, these are all from my posts.
http://www.hawkee.com/snippet/9549/
http://www.hawkee.com/snippet/9548/
http://www.hawkee.com/snippet/9547/
http://www.hawkee.com/snippet/9545/
http://www.hawkee.com/snippet/9540/

Conscious  -  Jan 24, 2013

Also, http://www.mediawiki.org/wiki/API - no need to use a google search for this TBH.

Hawkee  -  Jan 24, 2013

@FordLawnmower Did he change enough that he added value to them? If not I'll remove them.

Stewie1k94  -  Jan 26, 2013

I think these are just TCL version of Ford_Lawnmowers codes, but I do think a link to Ford's should be posted with some credit.

VxD aka DEATHJ0KER  -  Jan 26, 2013

is right always indicate the source from which it was taken the code of even a single alias ... Often many scripters exert their code also inspired by others. Better indicate those coming from this theory, in the case in which the code is improved ...
This will surely regard to both and to the global community, who has produced and who was ripped. I mean not just change the name of the script, but I mean those who use the structure of the non-proprietary codes for any function.
Many begin with the rip and evolve with their ideas and then I admit this, but I will not tolerate this by advanced programmers ....

What can I say more ... Ford is known throughout the world for scripts that often carefully explains the individual functions, perhaps too detailed.
It happens the code theory it is possible to rewrite it in countless mode, at times equal or similar in some points because of the limitations of the technology.
Just copy does not lead to anything, if only to a very bad shape as evident in this case.

In any case, I wanted to tell you that I think you all have ripped the theorem of Pythagoras to reach your intellectual level and this I will never forgive LoL

FordLawnmower  -  Jan 26, 2013

@Hawkee The scripts I mentioned were changed to use the tcl package http instead of the raw socket method that I use. This is useful for people who would prefer to use http.
@Gecko321 Thanks for posting the credit. I'm sorry I was so rude. I had a long day and took it out on your post. I will edit my comment to not be so harsh.
@Stewie1k94 Actually my tcl versions of these scripts were based on my mIRC versions. These were based on my tcl scripts.

Stewie1k94  -  Jan 26, 2013

Ah, okay... I just don't like it when I see someone post something that isn't completely there snippet and not add some credit to the original author.

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.