How to open a New window in Python PAMIE - python

I am using PAMIE to auto log in to websites and I have a couple to do. I got the scripts down to do this but I can't get PAMIE to open a new IE window so when I run the script it just opens one logs in and then when the next one is open it closes the first and opens the second and so on. So how do I get PAMIE to open new windows. This is what I have..
website="https://website"
ie.navigate(website)
ie.setTextBox("username","Myusername")
ie.setTextBox("password","mypassword")
ie.clickButton("btnSubmit")
Then I want to do this again but need it in new window.
website="https://website"
ie.navigate(website)
ie.setTextBox("username","Myusername")
ie.setTextBox("password","mypassword")
ie.clickButton("btnSubmit")
I tried ie.new before navigate(website), if someone could please tell me what command to open a new window I would appreciate it. I have also trie ie.change.window, and can't get it to work. Thanks

The web page is being re-opened in a single IE instance, because you're only using one PAMIE instance. If you really want multiple IE windows open, you can use multiple PAMIE instances.
Here is one very simple and crude example. Note that your import line may be slightly different than mine.
from pamie30 import PAM30
ie1 = PAM30.PAMIE("http://www.google.com")
ie2 = PAM30.PAMIE("http://news.google.com")
So now you can use ie1.navigate(), or ie2.navigate(), etc. to fill out the forms on your websites.
For example, to use the first IE instance:
ie1.setTextBox("q","my text goes here")
ie1.clickButton("btnK")
And when you're done with an instance you can kill it (it will leave the web page open, if you haven't done anything else with it), this just kills the Python object:
ie1 = None

Related

Chrome - active tabs locations and starting tabs location

I was wondering where the Chrome settings file that contains the URLs of web pages to open when you start it next time is. I couldn't find a similar question here. And also note that I am not talking about multiple homepages here, if that is possible though, that is a solution I guess. Chrome has this functionality to open all the tabs that you had open, the next time you start it. Though, sometimes by mistake, you may open a new chrome instance and close the one that you had with multiple tabs (thus, next time it will open the web pages in the second instance; i.e. in the last one that you had open). So I wanted to write a python script that I could execute that allows me to do two things:
1) Save the current state of open tabs
2) Restore that state next time I open Chrome (for an extension, I may also want to append the saved web pages from 1) into currently open web-pages).
This is not difficult, I think. I just need to know, probably, two locations. One - where the active tabs are, Two - where the starting tabs are.
Thanks

Is there a way to check if a program is open and then if it is, switch to it, and if it isn't, open it?

I'm currently writing a program which needs to check if a program is open before deciding to switch to it or open a new one. For example, a chrome short cut should check if chrome is already open. If it isn't then it should open a new chrome window but if it is then it should just show the existing chrome window/tab. Is there a way to write a function to do this?
Thanks in advance.
To check if a program is open I would suggest a library named psutil.
The switch of the window is more complicated and depends on the OS, for example in Windows you have to create (or get) an handle for that window and then call the OS API to change it, this is simply made using win32gui, as you can see here.

Spotfire Export Automatically

