-
-
Save Eluvatar/9176d21ef065b87eb7f4 to your computer and use it in GitHub Desktop.
fragment from toy.rb for dealing with factbooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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