Maybe we should have a thread of useful python modules and examples that we know work in touchdesigner and how to use them?
Heres a couple I’ve been using that people might find handy:
Requests
easy_install requests
An HTTP Library thats particularly useful for file uploading (Apparently the Web DAT does this but if it does I don’t have a clue how to use it.)
import sys
# set the following to the requests module path
sys.path.append("C:/Python33/Lib/site-packages/requests-2.3.0-py3.3.egg")
import requests
# set php/whatever script to upload to
url = 'http://yoursite.com/upload.php'
files = {'file': open('C:/thisismyfile.jpg', 'rb')}
with requests.Session() as session:
r = session.post(url, files=files, stream=True)
smtplib
Standard Library
Send email from within TouchDesigner, the following example sends an email from a gmail account.
import smtplib
gmail_user = "yourname@gmail.com"
gmail_pwd = "yourpassword"
FROM = 'yourname@gmail.com'
TO = ['afriend@something.com'] #must be a list
SUBJECT = "Hello from TouchDesigner"
TEXT = "Hows it going?"
# Prepare actual message
message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
try:
#server = smtplib.SMTP(SERVER)
server = smtplib.SMTP("smtp.gmail.com", 587) #or port 465 doesn't seem to work!
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_pwd)
server.sendmail(FROM, TO, message)
#server.quit()
server.close()
except:
print("failed")