I'm not at all sure that what I need is possible with the tools that I have, but I thought I'd ask.
I have the following Python script (technically IronPython, but I don't fully understand the difference), that I pulled from a blog and modified for my purposes:
import datetime
from System.IO import StreamWriter
from Spotfire.Dxp.Application.Visuals import TablePlot
tempFolder = "C:\\Spotfire Exports\\"
tempFilename = "Data.txt"
writer = StreamWriter(tempFolder + tempFilename)
vTable.As[TablePlot]().ExportText(writer)
print tempFolder + tempFilename
The script itself works perfectly fine, but the problem is that I need to be able to make this run automatically at a certain time of day, i.e., I need the *.txt file to be updated in the morning before I get to my desk. (The project pulls from a database that isn't accessible through MS Access.)
Although the script runs fine, I have to manually push the button to activate it. I can't seem to find any way to have the script run on file open (so that I can use Windows Task Scheduler) to make it run when the file is opened.
Does anybody know if there's a way to do this?
Bear in mind, I do not have Visual Studio available to me. I already tried Visual Studio Express, and it doesn't seem to be able to access the Spotfire SDK macros.
You can utilize JavaScript to click a button on load and have that button be your python script. Like so:
window.onload = function callButtonClickEvent(){
document.getElementById('YOUR_SPOTFIRE_CONTROL_ID').click();
}
By clicking "edit HTML" in the text box you're using you can see the ID spotfire has assigned your button. The above code will click that button once upon loading.
If you do not want your button to be shown to end users (if applicable) then you can put it inside a hidden div or span:
<span style='display:none'><SpotfireControl id="YOUR_SPOTFIRE_CONTROL_ID" /></span>
Then once this is setup it should run your script when opened as per your windows task scheduler as you desired.
Let me know if you have any questions regarding implementation.

Is it possible to get current application running with python script

I am very much concerned about my productivity all the time. I have recently come across this beautiful chrome extension Limitless
But this is only measuring what i'm doing within the chrome application. As I work most of the time with pdfs, videos etc, I want to develop similar application for linux(ubuntu) desktop enviroment.
Basically I want the script to run continuously as long as the workstation is on.
It should be able to know what I'm currently looking at (for eg a pdf file or a lecture video in vlc) and get the name of the respective file, start time, end times etc and finally post to db.
It is better if it could know if the system is idle or at sleep.
I don't have slightest clue at bash scripting. so my questions is could this task be accomplished with python.
What I've tried?
I started with a search in google "get current application python", "current window title python" etc etc and really surprised to see absurd results.
Please give me pointers on this.
I think you are asking for vocabulary. So I give you what I know.
You are using Ubuntu so your Window Manager may be Gnome.
The window manager knows which window has the focus.
So maybe you want to find out which window has the focus and you want to map it to the Process that opened the window.
What you need to focus on is is module for Python or a Python Binding for the window manager. This module is likely to also be able to control the windows.
The window manager is started with startx.
You could try to call a command line tool and catch the results
How do get the process list on command line:
https://stackoverflow.com/questions/53489/how-do-you-list-all-processes-on-the-command-line-in-windows
And how to call a tool with python:
Python subprocess.call and subprocess.Popen stdout
[edit] Repeating the call in Intervals and counting the intervals a process were running gives you a good estimation of running time of a process...
[edit2] As GreenAsJade said, you search a way to find out which windows has the focus.
See How do I detect the currently focused application?

pywebkitgtk: Headless + full DOM interaction possible?

I am currently using the Python Webkit DOM Bindings to interact with a website programmatically and that's working for me.
The only problem is that it insists on opening a GTK window to display the page. Has somebody figured out a way to prevent it from opening a window? I.e. to use it in a headless way?
I'm initializing the view like this:
wv = pywebkitgtk.WebView(1024, 768, url=url)
which implicitly opens the GTK window and then I have an onload event-handler to manipulate the DOM.
I first thought of subclassing WebView, but that's not possible because it is a compiled class.
Any other ideas?
I'm the developer responsible for pythonwebkit, and I have a great deal of expertise covering these areas across several platforms. Realistically, you really, really want a completely "headless" WebKit port. In pythonwebkit that actually shouldn't be too hard to do, as there are only three "entry point" functions (one for window, one for document, and one for XMLHTTPRequest).
Really, somebody should do a proper "completely headless" port of WebKit. There already is an example program which is pretty close in WebKit's source tree, maybe that will get you started.
I've been using PyQT. PyQTWebView runs on Webkit and works great. Check out Ghost.py to get started, or use PyQT's API directly. Runs fully headless, and supports a decently recent build of Webkit.
You could try using Xvfb. I like using the command line and setting my display manually, but if you don't like that you could use this: http://cgoldberg.github.io/xvfbwrapper/
Can you get a handle to the GTK window and then call window.hide()? Otherwise, you might just have to use the full Webkit library.
Create a window and add the webview there, and never show the window..
I have webviews running without showing them, and can call a show_all if I need to show them.
web_view = pywebkitgtk.WebView()
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
sw = gtk.ScrolledWindow(hadjustment=None, vadjustment=None)
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
sw.add(web_view)
window.add(sw)
#window.show_all()

Categories

Resources