I currently have some JavaScript code that calls a .php file to send me an email from within a .jsp using an on-click function. It also includes a couple of variables, see below.
<script>
function sendMail(video, user) {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {// IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "http://www.mydomain.com/sendemail.php?video="+video+"&user="+user+'&ip=<%= request.getHeader("X-Real-IP") %>', false);
xmlhttp.send();
}
</script>
Calling the script within a .jsp file:
<a href="${videoUrl}" target="main" onclick="sendMail(parentElement.parentElement.getElementsByTagName('span')[2].attributes['title'].value, '${model.user.username}')">
Now I have a .py (different application than above) file that I would like to call this sendMail function. Section where I want to call the sendMail function in the .py file
def play(self, song_id):
Addon.log('play: ' + song_id)
if Addon.get_setting('transcode') == 'true':
bitrate = self.bitrates[int(Addon.get_setting('bitrate'))]
Addon.resolve_url(self.build_rest_url('stream.view',
{'id': song_id,
'maxBitRate': bitrate}))
else:
Addon.resolve_url(self.build_rest_url('download.view',
{'id': song_id}))
Now is there anyway to accomplish this sendMail function but from within a python file? Instead of using the function can I call a URL?
I Frankenstein a webapp I’m running to email me notifications, easiest way I found was to create the JavaScript function and then call some PHP to send an email. Now the python is a different app all together, just trying to figure out how to do the same thing, call the URL to send an email but with Python.
To call a url try the urllib2 module eg:
To send email try the email module starting with any of these examples.
To launch an external process on the same machine (eg the php script) try the SubProcess module