chiark / gitweb /
yoweb-scrape: new flag and ocean functionality - war-flag-of, also print sinking... 6.8.0
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 16 Jan 2011 20:52:10 +0000 (20:52 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 16 Jan 2011 20:52:10 +0000 (20:52 +0000)
yoweb-scrape

index f9976b8..db5dc13 100755 (executable)
@@ -409,18 +409,31 @@ class CrewInfo(SomethingSoupInfo):
        def __str__(self):
                return `(self.crew, self.msgs)`
 
+class FlagRelation():
+       # Public data members (put there by hand by creater)
+       #       other_flagname
+       #       other_flagid
+       #       yoweb_heading
+       #       this_declaring
+       #       other_declaring_min
+       #       other_declaring_max
+       # where {this,other}_declaring{,_min,_max} are:
+       #       -1      {this,other} is declaring war
+       #        0      {this,other} is not doing either
+       #       +1      {this,other} is allying
+       def __repr__(self):
+               return '<FlagRelation %s %d/%d..%d %s %s>' % (
+                       self.yoweb_heading, self.this_declaring,
+                       self.other_declaring_min, self.other_declaring_max,
+                       self.other_flagname, self.other_flagid)
+
 class FlagInfo(SomethingSoupInfo):
        # Public data members (after init):
        #
        #   flagid
        #   name        #               string
        #
-       #   relations[n] = (otherflagname, otherflagid, [stringfromyoweb],
-       #               thisdeclaring, otherdeclaringmin, otherdeclaringmax)
-       #               # where {this,other}declaring{,min,max} are:
-       #               #       -1      {this,other} is declaring war
-       #               #        0      {this,other} is not doing either
-       #               #       +1      {this,other} is allying
+       #   relations[n] = FlagRelation
        #   relation_byname[otherflagname] = relations[some_n]
        #   relation_byid[otherflagname] = relations[some_n]
        #
@@ -472,7 +485,13 @@ class FlagInfo(SomethingSoupInfo):
                        if rel: return 'flag id twice!'
                        if flagname in self.relation_byname:
                                return 'flag name twice!'
-                       rel = (flagname,flagid,head, thisdecl,othermin,othermax)
+                       rel = FlagRelation()
+                       rel.other_flagname = flagname
+                       rel.other_flagid = flagid
+                       rel.yoweb_heading = head
+                       rel.this_declaring = thisdecl
+                       rel.other_declaring_min = othermin
+                       rel.other_declaring_max = othermax
                        self.relations.append(rel)
                        self.relation_byid[flagid] = rel
                        self.relation_byname[flagid] = rel
@@ -1376,6 +1395,7 @@ def do_crew_of(args, bu):
 
 def do_flag_of(args, bu):
        fi = prep_flag_of(args, bu)
+       print fi
 
 def do_standings_crew_of(args, bu):
        ci = prep_crew_of(args, bu, 60)
@@ -1424,34 +1444,63 @@ def do_embargoes(args, bu):
                        if flag is None: print ''; continue
                        delim = ''
                        for rel in flag.relations:
-                               (oname, oid, dummy, thisdeclaring,
-                                       odeclaringmin,odeclaringmax) = rel
-                               if thisdeclaring >= 0: continue
+                               if rel.this_declaring >= 0: continue
                                wr(delim)
-                               wr(oname)
+                               wr(rel.other_flagname)
                                delim = '; '
                        print ''
 
 def do_embargoes_flag_of(args, bu):
        progressreporter.doing('fetching flag info')
        fi = prep_flag_of(args, bu)
+       if fi is None:
+               progressreporter.stop()
+               print 'Pirate is not in a flag.'
+               return
+
        oi = OceanInfo(IslandFlagInfo)
+
        progressreporter.stop()
+       print ''
+
        any = False
        for islename in sorted(oi.islands.keys()):
                isle = oi.islands[islename]
                flag = isle.flag
                if flag is None: continue
                for rel in flag.relations:
-                       (oname, oid, dummy, thisdeclaring,
-                               odeclaringmin,odeclaringmax) = rel
-                       if thisdeclaring >= 0: continue
-                       if oid != fi.flagid: continue
+                       if rel.this_declaring >= 0: continue
+                       if rel.other_flagid != fi.flagid: continue
                        if not any: print 'EMBARGOED:'
                        any = True
-                       print " %-30s (%s)" % (islename, flag.name)
+                       print "  %-30s (%s)" % (islename, flag.name)
        if not any:
                print 'No embargoes.'
+       print ''
+
+       war_flag(fi)
+       print ''
+
+def do_war_flag_of(args, bu):
+       fi = prep_flag_of(args, bu)
+       war_flag(fi)
+
+def war_flag(fi):
+       any = False
+       for certain in [True, False]:
+               anythis = False
+               for rel in fi.relations:
+                       if rel.this_declaring >= 0: continue
+                       if (rel.other_declaring_max < 0) != certain: continue
+                       if not anythis:
+                               if certain: m = 'SINKING PvP'
+                               else: m = 'RISK OF SINKING PvP'
+                               print '%s (%s):' % (m, rel.yoweb_heading)
+                       anythis = True
+                       any = True
+                       print " ", rel.other_flagname
+       if not any:
+               print 'No sinking PvP.'
 
 #----- modes which use the chat log parser are quite complex -----
 
@@ -1784,7 +1833,7 @@ actions:
  yoweb-scrape [--ocean OCEAN ...] standings-crew-of PIRATE
  yoweb-scrape [--ocean OCEAN ...] track-chat-log CHAT-LOG
  yoweb-scrape [--ocean OCEAN ...] ocean|embargoes
- yoweb-scrape [--ocean OCEAN ...] embargoes-flag-of PIRATE
+ yoweb-scrape [--ocean OCEAN ...] war-flag-of|embargoes-flag-of PIRATE
  yoweb-scrape [options] ship-aid CHAT-LOG  (must be .../PIRATE_OCEAN_chat-log*)
 
 display modes (for --display) apply to ship-aid: