Added hantill id scraping, and output in members.csv
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Wed, 13 Jun 2012 15:33:35 +0000 (15:33 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Wed, 13 Jun 2012 15:33:35 +0000 (15:33 +0000)
members.py

index 2059153e4e91c607d52434d890e374b62bc75505..2ae321b39614171c4b86ccc340044cf460053a34 100755 (executable)
@@ -207,28 +207,38 @@ def members_fetch(alliance_tag=None):
 
 def members_fill_positions(newmembers):
     for nick, data in newmembers.items():
-        if data['x'] is not None:
+        if data['id'] is not None:
             continue
 
         httpresponse = httpopen(BASE_URL + '/Membre.php?Pseudo=' + nick)
         html = httpresponse.read().decode('utf-8')
 
+        f = open("debug.html", mode='w+', encoding='utf-8')
+        f.write(html)
+
         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)
+
+        match=re.match('.*commerce.php\\?ID=([0-9]+).*', html, re.DOTALL|re.MULTILINE)
+        _id = int(match.group(1))
+        newmembers[nick]['id'] = _id
+
+        logging.debug('%s has position %s %s and ID %s', nick, x, y, _id)
+
+        break # only one at a time (debug)
 
 def copy_existing_data(oldmembers, newmembers):
     '''
     Check if newmembers contains some keys and if missing, copy them from
     oldmembers:
     colonized, active: if alliance is forced, these keys are not fetched
-    x, y: only fetch them when neded.
+    x, y, id: only fetch them when neded.
     '''
     for nick, data in newmembers.items():
-        for key in ['colonized', 'active', 'x', 'y' ]:
+        for key in ['colonized', 'active', 'x', 'y', 'id' ]:
             if data.get(key, None) is None:
                 # missing or None
                 value = oldmembers.get(nick, {}).get(key, None)
@@ -518,7 +528,7 @@ if __name__ == '__main__':
         members_csvfilename = os.path.join(BASE_DIRECTORY, "members.csv")
         members_csvfilename_new = members_csvfilename + '.new'
         f = open(members_csvfilename_new, mode='w', encoding='utf-8')
-        f.write('grade,nick,field,techno,anthill,active,colonized,x,y\n')
+        f.write('grade,nick,field,techno,anthill,active,colonized,x,y,id\n')
         for nick, data in newmembers.items():
             data = [
                 data['grade'],
@@ -530,6 +540,7 @@ if __name__ == '__main__':
                 data['colonized'],
                 data['x'],
                 data['y'],
+                data['id'],
                 ]
             data = [ str(x) for x in data ]
             f.write(','.join(data) + '\n')