Change the way privatebin paste denies are handled. Now we try max 5 times to find a usable instance.

This commit is contained in:
kalzu rekku 2024-07-28 22:13:39 +03:00
parent 06c01c23c4
commit 9477dde1ec

View File

@ -422,17 +422,20 @@ def publish_to_cpaste(file, paste_url='https://cpaste.org'):
output = '%s%s#%s DELETE TOKEN: %s' % (paste_url, paste_id, paste_decrypt, paste_deletetoken)
return output
def publish_to_multiple_cpastes(file, num_instances=3):
def publish_to_multiple_cpastes(file, num_instances=3, max_attempts=5):
instances = get_list_of_instances()
# Ensure we don't try to select more instances than available
num_instances = min(num_instances, len(instances))
# Randomly select num_instances from the list
selected_instances = random.sample(instances, num_instances)
results = {}
for instance in selected_instances:
attempts = 0
while len(results) < num_instances and attempts < max_attempts:
# Randomly select an instance that hasn't been tried yet
available_instances = [i for i in instances if i not in results]
if not available_instances:
break # No more instances to try
instance = random.choice(available_instances)
attempts += 1
try:
# Extract the base URL from the instance link
base_url = instance.split('?')[0]
@ -440,6 +443,10 @@ def publish_to_multiple_cpastes(file, num_instances=3):
results[base_url] = result
except Exception as e:
print(f"Failed to publish to {instance}: {str(e)}")
# We don't add this instance to results, so it might be retried
if len(results) < num_instances:
print(f"Warning: Only managed to publish to {len(results)} instances out of {num_instances} requested.")
return results