Automatically fills x & y position from server
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Mon, 28 May 2012 22:33:27 +0000 (22:33 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Mon, 28 May 2012 22:33:27 +0000 (22:33 +0000)
members.py

index 759b614b550f7136d1a7c1833c5363051f6e7f38..a98eccfbd5801e2ecf8f980a8ae1c723accfd71d 100755 (executable)
@@ -205,6 +205,22 @@ def members_fetch(alliance_tag=None):
     return members
 
 
+def members_fill_positions(newmembers):
+    for nick, data in newmembers.items():
+        if data['x'] is not None:
+            continue
+
+        httpresponse = httpopen(BASE_URL + '/Membre.php?Pseudo=' + nick)
+        html = httpresponse.read().decode('utf-8')
+
+        match = re.match('.*x=([0-9]+) et y=([0-9]+)', html, re.DOTALL|re.MULTILINE)
+        x = int(match.group(1))
+        y = int(match.group(2))
+        newmembers[nick]['x'] = x
+        newmembers[nick]['y'] = y
+        logging.debug('%s has position %s %s', nick, x, y)
+        break # XXX
+
 def copy_existing_data(oldmembers, newmembers):
     '''
     Check if newmembers contains some keys and if missing, copy them from
@@ -480,6 +496,8 @@ if __name__ == '__main__':
 
     if oldmembers is not None:
         copy_existing_data(oldmembers, newmembers)
+        if not options.new_archive_filename:
+            members_fill_positions(newmembers)
         csvfilename = os.path.join(BASE_DIRECTORY, 'results.csv')
         csvfile = open(csvfilename, mode='a', encoding='utf-8')
         field_compare(oldmembers, newmembers, csvfile)