master
Ethan Dalool 2016-12-04 17:50:52 -08:00
parent 2e337c77c5
commit 97403c7d5f
11 changed files with 96 additions and 39 deletions

View File

@ -1,11 +1,24 @@
'''
Batch rename files by providing a string to be `eval`ed, using variable `x` as
the current filename.
Yes I know this is weird, but for certain tasks it's just too quick and easy to pass up.
For example:
Prefix all the files:
brename.py "'Test_' + x"
Keep the first word and extension:
brename.py "(x.split(' ')[0] + '.' + x.split('.')[-1]) if ' ' in x else x"
'''
import os
import random
import re
import sys
def brename(transformation):
old = os.listdir()
if 're.' in transformation:
import re
new = [eval(transformation) for x in old]
pairs = []
for (x, y) in zip(old, new):
@ -58,4 +71,4 @@ def title(text):
if __name__ == '__main__':
transformation = sys.argv[1]
brename(transformation)
brename(transformation)

View File

@ -1,7 +1,10 @@
'''
Batch rename files by replacing the first argument with the second.
'''
import brename
import sys
replace_from = sys.argv[1]
replace_to = sys.argv[2]
command = 'x.replace("{f}", "{t}")'.format(f=replace_from, t=replace_to)
brename.brename(command)
brename.brename(command)

View File

@ -1,7 +1,9 @@
'''
Dump the clipboard to stdout. I use this for redirecting to files.
'''
import pyperclip
import sys
if len(sys.argv) > 1:
from voussoirkit import clipext
stuff = clipext.resolve(sys.argv[1])

View File

@ -1,3 +1,7 @@
'''
Pull all of the files in nested directories into the current directory.
'''
import os
import sys
@ -33,4 +37,4 @@ def main():
os.rename(f.absolute_path, local)
if __name__ == '__main__':
main()
main()

View File

@ -1,3 +1,10 @@
'''
Search for a target string within the lines of files.
For example:
fileswith.py *.py "import random"
'''
import fnmatch
import glob
import re
@ -25,4 +32,4 @@ for filename in spinal.walk_generator():
if matches:
print(filename)
print('\n'.join(matches))
print()
print()

View File

@ -1,3 +1,12 @@
'''
Find time, filesize, or bitrate, given two of the three.
For example:
kbps.py --time 1:00:00 --size 2g
kbps.py --time 1:00:00 --kbps 4660
kbps.py --size 2g --kpbps 4660
'''
import argparse
import sys
@ -45,7 +54,8 @@ def kbps(time=None, size=None, kbps=None):
kibs = size / 1024
kilobits = kibs * 8
kbps = kilobits / seconds
return int(kbps)
kbps = '%d kbps' % int(round(kbps))
return kbps
def example_argparse(args):
print(kbps(time=args.time, size=args.size, kbps=args.kbps))

View File

@ -1,31 +0,0 @@
import sys
# pip install
# https://raw.githubusercontent.com/voussoir/else/master/_voussoirkit/voussoirkit.zip
from vousoirkit import bytestring
def hms_s(hms):
hms = hms.split(':')
seconds = 0
if len(hms) == 3:
seconds += int(hms[0])*3600
hms.pop(0)
if len(hms) == 2:
seconds += int(hms[0])*60
hms.pop(0)
if len(hms) == 1:
seconds += int(hms[0])
return seconds
def calc(seconds, goal_bytes):
goal_kibs = goal_bytes / 1024
goal_kilobits = goal_kibs * 8
goal_kbps = goal_kilobits / seconds
goal_kbps = round(goal_kbps, 2)
return goal_kbps
if __name__ == '__main__':
length = sys.argv[1] # HH:MM:SS
goal_bytes = bytestring.parsebytes(sys.argv[2])
seconds = hms_s(length)
print(calc(seconds, goal_bytes), 'kbps')

View File

@ -1,3 +1,8 @@
'''
Recompress all jpg images in the current directory.
Add /r to do nested directories as well.
'''
from voussoirkit import bytestring
import io
import os

19
Toolbox/sorted.py Normal file
View File

@ -0,0 +1,19 @@
'''
Sort the lines coming from stdin and print them.
'''
from voussoirkit import clipext
import sys
if len(sys.argv) > 1:
text = clipext.resolve(sys.argv[1])
else:
text = clipext.resolve('!input')
text = text.split('\n')
if '-l' in sys.argv:
text.sort(key=lambda x: x.lower())
else:
text.sort()
new_text = '\n'.join(text)
print(new_text)

View File

@ -1,3 +1,6 @@
'''
Create the file, or update the last modified timestamp.
'''
import glob
import os
import sys

22
Toolbox/unique.py Normal file
View File

@ -0,0 +1,22 @@
'''
Keep the unique lines coming from stdin and print them.
'''
from voussoirkit import clipext
import sys
if len(sys.argv) > 1:
text = clipext.resolve(sys.argv[1])
else:
text = clipext.resolve('!input')
text = text.split('\n')
new_text = []
seen = set()
for item in text:
if item not in seen:
new_text.append(item)
seen.add(item)
new_text = '\n'.join(new_text)
print(new_text)