Ejemplo n.º 1
0
def split_efile(filename):
    fs = Filesplit()
    filedata = read_file(filename, "rb")
    split_length = len(filedata) // 2
    if split_length % 2 != 0:
        split_length += 1
    fs.split(file=filename, split_size=split_length, output_dir="cache")
    return True
Ejemplo n.º 2
0
    def _split_file_into_chunks(self, src_file_path: str,
                                dst_dir_path: str) -> None:
        # define helper method that renames file chunks created with FileSplit
        def rename_chunk(chunk_path: str):
            directory, name, extension = self.split_file_path(chunk_path)
            chunk_id = re.match(r'^.*_(?P<id>\d+)$', name).group('id')
            new_chunk_path = os.path.join(directory,
                                          f'chunk_{chunk_id}{extension}')
            os.rename(chunk_path, new_chunk_path)
            return new_chunk_path

        # define callback function for FileSplit.split
        def note_created_file(file_path: str, file_path_list: list):
            self.log.debug(f'Creating file: {file_path}')
            file_path_list.append(file_path)

        # if source file size is bigger than defined chunk size split it into chunks
        if os.path.getsize(src_file_path) > self.chunk_byte_size:
            # initialize file paths list
            chunk_file_paths = list()

            # split file
            fs = Filesplit()
            fs.split(file=src_file_path,
                     split_size=self.chunk_byte_size,
                     output_dir=dst_dir_path,
                     callback=lambda path, _: note_created_file(
                         path, chunk_file_paths),
                     newline=True)

            # rename files on file paths list
            chunk_file_paths = [
                rename_chunk(path) for path in chunk_file_paths
            ]

            # delete manifest file
            manifest_file_path = os.path.join(dst_dir_path, 'fs_manifest.csv')
            if os.path.exists(manifest_file_path):
                os.remove(manifest_file_path)

        else:
            # copy and rename the source file
            _, _, extension = self.split_file_path(src_file_path)
            dst_file_path = os.path.join(dst_dir_path, f'chunk_1{extension}')
            shutil.copy(src_file_path, dst_file_path)
Ejemplo n.º 3
0
import sys
from fsplit.filesplit import Filesplit

fs = Filesplit()


#Callback function to print the split outputs in the terminal
def split_cb(f, s):
    print("file: {0}, size: {1}".format(f, s))


#file -> input file name
#split_size -> size of every splits in bytes
#output_dir -> target directory to store the splits.
fs.split(file=sys.argv[1],
         split_size=1000000,
         output_dir="/home/anamika/Assignment/Splits",
         callback=split_cb)
Ejemplo n.º 4
0
''' Python Assignment for splitting the file based on size - Submitted by - Shashi Prakash 
    input format -> python main.py input.csv 
    input.csv is majestic million csv file, which contains recods over a million for testing purpose'''

import sys
from fsplit.filesplit import Filesplit

fs = Filesplit()


#Callback function to print the split outputs in the terminal
def split_cb(f, s):
    print("file: {0}, size: {1}".format(f, s))


#file -> input file name
#split_size -> size of every splits in bytes
#output_dir -> target directory to store the splits.
fs.split(file=sys.argv[1],
         split_size=1000000,
         output_dir="/home/shashi/Assignmnet/Splits",
         callback=split_cb)
Ejemplo n.º 5
0
async def chnnlzip(client, message):
    engine = message.Engine
    pablo = await edit_or_reply(message, engine.get_string("FILE_TOOLS_1"))
    rndm = uuid.uuid4().hex
    un = get_text(message)
    dirz = f"./{rndm}/"
    media_count = 0
    text_count = 0
    os.makedirs(dirz)
    if un:
        chnnl = un
    else:
        chnnl = message.chat.id
    async for msg in client.iter_history(chnnl):
        if msg.sticker:
            rndmname = uuid.uuid4().hex
            if msg.sticker.mime_type == "application/x-tgsticker":
                file_name = os.path.join(dirz + rndmname + ".tgs")
            else:
                file_name = os.path.join(dirz + rndmname + ".wepb")
            try:
                await msg.download(file_name=file_name)
            except Exception as e:
                logging.info(e)
        elif msg.media:
            media_count += 1
            try:
                await msg.download(file_name=dirz)
            except Exception as e:
                logging.info(e)
        elif msg.text:
            text_count += 1
            f = open(os.path.join(dirz + f"{chnnl}.txt"), "a")
            f.write(f"[{msg.date}] - {msg.text} \n\n")
    total = text_count + media_count
    await pablo.edit(
        engine.get_string("FILE_TOOLS_2").format(total, media_count,
                                                 text_count))
    shutil.make_archive(str(f"{chnnl}_ZippedByFridayUB"), "zip", dirz)
    await pablo.edit("`Zipped! Uploading Now!`")
    zip_name = f"{chnnl}_ZippedByFridayUB.zip"
    siz_e = os.stat(zip_name).st_size
    list_ = []
    if siz_e > 2040108421:
        await pablo.edit(engine.get_string("FILE_TOOLS_3"))
        fs = Filesplit()
        if not os.path.exists(f"./splitted_{chnnl}_{rndm}"):
            os.makedirs(f"./splitted_{chnnl}_{rndm}")
        fs.split(
            file=zip_name,
            split_size=2040108421,
            output_dir=f"./splitted_{chnnl}_{rndm}",
        )
        file_list(f"./splitted_{chnnl}_{rndm}", list_)
        for oof in list_:
            if oof == "fs_manifest.csv":
                return
            await client.send_document(
                message.chat.id,
                oof,
                caption=
                f"**Total :** `{total}` \n**Total Media :** `{media_count}` \n**Total Text :** `{text_count}`",
            )
        shutil.rmtree(dirz)
        shutil.rmtree(f"./splitted_{chnnl}_{rndm}")
        if os.path.exists(zip_name):
            os.remove(zip_name)
        await pablo.delete()
        return
    await client.send_document(
        message.chat.id,
        zip_name,
        caption=
        f"**Total :** `{total}` \n**Total Media :** `{media_count}` \n**Total Text :** `{text_count}`",
    )
    os.remove(zip_name)
    shutil.rmtree(dirz)
    await pablo.delete()
Ejemplo n.º 6
0
async def chnnlzip(client, message):
    pablo = await edit_or_reply(message, "`Fetching All Files From This Channel!`")
    rndm = uuid.uuid4().hex
    un = get_text(message)
    dirz = f"./{rndm}/"
    media_count = 0
    text_count = 0
    os.makedirs(dirz)
    if un:
        chnnl = un
    else:
        chnnl = message.chat.id
    async for msg in client.search_messages(chnnl):
        if msg.sticker:
            rndmname = uuid.uuid4().hex
            if msg.sticker.mime_type == "application/x-tgsticker":
                file_name = os.path.join(dirz + rndmname + ".tgs")
            else:
                file_name = os.path.join(dirz + rndmname + ".wepb")
            try:
                await msg.download(file_name=file_name)
            except Exception as e:
                logging.info(e)
        elif msg.media:
            media_count += 1
            try:
                await msg.download(file_name=dirz)
            except Exception as e:
                logging.info(e)
        elif msg.text:
            text_count += 1
            f = open(os.path.join(dirz + f"{chnnl}.txt"), "a")
            f.write(f"[{msg.date}] - {msg.text} \n\n")
    total = text_count + media_count
    await pablo.edit(
        f"**Total Media :** `{total}` \n**Downloaded Media :** `{media_count}` \n**Total Texts Appended :** `{text_count}` \n**Now Zipping Files.**"
    )
    shutil.make_archive(str(f"{chnnl}_ZippedByFridayUB"), "zip", dirz)
    await pablo.edit("`Zipped! Uploading Now!`")
    zip_name = f"{chnnl}_ZippedByFridayUB.zip"
    siz_e = os.stat(zip_name).st_size
    list_ = []
    if siz_e > 2040108421:
        await pablo.edit(
            "`File Over 2GB, Telegram Doesn't Allow This. Trying To Split Files!`"
        )
        fs = Filesplit()
        if not os.path.exists(f"./splitted_{chnnl}_{rndm}"):
            os.makedirs(f"./splitted_{chnnl}_{rndm}")
        fs.split(
            file=zip_name,
            split_size=2040108421,
            output_dir=f"./splitted_{chnnl}_{rndm}",
        )
        file_list(f"./splitted_{chnnl}_{rndm}", list_)
        for oof in list_:
            if oof == "fs_manifest.csv":
                return
            await client.send_document(
                message.chat.id,
                oof,
                caption=f"**Total :** `{total}` \n**Total Media :** `{media_count}` \n**Total Text :** `{text_count}`",
            )
        shutil.rmtree(dirz)
        shutil.rmtree(f"./splitted_{chnnl}_{rndm}")
        if os.path.exists(zip_name):
            os.remove(zip_name)
        await pablo.delete()
        return
    await client.send_document(
        message.chat.id,
        zip_name,
        caption=f"**Total :** `{total}` \n**Total Media :** `{media_count}` \n**Total Text :** `{text_count}`",
    )
    os.remove(zip_name)
    shutil.rmtree(dirz)
    await pablo.delete()
Ejemplo n.º 7
0
from mega import Mega # importing 
import glob, os
from fsplit.filesplit import Filesplit


fs = Filesplit()

inp1=int(input("Enter the split size in KB: "))

fs.split(file="./output/data.file", split_size=inp1*1000, output_dir="./output/divided")
os.remove("./output/data.file")

print("Files are divided, Please check output/divided folder")

mega = Mega() # creating instance of mega
print("\nPlease wait, logging in .....")
m = mega.login("email", "password") #email id and passwor of www.mega.nz
print("login done !! ")

filename=[]
os.chdir("./output/divided")

for file in glob.glob("*.file"):
    filename.append(file)

print("No. of division created:",len(filename))

print("Uploading file in progress ....")
for i in range(len(filename)):
    file_upload=filename[i]
    file = m.upload(file_upload)
from fsplit.filesplit import Filesplit
fs = Filesplit()

fs.split(file='SampleMP3.mp3', split_size=50000, output_dir='.')
Ejemplo n.º 9
0
! pip install filesplit

from fsplit.filesplit import Filesplit

fs = Filesplit()
filedir=input("Enter the complete file path")
outdir=input("Enter the complete path of the directory where you want to store the output files")
choice=int(input("Do you want to split the file in \n 1.KB's \n 2.MB's \n 3.GB's \n"))
if(choice == 1):
    x=int(input("Enter the split size for KB split"))
    x=x*1024
elif(choice == 2):
    x=int(input("Enter the split size for MB split"))
    x=x*1024*1024
elif(choice == 3):
    x=int(input("Enter the split size for GB split"))
    x=x*1024*1024*1024
else:
    print("Wrong Input") 
f_size=x
print(f_size)
def split_cb(f, s):
    print("file: {0}, size: {1}".format(f, s))
    
fs.split(file=filedir, split_size=f_size, output_dir=outdir,  callback=split_cb)
Ejemplo n.º 10
0
    input_data(number_of_students)


main()

from fsplit.filesplit import Filesplit

fs = Filesplit()


def split_cb(f, s):
    print("file: {0}, size: {1}".format(f, s))


fs.split(file="students.xml",
         split_size=2000000,
         output_dir="Downloads/CSVfile",
         callback=split_cb)

from fsplit.filesplit import Filesplit

fs = Filesplit()


def split_cb(f, s):
    print("file: {0}, size: {1}".format(f, s))


fs.split(file="students.json",
         split_size=2000000,
         output_dir="Downloads/Jsonfile",
         callback=split_cb)
args['output_dir'] = args['output_dir'].replace("\\", "/")
args['file'] = args['file'].replace("\\", "/")

try:

    if (os.path.isdir(args['output_dir'])):
        if (bool(args['force'])):
            delete_files()
        if (len(os.listdir(args['output_dir'])) != 0):
            raise ValueError("Output directory should be empty! Exiting...")
    else:
        os.mkdir(args['output_dir'])

    if not os.path.isfile(args['file']):
        raise ValueError("Input file path is invalid")

    fs = Filesplit()
    fs.split(file=args['file'],
             split_size=int(args['split_size']),
             output_dir=args['output_dir'],
             callback=split_cb,
             new_line=bool(args['newline']),
             include_header=bool(args['header']))
    print("Splitting sucessfully completed!")

except ValueError as ve:
    print(ve)

except Exception as e:
    print("Oops!", e.__class__, "occurred.")