Added options to override where old & new data is read from
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sat, 26 May 2012 11:29:35 +0000 (11:29 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sat, 26 May 2012 11:29:35 +0000 (11:29 +0000)
members.py

index 2b8419adf52e8118fa8ca8d430be2b9dcc9eda5f..9f800b5152477fe4b841fd9e43b210f18fc3c880 100755 (executable)
@@ -109,7 +109,7 @@ def number_format(i):
     return result
 
 
-def members_get(alliance_tag=None):
+def members_fetch(alliance_tag=None):
     #httpresponse = httpopen(BASE_URL + '/')
     #html = httpresponse.read().decode('utf-8')
     #print(html)
@@ -273,13 +273,22 @@ if __name__ == '__main__':
         action='store_true', dest='quiet', default=False,
         help="quiet mode")
     parser.add_option('-a', '--alliance',
-        dest='alliance',
-        help="alliance tag. default is to process player own alliance.")
+        dest='alliance', metavar="TAG",
+        help="Default is to process player own alliance.")
     parser.add_option('--dir',
         dest='directory', default='.fourmizzz',
         help="Working directory, including config.py, archives and results. "
              "Relative to HOME unless it starts with /. "
              "Default is '%default'.")
+    parser.add_option('--members-name',
+        dest='archive_filename', metavar='FILENAME', default="archive.py",
+        help="Override filename containing old data. "
+        "Default is '%default' in Working directory. "
+        "See --dir.")
+    parser.add_option('--new-members-name',
+        dest='new_archive_filename', metavar='FILENAME',
+        help="Read new members data from a file. "
+        "Default is to fetch data from antzzz server.")
     parser.add_option('--dry-run',
         action='store_true', dest='dryrun', default=False,
         help="don't store result in archives.")
@@ -303,7 +312,7 @@ if __name__ == '__main__':
 
     read_config(BASE_DIRECTORY)
 
-    members_filename = os.path.join(BASE_DIRECTORY, 'archive.py')
+    members_filename = os.path.join(BASE_DIRECTORY, options.archive_filename)
     oldmembers = None
     try:
         f = open(members_filename, mode='r+', encoding='utf-8')
@@ -316,7 +325,11 @@ if __name__ == '__main__':
     else:
         oldmembers = eval(f.read())
     
-    newmembers = members_get(options.alliance)
+    if options.new_archive_filename:
+        newf = open(options.new_archive_filename, mode='r', encoding='utf8')
+        newmembers = eval(newf.read())
+    else:
+        newmembers = members_fetch(options.alliance)
 
     if oldmembers is not None:
         field_compare(oldmembers, newmembers)