Now also monitor active/inactive status change
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 27 May 2012 20:15:31 +0000 (20:15 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 27 May 2012 20:15:31 +0000 (20:15 +0000)
members.py

index 998ebd4349e705c98ea23c04c042f2f6156d8d8e..7192c28907cae1cdc9ebe169770fc6cea0a97268 100755 (executable)
@@ -20,7 +20,7 @@ import htmlentities
 """
 csv file format:
 DateTime,Action,Nick1,Grade1,OldField1,NewField1,Nick2,Grade2,OldField2,NewField2,FloodField,FieldLossPercent,Text
-Action is one of: JOIN, QUIT, WIN, LOSS, FLOOD, NOOP
+Action is one of: JOIN, QUIT, WIN, LOSS, FLOOD, NOOP, ACT
 
 Exemples:
 NOOP,,,,,,,,,,,No changes
@@ -32,6 +32,8 @@ FLOOD,filoux,Passeur 003,55813865,74225093,yosemite,Passeur 004,51142304,3273107
 FLOOD,Nick1,Grade1,100,102,Nick2,Grade2,100,99,1,1.00,Nick1 a pris 1 cm² à Nick2 (1.00%)
 FLOOD,Nick1,Grade1,100,102,Nick3,Grade3,100,99,1,1.00,Nick1 a pris 1 cm² à Nick3 (1.00%)
 
+ACT,Nick1,Grade1,100,100,,,,,,,Nick1 est en vacances
+
 Note that in last 2 lines exemple, NewField1 is 102 that is different from 100+1 because of multiple floods.
 """
 
@@ -314,6 +316,24 @@ def field_compare(oldmembers, newmembers, csvfile):
     for txtchange in txtchanges2:
         csvfile.write(time.strftime(DATETIME_FORMAT)+','+txtchange+'\n')
 
+def activity_compare(oldmembers, newmembers, csvfile):
+    txtchanges2 = []
+    for nick, data in newmembers.items():
+        newa = data.get('active', None)
+        olda = oldmembers.get(nick, {}).get('active', None)
+        if newa and olda and newa != olda:
+            txtchanges2.append('ACT,{nick1},{grade1},{olddata1},{newdata1},,,,,,,{nick1} est maintenant {lowernewdata1}'.format(
+                nick1=nick,
+                grade1=newmembers[nick]['grade'],
+                olddata1=olda,
+                newdata1=newa,
+                lowernewdata1=newa.lower(),
+                ))
+
+    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()
@@ -394,6 +414,7 @@ if __name__ == '__main__':
         csvfilename = os.path.join(BASE_DIRECTORY, 'results.csv')
         csvfile = open(csvfilename, mode='a', encoding='utf-8')
         field_compare(oldmembers, newmembers, csvfile)
+        activity_compare(oldmembers, newmembers, csvfile)
     
     # Save archive only after processing, just in case it crashes
     if not options.dryrun: