I am new to python scripts .
I have few repetative testing tasks such logging to various IM's
ex (OCS,different public messengers) etc .
Is it possible to automate these tasks using python .
If so from where do I start with ?
Working on windows 2003 server .
I know the basics of python. want to enhance the skills .
Thanks,
Tazim
Not quite a duplicate question, but the answers to "How can we use ms office communicator client exposed APIs in python, is that possible ?" should prove valuable.
If you are new to Python, you'll want to check out the Python Tutorial.
You may also wish to consider something a bit more Windows-oriented like VBScript or PowerShell, however.
OCS
For OCS, you should be able to use COM scripting to do most but not all[1] things. The code should look a bit like this:
import win32com.client
def get_contact(signin_uri, communicator):
c = communicator.GetContact(signin_uri, communicator.MyServiceId)
return c
comm = win32com.client.Dispatch('Communicator.UIAutomation')
contact = get_contact("jaya#contoso.com", comm)
You should be able to translate the documentation from the API fairly easily, especially if you focus on the JScript examples.
MSN/Live, AIM, ICQ, and IRC
For MSN/Live Messenger, the excellent twisted library contains an rudimentary implementation of a multiprotocol IM client (and server). To get started, check out some code samples.
[1] From the documentation:
For reasons of security, not all
methods or properties can be called
using JavaScript or another scripting
language. Such restrictions are
documented in Office Communicator Automation API Reference.
Related
Software these days can be separated into two categories: runs on client infrastructure (like in the case of enterprise software, like Splunk or Tibco), OR runs on the infrastructure of a software provider (like in the case of Facebook, where you need to use their API to access the backend).
In the first category, the client pays for a license and receives the software to run on their own machines on their premises of choice. The client IS in possession of the actual code and software.
In the second category, the software resides somewhere external and can be accessed only by an API. The client is NOT in possession of the software and can only use it to the extent allowed by the API.
My question is: in the first category above, how is the actual code kept hidden from the client?
Let's say I've built a really awesome analysis engine in Python for analyzing output logs. A corporate client is interested in using it for their internal applications. However, they insist that my engine must run on their own machines for security reasons. If I succumb and give them my Python code, then I will risk my intellectual property.
In that case, do I need to rewrite all my code into a compiled language like C++ to obfuscate it during compile time? Or is there a way to keep it in Python but secure the source code it in another way?
Update:
Given the answers below, in that case, would the more efficient pathway to developing a client-hosted application (i.e.: first category above) be to write a proof of concept in a more convenient language like Python first, and then take those ideas and rewrite it into C++?
The short answer is that you pretty much can't. You can do workarounds, but in the end almost anyone can reverse engineer your code no matter how you obfuscate it.
Your best bet might be to use something like PyInstaller and see if you can only include .pyc files. That doesn't protect you all the way, but it at least makes it a pain to reverse. You might even be able to find an obfuscater to run it first, but I don't know much about that part.
Similar to #gabeappleton's suggestion above, compile the Python code into an EXE. I use cx_freeze quite regularly and have good success. It's pretty well documented and reasonable support on these forums.
We are using software called Enovia.
I would like to query Enovia from inside Excel / VBA.
After some search, Enovia seems to have a programming interface called Abaqus.
http://www.3ds.com/products-services/simulia/services/training-courses/course-descriptions/introduction-to-the-abaqus-scripting-interface/
I would like to access this interface in VBA directly but I didn't find anything to that effect.
I found two projects that might allow Excel/VBA to talk to python components or at least to python scripts.
They are as follows
Python For Excel
http://opentradingsystem.com/PythonForExcel/main.html
And the discontinued excelpython
github.com/ericremoreynolds/excelpython
which became integrated in xlwings
xlwings.org
I am not familiar with python nor these two projects. I'm not sure if they will allow me to do what I want.
I'm ok with learning some python to do this but my main program and user interface is in excel.
I figure I could make some simple python scripts then call them through the python interpreter from excel with shellexecute but that is not a very elegant solution I think.
Any advice welcomed
thanks !
Enovia uses the MQL language for scripting. There are some guides available, such as http://emdros.org/MQL-Programmers-Guide.pdf
I would recommend some training such as http://www.techniatranscat.com/services/education/mql-and-tcl-intro as this doesnt seem to be a very common language.
Not to be confused with the financial trading language MQL4/MQL5 from MetaQuotes Software Corp.
ENOVIA does not have a Python programming interface.
Abaqus is a FEA simulation software which can be scripted with its own Python programming interface.
ENOVIA though, is a PLM software solution. They are different software for completely different applications. As programming interfaces you may look at maybe this
In short, you may need to contact your Dassault Systemes local support team to point you in the right direction.
Using tcl and mql you can solve the problem
TCL |
MQL
Latest Enovia version 3DEXPERIENCE support Rest based webservices. you can create a rest API in enovia and can call rest service using vb script in excel.
3DEXPERIENCE Enovia Rest webservice Framework
Above mentioned Rest framework may not be available with 2014X version. You have to try SOAP based service or JAX-RS.
Option 1
Enovia is java based application and doesn't support VBA ADK to directly work with backend data. However webservice can be used communicate between applications of different platforms or managed by different programming ADK.
For this you need to create your own service (REST/SOAP). For this you will need server access and first you have to write some java code (Rest/SOAP service) and update the class/jar into 2014 server (tomcat).
Then you can make use of that service in to your vba function.
Again you have to decide the kind of data whether xml or json it is separate topic.
Option 2
As I told earlier Enovia is Java based application, It provides JAVA ADK to extend its functionality.
Sample code shows how you can get the context and work with Enovia ADK.
matrix.db.Context ctx = new matrix.db.Context("http://myserver-nocas:8080/enovia");
ctx.setUser("Test Everything");
ctx.setPassword("");
ctx.connect();
System.out.println("Is context set "+ctx.isConnected());
As you mentioned you are currently using 3DEXPERIENCE then 3DPassport might block above URL method connection, So you need to pass NO-CAS URL.
You can get the context by running above java code from your local eclipse. Using this ADK you can also call MQL queries and work seamlessly.
import com.matrixone.apps.domain.util.MqlUtil;
String strPartFamily = MqlUtil.mqlCommand(ctx,"temp query bus Part * * select attribute[Length]");
But again this is java based solution and not VBA.
Finally 3DEXPERIENCE provides MQL console in server, to play around with all the data using SQL like queries in more developer friendly manner. Enovia also provides web based MQL console but you need to have some license for that (Administrator should be having access).
Use TCL to go through Excel sheet, it is very easy. Use "/t" to separate data.
We have a sizable code base in Perl. For the forseeable future, our codebase will remain in Perl. However, we're looking into adding a GUI-based dashboard utility. We are considering writing the dashboard in Python (using tkinter or wx). The problem, however, is that we would like to leverage our existing Perl codebase in the Python GUI.
So... any suggestions on how achieve this? We are considering a few options:
Write executables (in Perl) that mimic function calls; invoke those Perl executables in python as system calls.
Write Perl executables on-the-fly inside the Python dashboard, and invoke the (temporary) Perl executable.
Find some kind of Perl-to-Python converter or binding.
Any other ideas? I'd love to hear if other people have confronted this problem. Unfortunately, it's not an option to convert the codebase itself to Python at this time.
I hate to be another one in the chorus, but...
Avoid the use of an alternate language
Use Wx so it's native look and feel makes the application look "real" to non-technical audiences.
Download the Padre source code and see how it does Wx Perl code, then steal rampantly from it's best tricks or maybe just gut it and use the application skeleton (using the Artistic half of the Perl dual license to make it legal).
Build your own Strawberry Perl subclass to package the application as an MSI installer and push it out across the corporate Active Directory domain.
Of course, I only say all this because you said "Dashboard" which I read as "Corporate", which then makes me assume a Microsoft AD network...
You can spawn a child process and use an IPC mechanism like sockets or STDIO, or even embed one interpreter in the other.
But why switch languages when Perl offers several Tk (Tk, Tkx, and Tcl::Tk) bindings and a very capable Wx binding?
I have written and distributed GUI projects with Perl's Tk and Wx libraries.
If you are need the ability to create stand-alone executables, check out PAR::Packer, ActiveState's PerlApp, and Cava Pacakger.
Try the CPAN distribution Python (pyperl) for interfacing with python code.
Well, if you really want to write the GUI in another language (which, seriously, is just a bad idea, since it will cost you more than it could ever benefit you), the thing you should do is the following:
Document your Perl app in terms of the services it provides. You should do it with XML Schema Definition - XSD - for the data types and Web Service Description Language - WSDL - for the actual service.
Implement the services in Perl, possibly using Catalyst::Controller::SOAP, or just XML::Compile::SOAP.
Consume the services from your whatever-language GUI interface.
Profit.
But honestly, I really suggest you taking a look at the Perl GTK2 binding, it is awesome, including features such as implementing a Gtk class entirely in Perl and using it as argument to a function written in C - for instance, you can write a model class for a gtk tree entirely in Perl.
I'd avoid inter-language calls if possible; fragility and massive increases in dependencies await you down this road. However, there is...
Inline::Python
If python must be used, the Inline::* series of modules have been generally well received. This lets you write python inside a perl script. You still have to write perl but it would let you use python libraries inside perl scripts. It will make things more difficult to debug, though.
I'd think the major criterion for any qualified answer would involve the details of the existing codebase. How is this Perl code called and how does it return it's results?
A collection of command line utilities returning results through reasonably good textual output ("good" as in "amenable to further machine parsing" or "pipeline friendly") ... should be reasonably easy to call from any programming language (and Python's excellent subprocess and multiprocessing modules in particular). A collection of web CGI or other modules layered between Apache and some DBMS system could still be accessed with things like urlopen2 or mechanize -- but it might be better to bypass the Perl code and write Python to query the underlying (presumably canonical) model (data store).
If the majority of the codebase is a set of libraries or modules ... and the functionality that your proposed dashboard requires isn't already exposed via some higher level mechanism (some command line interface, networking protocol, etc) ... then it's basically insane to consider interfacing to it through any language other than Perl. (Unless, by some strange and extremely unlikely twist of fate, your existing codebase and your intended implementation target are both already stable under Parrot).
Let's ask a different, broader, question: What interface to you intend to use between your dashboard and your existing code base?
This question is paramount regardless of your choice of implementation language. If you write the dashboard in Perl it still needs to call into your existing code base in some way. You probably need to fix-up your code base to implement support for whatever your going to use for your dashboard. At the point where your codebase supports the necessary API (has command line or IPC protocol calls into the desired functionality which return results over any reasonable IPC mechanism) ... then your choice of dashboard implementation language will be essentially arbitrary.
Interesting project: I would opt for loose-coupling and consider an XML-RPC or JSON based approach.
Find some kind of Perl-to-Python converter
Try out my pythonizer - it does a pretty good job at that!
OK, so I am experimenting with a simple python repl in a browser. I want to put some python code in a text input, and then hit the 'send' button, then get back the result of evaluating it.
I was using flask, with one route, which called the stdlib eval function, and then sends it back. I was also using zeroMQ with a simple server/client setup. I feel like I am missing something though...
How is the standard way to go about doing this kind of thing? Projects like repl.it and skulpt are doing it but they are compiling to javascript. Ipython notebook is using zeroMQ, well I don't know the exact way they are doing it, sending some python string with a pub/sub setup and then using exec I think....
I was thinking I would like to embed repl's into webpages that support many languages, but I am starting with python first. Maybe someone else is doing this already? Any help is appreciated!
IPython notebook webapp discuss with a tornado webserver that act as a bridge with ZMQ to talk to kernels, kernels might be python, julia, haskell, OCamel, nodejs, ruby, scala ... for thoses that I know of. As long as a kernel comply to the message spec (and nice blog post about messaging protocol from the guy who wrote IHaskell) it is transparent for the frontend that just send strings/ receive results.
If you want a more stand-alone version you can look at Min's single cell demo. But basically you should be able to embed IPython's kernel.js in a page, and just use IPython.kernel.execute(code, callbacks).
The exact way of how this work in the kernel differs from language to language. Python can natively do so as you can eval a buch of code in a specific namespace, for other languages I can't tell you exactly.
Instead of reinventing, I think re-using IPython's message spec and reusable component would make sens[1].
Also I've heard from reliable source that IPython want the ability to start notebook with languages in different languages, and that they also want some closer than a REPL (like QtConsole) in the browser[2].
[1] I'm biased, I'm an IPython dev.
[2] That something we often talk about, but we have some Python-ism we want to get rid of first.
I have some really nice Python code to do what I need to do. I don't particularly like any of the Python GUI choices though. wxPython is nice, but for what I need, the speed on resizing, refreshing and dynamically adding controls just isn't there. I would like to create the GUI in VB.NET. I imagine I could use IronPython to link the two, but that creates a dependency on a rather large third-party product. I was perusing the MSDN documentation on Windows IPC and got the idea to use sockets. I copied the Python echo server code from the Python documentation and in under 5 minutes was able to create a client in VB.NET without even reading the System.Net.Sockets documentation, so this certainly doesn't seem too hard.
The question I have is... is this a terrible idea? If so, what should I be doing instead?
If this is a good idea, how do I go about it?
It's not a terrible idea. In fact, if you write the Python code to have a RESTful interface, and then access that from VB.NET, it is a downright good idea. Later on you could reuse that Python server from any other application written in Python or VB.NET or something else. Because REST is standard and easy to test, people can even do GETs from a browser and maybe that will be useful in itself.
Here is a Yahoo page that gives you code examples to do REST GET, POST and so on, in VB.NET.
If you think REST has too much overhead and need something more lightweight, please don't try to invent your own protocol. Consider something like Google's Protocol Buffers which can also be used from VB.NET.
I think this is an excellent idea. I'll second Michael Dillon's recommendation for a REST API, and I'll further recommend that you use Django to implement your REST server.
I wrote a REST web service using Django, and Django made it really easy and fun. Django made it really simple to set up the URLs the way I wanted them, to run whatever code a URL called for, and to interact with the database as needed. My web service was rock solid reliable, and I was able to test it for debugging simply using a web browser.
If you already have your code working in Python and just want to slap on a glue interface, and if REST doesn't seem like what you want, you could look at the Twisted networking framework. Here is a nice article on how to do networking in Python with both the standard Python modules and with Twisted.