Skip to content

Instantly share code, notes, and snippets.

@Eluvatar
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eluvatar/9176d21ef065b87eb7f4 to your computer and use it in GitHub Desktop.
Save Eluvatar/9176d21ef065b87eb7f4 to your computer and use it in GitHub Desktop.
fragment from toy.rb for dealing with factbooks
# a method off of an object which represents a nation (session)
def factbook( self, id_, name, cat, factbook ):
url="/template-overall=none/page=lodge_dispatch"
query = { 'submitbutton' : ' Post ', 'edit': id_, 'localid': self.localid, 'message':factbook, 'dname' : name, 'dcategory' : 1, 'dcategory1' : int(cat) }
qs = urllib.urlencode(query)
res=trawler.request( path = url, query=qs, session = "pin={0}".format(self.pin()) )
doc = res.read()
m = re.compile('^<p class="error">.*$').match(doc):
if m:
print m.group(0)
self.localid = self.get_localid()
return re.compile('<p class="info">Factbook edited\.').match(doc)
# a method off of an object which represents a nation (session)
def factbook( id, name, cat, factbook )
url="http://www.nationstates.net/template-overall=none/page=lodge_dispatch"
post_hash = { :submitbutton => ' Post ', :edit => id, :localid => localid, :message => CGI.escape(factbook), :dname => CGI.escape(name), :dcategory => 1, :dcategory1 => cat.to_i }
post_string = post_hash.collect {|a| a.join('=')}.join('&')
res=Curld.request( :get => url, :post => post_string, :sess => "pin=#{pin}" )
if res =~ /^<p class="error">.*$/
puts $~[0]
end
@localid = get_localid
return res =~ /<p class="info">Factbook edited./
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment