colonized field now contains colonizer name rather than True/False
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Fri, 18 Jan 2013 19:58:16 +0000 (19:58 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Fri, 18 Jan 2013 19:58:16 +0000 (19:58 +0000)
members.py

index 8c7aac217a0ed1e2769848909453a4ca375bc37e..2fc4ab21351f92f738322e88fed618e35bf73763 100755 (executable)
@@ -179,7 +179,7 @@ def members_fetch(alliance_tag=None):
             techno = int(get_merged_leaf_content(row[5]))
             anthill = int(get_merged_leaf_content(row[6]))
             active = get_elem(row[7], 'img')[0].attributes['alt']
-            colonized = len(get_elem(row[8], 'img')) == 1
+            colonized = len(get_elem(row[8], 'img')) == 1 # True will become a string, see bellow
             #print(nick, grade, field, techno, anthill, active, colonized)
 
         else:
@@ -210,7 +210,7 @@ def members_fetch(alliance_tag=None):
 
 def members_fill_positions(newmembers):
     for nick, data in newmembers.items():
-        if data['id'] is not None:
+        if data['id'] is not None and data['colonized'] != True:
             continue
 
         httpresponse = httpopen(BASE_URL + '/Membre.php?Pseudo=' + nick)
@@ -229,7 +229,13 @@ def members_fill_positions(newmembers):
         _id = int(match.group(1))
         newmembers[nick]['id'] = _id
 
-        logging.debug('%s has position %s %s and ID %s', nick, x, y, _id)
+        match=re.match('.*Fourmilière soumise par <a href="Membre.php\\?Pseudo=([^"]+)', html, re.DOTALL|re.MULTILINE)
+        if match:
+            newmembers[nick]['colonized'] = match.group(1)
+        else:
+            newmembers[nick]['colonized'] = False
+
+        logging.debug('%s has position %s %s and ID %s. Colonized:%s', nick, x, y, _id, newmembers[nick]['colonized'])
 
         break # only one at a time (debug)
 
@@ -246,6 +252,10 @@ def copy_existing_data(oldmembers, newmembers):
                 # missing or None
                 value = oldmembers.get(nick, {}).get(key, None)
                 newmembers[nick][key] = value
+        if data.get('colonized', None) == True:
+            value = oldmembers.get(nick, {}).get('colonized', True)
+            if isinstance(value, str):
+                newmembers[nick]['colonized'] = value
 
 def members_to_field(members):
     """
@@ -395,9 +405,15 @@ def colonized_compare(oldmembers, newmembers, csvfile):
         oldc = oldmembers.get(nick, {}).get('colonized', None)
         if newc is not None and oldc is not None and newc != oldc:
             if newc:
-                txt = "s'est fait colonisé"
+                if oldc == True and isinstance(newc, str):
+                    continue # old versions of script had only True/False
+                txt = "s'est fait coloniser"
+                if newc != True:
+                    txt += " par " + newc
             else:
                 txt = "n'est plus colonisé"
+                if oldc != True:
+                    txt += " par " + oldc
             publish_line(csvfile, 
                 'COLON,{nick1},{grade1},{olddata1},{newdata1},,,,,,{nick1} {txt}',
                 nick1=nick,