def archive_group(groupName, mode="update"): log("\nArchiving group '" + groupName + "', mode: " + mode + " , on " + time.strftime("%c"), groupName) startTime = time.time() msgsArchived = 0 if mode == "retry": #don't archive any messages we already have #but try to archive ones that we don't, and may have #already attempted to archive min = 1 elif mode == "update": #start archiving at the last+1 message message we archived mostRecent = 1 if os.path.exists(groupName): oldDir = os.getcwd() os.chdir(groupName) for file in glob.glob("*.json"): if int(file[0:-5]) > mostRecent: mostRecent = int(file[0:-5]) os.chdir(oldDir) min = mostRecent elif mode == "restart": #delete all previous archival attempts and archive everything again if os.path.exists(groupName): shutil.rmtree(groupName) min = 1 else: print ("You have specified an invalid mode (" + mode + ").") print ("Valid modes are:\nupdate - add any new messages to the archive\nretry - attempt to get all messages that are not in the archive\nrestart - delete archive and start from scratch") sys.exit() if not os.path.exists(groupName): os.makedirs(groupName) max = group_messages_max(groupName) for x in range(min,max+1): if not os.path.isfile(groupName + '/' + str(x) + ".json"): print ("Archiving message " + str(x) + " of " + str(max)) sucsess = archive_message(groupName, x) if sucsess == True: msgsArchived = msgsArchived + 1 log("Archive finished, archived " + str(msgsArchived) + ", time taken is " + str(time.time() - startTime) + " seconds", groupName)