Last active
September 3, 2018 07:07
-
-
Save EnriqueSoria/9c1e023b283eaeb465ce96ba98248f24 to your computer and use it in GitHub Desktop.
Alguns scripts que tinc
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
import numpy as np | |
import sympy as sym | |
import argparse | |
parser = argparse.ArgumentParser( | |
description="Fa el producte (·) entre dos matrius" | |
) | |
parser.add_argument("-a", help="Matriu `a`", required=True) | |
parser.add_argument("-b", help="Matriu `b`", required=True) | |
args = parser.parse_args() | |
a = [] | |
for token in args.a.split(";"): | |
a.append([]) | |
for nmbr in token.split(" "): | |
a[-1] += [sym.sympify(nmbr)] | |
b = [] | |
for token in args.b.split(";"): | |
b.append([]) | |
for nmbr in token.split(" "): | |
b[-1] += [sym.sympify(nmbr)] | |
print("a = {}".format(a)) | |
print("b = {}".format(b)) | |
print("a·b =\n",np.dot(a,b)) |
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
from os import listdir as ls | |
from sys import argv, exit | |
import argparse | |
def load_exif(filename): | |
import piexif | |
exif_dict = piexif.load(filename) | |
exif = {} | |
for ifd in ("0th", "Exif", "GPS", "1st"): | |
for tag in exif_dict[ifd]: | |
key = piexif.TAGS[ifd][tag]["name"] | |
value = exif_dict[ifd][tag] | |
if key in ("Model",) : | |
exif['model'] = value.decode() | |
if key in ("FNumber",): | |
a,b = value | |
exif['aperture'] = "f/{}".format(a/b) | |
if key in ("FocalLength",): | |
a,b = value | |
exif['focal'] = "{}mm".format(int(a/b)) | |
if key in ("ExposureTime",): | |
a,b = value | |
exif['shutter'] = "{}/{}s".format(a,b) | |
if key in ("ISOSpeedRatings",): | |
exif['iso'] = "{}-ISO".format(value) | |
if key in ("DateTimeOriginal",): | |
exif['datetime'] = value | |
return exif | |
def parse_arguments(): | |
parser = argparse.ArgumentParser(description="Mostra informació sobre fotografies") | |
parser.add_argument("foto", help="Nombre de la foto") | |
parser.add_argument("-n", "--name", help="Mostra el nom de la imatge", action="store_true") | |
parser.add_argument("--all", help="-mfsai", action="store_true") | |
parser.add_argument("-m", "--model", help="Model de càmara", action="store_true") | |
parser.add_argument("-f", "--focal", help="Distància focal", action="store_true") | |
parser.add_argument("-s", "--shutter", help="Temps d'obturació", action="store_true") | |
parser.add_argument("-a", "--aperture", help="Apertura de diafragma", action="store_true") | |
parser.add_argument("-i", "--iso", help="ISO", action="store_true") | |
args = parser.parse_args() | |
if args.all: | |
args.model = True | |
args.focal = True | |
args.shutter = True | |
args.aperture = True | |
args.iso = True | |
return args | |
if __name__ == "__main__": | |
args = parse_arguments() | |
args.foto = ls('.') if args.foto == "." else [args.foto] | |
for photo in args.foto: | |
if photo.endswith((".jpg",".JPG")): | |
exif = load_exif(photo) | |
if args.name: | |
print(photo, end=" - ") | |
if args.model: | |
print(exif.get('model', "unknown"), end=" ") | |
if args.focal: | |
print(exif.get('focal', "unknown"), end=" ") | |
if args.shutter: | |
print(exif.get('shutter', "unknown"), end=" ") | |
if args.aperture: | |
print(exif.get('aperture', "unknown"), end=" ") | |
if args.iso: | |
print(exif.get('iso', "unknown"), end=" ") | |
print("") |
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
mkdir RAW && mv *.CR2 RAW/ |
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
import argparse | |
from subprocess import run | |
from time import sleep | |
from os import listdir as ls | |
parser = argparse.ArgumentParser( | |
description='Repeat commands' | |
) | |
parser.add_argument('command') | |
parser.add_argument('-d', '--delay', help='delay in seconds', type=float) | |
parser.add_argument('-l', '--ls', action='store_true', help='performs `for file in ls(".")`. Example: repeat.py "echo {file}" --ls') | |
parser.add_argument('-r', '--range', type=int, nargs=2) | |
args = parser.parse_args() | |
if args.range: | |
for number in range(args.range[0], args.range[1]): | |
command = args.command.format( | |
number=number | |
) | |
run(command) | |
if args.delay: | |
sleep(args.delay) | |
elif args.ls and '{file}' in args.command: | |
autonumber = autonumber or 1 | |
for file in ls('.'): | |
command = args.command.format( | |
file=file, | |
number=autonumber | |
) | |
run(command) | |
if args.delay: | |
sleep(args.delay) | |
autonumber += 1 | |
else: | |
while True: | |
run(args.command) | |
if args.delay: | |
sleep(args.delay) |
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
from tkinter import Tk, Label, Button | |
from shutil import move as mv | |
from os import remove as rm | |
from os import listdir as ls | |
from os import system as run | |
from os import path | |
from sys import exit | |
join=path.join | |
class Main: | |
COMMAND = '''ffmpeg -i "{file}.aac" -acodec libmp3lame -ac 2 -b:a 192k "{file}.mp3"''' | |
def __init__(self, master): | |
self.master = master | |
master.title('Convertir a mp3') | |
self.center(master) | |
# label | |
self.label = Label( | |
master, | |
text='\n'.join(f for f in ls('.') if f.endswith('.aac')) | |
) | |
self.label.pack() | |
self.button = Button( | |
master, | |
text = "Convertir", | |
command = self.convert | |
) | |
self.button.pack() | |
def convert(self): | |
filenames = [ file.replace('.aac', '') for file in ls('.') ] | |
for file in filenames: | |
run( self.COMMAND.format(file=file) ) | |
self.clear() | |
self.ask_to_remove_aac_files() | |
def clear(self): | |
self.label.destroy() | |
self.button.destroy() | |
def ask_to_remove_aac_files(self): | |
self.label = Label( | |
self.master, | |
text='Vols borrar els fitxers AAC?' | |
) | |
self.label.pack() | |
self.yes = Button( | |
self.master, | |
text = "Si", | |
command = self.remove_aac | |
) | |
self.yes.pack() | |
self.no = Button( | |
self.master, | |
text = "No", | |
command = exit | |
) | |
self.no.pack() | |
def remove_aac(self): | |
filenames = [ file for file in ls('.') if file.endswith('aac')] | |
for file in filenames: | |
rm( file ) | |
exit() | |
def center(self, toplevel): | |
toplevel.update_idletasks() | |
w = toplevel.winfo_screenwidth() | |
h = toplevel.winfo_screenheight() | |
size = tuple(int(_) for _ in toplevel.geometry().split('+')[0].split('x')) | |
x = w/2 - size[0]/2 | |
y = h/2 - size[1]/2 | |
toplevel.geometry("%dx%d+%d+%d" % (size + (x, y))) | |
root = Tk() | |
root.geometry("600x400") | |
my_gui = Main(root) | |
root.mainloop() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment