Renamed a few things into proper (better) english
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sat, 26 May 2012 10:30:37 +0000 (10:30 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sat, 26 May 2012 10:30:37 +0000 (10:30 +0000)
members.py

index 404e3049958a7566d4cc59b702dea72fc44408f6..0e3a62caa82f3e49048d0adad25fee5833e8c922 100755 (executable)
@@ -106,7 +106,7 @@ def number_format(i):
     return result
 
 
-def tdc_get(alliance_tag=None):
+def members_get(alliance_tag=None):
     #httpresponse = httpopen(BASE_URL + '/')
     #html = httpresponse.read().decode('utf-8')
     #print(html)
@@ -203,21 +203,21 @@ def members_to_field(members):
 
 def field_compare(oldmembers, newmembers):
     
-    oldtdc = members_to_field(oldmembers)
-    newtdc = members_to_field(newmembers)
+    oldfield = members_to_field(oldmembers)
+    newfield = members_to_field(newmembers)
 
     changes = {}
     txtchanges = []
-    for nick in newtdc.keys():
-        told = oldtdc.get(nick, 0)
-        tnew = newtdc[nick]
+    for nick in newfield.keys():
+        told = oldfield.get(nick, 0)
+        tnew = newfield[nick]
         if told == tnew:
             continue
         changes[nick] = { 'old': told, 'new': tnew, 'delta': tnew-told }
     
-    for nick in oldtdc.keys():
-        if nick not in newtdc:
-            told = oldtdc[nick]
+    for nick in oldfield.keys():
+        if nick not in newfield:
+            told = oldfield[nick]
             tnew = 0
             changes[nick] = { 'old': told, 'new': 0, 'delta': -told }
     #for nick, change in changes.items():
@@ -237,22 +237,21 @@ def field_compare(oldmembers, newmembers):
                 continue # already done
             if changes[nick2]['delta'] != -delta:
                 continue # not the good one
-            percent = float(oldtdc[nick2] - newtdc[nick2]) / oldtdc[nick2] * 100.
+            percent = float(oldfield[nick2] - newfield[nick2]) / oldfield[nick2] * 100.
             txtchanges.append('%s a pris %s cm² à %s (%.2f%%)' % (nick, number_format(delta), nick2, percent))
             changes[nick]['delta'] = 0
             changes[nick2]['delta'] = 0
 
-                
     for nick, change in changes.items():
         delta = change['delta']
         if delta < 0:
-            if nick in newtdc:
-                percent = float(-delta) / oldtdc[nick] * 100.
+            if nick in newfield:
+                percent = float(-delta) / oldfield[nick] * 100.
                 txtchanges.append('%s a perdu %s cm² (%.2f%%)' % (nick, number_format(-delta), percent))
             else:
                 txtchanges.append("%s a quité l'alliance avec %s cm²" % (nick, number_format(-delta)))
         elif delta > 0:
-            if nick in oldtdc:
+            if nick in oldfield:
                 txtchanges.append('%s a gagné %s cm²' % (nick, number_format(delta)))
             else:
                 txtchanges.append("%s a rejoint l'alliance avec %s cm²" % (nick, number_format(delta)))
@@ -314,7 +313,7 @@ if __name__ == '__main__':
     else:
         oldmembers = eval(f.read())
     
-    newmembers = tdc_get(options.alliance)
+    newmembers = members_get(options.alliance)
 
     if oldmembers is not None:
         field_compare(oldmembers, newmembers)