Up arrow key wih Pexpect, Python - python

How can I send a up arrow key with Python module pexpect? I have tried this:
child.send("\033[A")
but it will not work..

Use two sends. First to send the code for the shift key, and another to send a lower case a.
It may work if you send them together as well.

You can try:
child.send('\x1b[A')

Related

How can I get a key from the value in Firebase?

My Firebase structure is as below.
I'm using python to use firebase,
and also I use Pyrebase.
I want to get a key, which looks like '288xxxxxx'
from the value(busStopName).
Can I get the answer in Pyrebase?
Thank you in advance...
The following should work, based on the documentation
searched_bus = db.child("asanbus").order_by_child("busStopName").equal_to("XYZ").get()
for bus in searched_bus.each():
print(bus.key())
Assumption: there is only one record corresponding to busStopname = "XYZ". If not the case, you may do:
searched_bus = db.child("asanbus").order_by_child("busStopName").equal_to("XYZ").limit_to_first(1).get()

grabbing HTTP GET parameter from url using Box API in python

I am dealing with the Box.com API using python and am having some trouble automating a step in the authentication process.
I am able to supply my API key and client secret key to Box. Once Box.com accepts my login credentials, they supply me with an HTTP GET parameter like
'http://www.myapp.com/finish_box?code=my_code&'
I want to be able to read and store my_code using python. Any ideas? I am new to python and dealing with APIs.
This is actually a more robust question than it seems, as it exposes some useful functions with web dev in general. You're basically asking how to separate my_code in the string 'http://www.myapp.com/finish_box?code=my_code&'.
Well let's take it in bits and pieces. First of all, you know that you only really need the stuff after the question mark, right? I mean, you don't need to know what website you got it from (though that would be good to save, let's keep that in case we need it later), you just need to know what arguments are being passed back. Let's start with String.split():
>>> return_string = 'http://www.myapp.com/finish_box?code=my_code&'
>>> step1 = return_string.split('?')
["http://www.myapp.com/finish_box","code=my_code&"]
This will return a list to step1 containing two elements, "http://www.myapp.com/finish_box" and "code=my_code&". Well hell, we're there! Let's split the second one again on the equals sign!
>>> step2 = step1[1].split("=")
["code","my_code&"]
Well lookie there, we're almost done! However, this doesn't really allow any more robust uses of it. What if instead we're given:
>>> return_string = r'http://www.myapp.com/finish_box?code=my_code&junk_data=ohyestheresverymuch&my_birthday=nottoday&stackoverflow=usefulplaceforinfo'
Suddenly our plan doesn't work. Let's instead break that second set on the & sign, since that's what's separating the key:value pairs.
step2 = step1[1].split("&")
["code=my_code",
"junk_data=ohyestheresverymuch",
"my_birthday=nottoday",
"stackoverflow=usefulplaceforinfo"]
Now we're getting somewhere. Let's save those as a dict, shall we?
>>> list_those_args = []
>>> for each_item in step2:
>>> list_those_args[each_item.split("=")[0]] = each_item.split("=")[1]
Now we've got a dictionary in list_those_args that contains key and value for every argument the GET passed back to you! Science!
So how do you access it now?
>>> list_those_args['code']
my_code
You need a webserver and a cgi-script to do this. I have setup a single python script solution to this to run this. You can see my code at:
https://github.com/jkitchin/box-course/blob/master/box_course/cgi-bin/box-course-authenticate
When you access the script, it redirects you to box for authentication. After authentication, if "code" is in the incoming request, the code is grabbed and redirected to the site where tokens are granted.
You have to setup a .htaccess file to store your secret key and id.

send key code to field

i want to simulate the pressing of the enter key using py-appscript
i already found this, but it seems to only output the newline
Translate Applescrip [key code 125 using command down] to appscript
right now i want to press the enter key after the value has been set.
Example, after entering the IP hit enter key.
or send a keycode to the field itself.
app('System Events').key_code(76). (Or key_code(36) or keystroke('\r') if you meant ↩ instead of ⌤.)
keystroke and key_code don't ignore keys actually held down by the user, so you might need to add a delay if you're using a shortcut with modifier keys used to run the script.

Python textbox program

I want to write a Python program that will be able to read from a dictionary into any (or most) textboxes. Will this be possible and how would I approach it?
Here is an example of what I mean with the first line being an example of a command I'd like to be able type to receive the 2nd line which would be the message stored in the dictionary value:
/alias hello
HELLO! THIS IS AN AUTOMATED REPLY! :D
Store the dictionary as key,value pair in the form {key:value}. In the key part write your commands like 'hello' and in the value part give your corresponding message like ' HELLO! THIS IS AN AUTOMATED REPLY! :D'. You can access your value from its key. For eg:
abc = {"hello" : "HELLO! THIS IS AN AUTOMATED REPLY! :D"}
print abc["hello"]
It will print "HELLO! THIS IS AN AUTOMATED REPLY! :D".
I think this is what you meant. Actually I haven't understood what you meant by textboxes..

dictionary key-call

im building a test program. its essentially a database of bugs and bug fixes. it may end up being an entire database for all my time working in python.
i want to create an effect of layers by using a dictionary.
here is the code as of april 29 2011:
modules=['pass']
syntax={'PRINT':''' in eclipse anthing which
you "PRINT" needs to be within a set of paranthesis''','StrRet':'anytime you need to use the return action in a string, you must use the triple quotes.'}
findinp= input('''where would you like to go?
Dir:''')
if findinp=='syntax':
print(syntax)
dir2= input('choose a listing')
if dir2=='print'or'PRINT'or'Print':
print('PRINT' in syntax)
now when i use this i get the ENTIRE dictionary, not just the first layer. how would i do something like this? do i need to just list links in the console? or is there a better way to do so?
thanks,
Pre.Shu.
I'm not quite sure what you want, but to print the content of a single key of dictionary you index it:
syntax['PRINT']
Maybe this help a bit:
modules=['pass']
syntax={
'PRINT':''' in eclipse anthing which
you "PRINT" needs to be within a set of paranthesis''',
'STRRET':'anytime you need to use the return action in a string, you must use the triple quotes.'}
choice = input('''where would you like to go?
Dir:''').upper()
if choice in syntax:
print syntax[choice]
else:
print "no data ..."

Categories

Resources