Last active
December 21, 2020 15:44
-
-
Save beaukinstler/5419c41b18f208c9763e642aa04538f8 to your computer and use it in GitHub Desktop.
A script to create dummy files based on an existing (in this case, an MP4)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/python | |
# this script creates randomly sized dummy files, based on a binary type of file. | |
# it was used to exercise Dropbox, and see the effect of adding a removing data. | |
# Mostly, it was to test a third party API that was using Dropbox, and see how | |
# well it handled this case. | |
import os | |
import time | |
import pathlib | |
from random import randint | |
WORKINGDIR = pathlib.Path("/Users/beauk/Dropbox (Spotify)/temp/") | |
OUTPUTDIR = WORKINGDIR.joinpath("dumbfiles/") | |
DELETE_DELAY = 8 | |
LOOPS = 100 | |
TEST_FILE_SOURCE = "./Downloads/ffmpeg/input/testfile.mp4" | |
OUT_FILE_NAME = 'dummy_test_file' | |
data = 0 | |
# read in some dumb data | |
with open(TEST_FILE_SOURCE, 'rb') as test_file: | |
data = test_file.read() | |
# loop | |
# create a file name | |
# write data to that file name | |
loop = LOOPS | |
while loop > 0: | |
loop -= 1 | |
for number in range(0, 50): | |
new_data = bytes(randint(400, 5000)) + data # add new data for randomness | |
print(f"{file_name}_{str(number)}") | |
with open(OUTPUTDIR.joinpath(f"{OUT_FILE_NAME}_{str(number)}.mp4"), 'wb') as file_to_write: | |
file_to_write.write(new_data) | |
dir_path, sub_dir, all_files = list(os.walk(OUTPUTDIR))[0] | |
time.sleep(DELETE_DELAY) | |
# print(list(all_files)) | |
for filename in all_files: | |
# time.sleep(4) | |
file_to_delete = str(pathlib.Path(dir_path).joinpath(filename)) | |
if os.path.exists(file_to_delete): | |
os.remove(file_to_delete) | |
else: | |
print("The file does not exist") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment