-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added file processing script + readme
- Loading branch information
1 parent
bb846d3
commit 283f5ea
Showing
3 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
import os | ||
from typing import Any, Iterable | ||
|
||
from fileStreams import getFileJsonStream | ||
|
||
|
||
fileOrFolderPath = r"<path to file or folder>" | ||
recursive = False | ||
|
||
def processRow(row: dict[str, Any]): | ||
# Do something with the row | ||
pass | ||
|
||
def processFile(path: str): | ||
jsonStream = getFileJsonStream(path) | ||
if jsonStream is None: | ||
print(f"Skipping unknown file {path}") | ||
return | ||
for i, (lineLength, row) in enumerate(jsonStream): | ||
if i % 10000 == 0: | ||
print(f"\rRow {i}", end="") | ||
if i > 10_000: | ||
break | ||
processRow(row) | ||
print(f"\rRow {i+1}") | ||
|
||
def processFolder(path: str): | ||
fileIterator: Iterable[str] | ||
if recursive: | ||
def recursiveFileIterator(): | ||
for root, dirs, files in os.walk(path): | ||
for file in files: | ||
yield os.path.join(root, file) | ||
fileIterator = recursiveFileIterator() | ||
else: | ||
fileIterator = os.listdir(path) | ||
fileIterator = (os.path.join(path, file) for file in fileIterator) | ||
|
||
for i, file in enumerate(fileIterator): | ||
print(f"Processing file {i+1: 3} {file}") | ||
processFile(file) | ||
|
||
def main(): | ||
if os.path.isdir(fileOrFolderPath): | ||
processFolder(fileOrFolderPath) | ||
else: | ||
processFile(fileOrFolderPath) | ||
|
||
print("Done :>") | ||
|
||
if __name__ == "__main__": | ||
main() |
Submodule zst_blocks_format
updated
3 files
+1 −1 | README.md | |
+9 −9 | python_cli/README.md | |
+4 −4 | python_cli/ZstBlocksFile.py |