Add colonization monitoring
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 27 May 2012 20:35:37 +0000 (20:35 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 27 May 2012 20:35:37 +0000 (20:35 +0000)
members.py

index 616c4224ba2e3f732b79bd1d9cc967972efbc152..56dccfba8d266c5afee8ec0e7cbe5b270317a075 100755 (executable)
@@ -33,6 +33,8 @@ FLOOD,Nick1,Grade1,100,102,Nick2,Grade2,100,99,1,1.00,Nick1 a pris 1 cm² à Nic
 FLOOD,Nick1,Grade1,100,102,Nick3,Grade3,100,99,1,1.00,Nick1 a pris 1 cm² à Nick3 (1.00%)
 
 ACT,Nick1,Grade1,Actif,En vacances,,,,,,,Nick1 est maintenant en vacances
+COLON,Nick1,Grade1,False,True,,,,,,,Nick1 s'est fait colonisé
+COLON,Nick1,Grade1,True,False,,,,,,,Nick1 n'est plus colonisé
 
 Note that in last 2 lines exemple, NewField1 is 102 that is different from 100+1 because of multiple floods.
 """
@@ -325,6 +327,28 @@ def activity_compare(oldmembers, newmembers, csvfile):
         logging.info(txtchange.split(',')[-1])
         csvfile.write(time.strftime(DATETIME_FORMAT)+','+txtchange+'\n')
 
+def colonized_compare(oldmembers, newmembers, csvfile):
+    txtchanges2 = []
+    for nick, data in newmembers.items():
+        newc = data.get('colonized', None)
+        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é"
+            else:
+                txt = "n'est plus colonisé"
+            txtchanges2.append('COLON,{nick1},{grade1},{olddata1},{newdata1},,,,,,,{nick1} {txt}'.format(
+                nick1=nick,
+                grade1=newmembers[nick]['grade'],
+                olddata1=str(oldc),
+                newdata1=str(newc),
+                txt=txt,
+                ))
+
+    for txtchange in txtchanges2:
+        logging.info(txtchange.split(',')[-1])
+        csvfile.write(time.strftime(DATETIME_FORMAT)+','+txtchange+'\n')
+
 if __name__ == '__main__':
     from optparse import OptionParser
     parser = OptionParser()
@@ -406,6 +430,7 @@ if __name__ == '__main__':
         csvfile = open(csvfilename, mode='a', encoding='utf-8')
         field_compare(oldmembers, newmembers, csvfile)
         activity_compare(oldmembers, newmembers, csvfile)
+        colonized_compare(oldmembers, newmembers, csvfile)
     
     # Save archive only after processing, just in case it crashes
     if not options.dryrun: