Added delay to spread server hits within minutes
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 27 May 2012 17:05:21 +0000 (17:05 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 27 May 2012 17:05:21 +0000 (17:05 +0000)
Added --quick option

members.py

index 8933084fef2ac6cb539151653d7a52a1fcc7eaa4..998ebd4349e705c98ea23c04c042f2f6156d8d8e 100755 (executable)
@@ -10,6 +10,7 @@ import re
 import logging
 from datetime import datetime
 import calendar
+import random
 import urllib.request
 from http.cookiejar import CookieJar
 
@@ -296,7 +297,6 @@ def field_compare(oldmembers, newmembers, csvfile):
                     newfield1=newfield[nick],
                     deltafield=delta,
                     nicedeltafield=number_format(delta),
-                    percent=percent,
                     ))
             else:
                 txtchanges.append("%s a rejoint l'alliance avec %s cm²" % (nick, number_format(delta)))
@@ -331,6 +331,11 @@ if __name__ == '__main__':
         help="Working directory, including config.py, archives and results. "
              "Relative to HOME unless it starts with /. "
              "Default is '%default'.")
+    parser.add_option('--quick',
+        action='store_true', dest='quick', default=False,
+        help="Don't sleep a random delay before hiting the server. "
+             "The programme usually wait between 0 and 59s, so that "
+             "there is no pick usage on a round minute")
     parser.add_option('--members-name',
         dest='archive_filename', metavar='FILENAME', default="archive.py",
         help="Override filename containing old data. "
@@ -359,6 +364,10 @@ if __name__ == '__main__':
         BASE_DIRECTORY = os.path.join(HOME, options.directory)
     logging.basicConfig(level=loglevel, format='%(asctime)s %(levelname)s %(message)s', datefmt=DATETIME_FORMAT)
 
+    if not options.quick:
+        delay = random.randint(0,59)
+        sleep(delay)
+
     read_config(BASE_DIRECTORY)
 
     members_filename = os.path.join(BASE_DIRECTORY, options.archive_filename)