Last active
December 20, 2015 21:18
-
-
Save jplattel/6196527 to your computer and use it in GitHub Desktop.
Pipe a CSV file column over to OSC and send it, a small commandline interface.
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
import time | |
import OSC | |
import argparse | |
# Argument parser | |
parser = argparse.ArgumentParser(description='(loop) a CSV file to a OSC adress with values according to the file.') | |
parser.add_argument('input') | |
parser.add_argument('-o','--out', help='Out OSC adress', required=True) | |
parser.add_argument('-t','--time', help='Pause length', required=True) | |
parser.add_argument('-p','--port', help="OSC to send", required=True) | |
parser.add_argument('-c','--col', help="Col in CSV file", required=True) | |
parser.add_argument('-l','--loop' , help="Loop (y/n)", action="store_true") | |
parser.add_argument('-s','--sep' , help="Seperator", required=True) | |
args = vars(parser.parse_args()) | |
# Setup OSC Client | |
client = OSC.OSCClient() | |
# Open CSV file | |
f = open(args['input'],'r').readlines() | |
for line in f: | |
line = line.replace('\n', '').replace('\r', '') | |
v = line.split(args['sep'])[int(args['col'])] | |
msg = OSC.OSCMessage() | |
msg.setAddress(args['out']) | |
msg.append(v) | |
print 'Sending: ' + args['out'] + ' ' + str(v) | |
client.sendto(msg, ('127.0.0.1', int(args['port']))) | |
time.sleep(float(args['time'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment