How do I cancel out double quote in Sikuli w/ Python? - python

I am using Sikuli to create an automation script and am currently struggling with the 'type' function as the input I am attempting to type has quote marks.
Example:
type('h', Key.CTRL)
wait(1)
type('<tbody class="MenuTableBody">')
The actual outcome when it types this is:
<tbody class=#MenuTableBody#>
Any help is appreciated.
Cheers,
Jack

Workaround maybe worth trying is first define the string.
stringSample = str('<tbody class="MenuTTableBody">')
type(stringSample)

Related

Selenium find element with variable value

i want to click an element with a value, which will be inserted by user. I tried this:
def transition(action, value=none):
if (action=='next_page'):
button = driver.find_element_by_link_text('"value"')
button.click()
transition('next_page', value='car1')
The problem is that 'car1' value isn't inserted. What can i fix it?
What your code does, is actually calling the find_element function with the string "value", as you wrote it in quotation marks, making it a string literal
button = driver.find_element_by_link_text('"value"')
What you want to do is insert the name of the variable value without any "double" or 'single' quotation marks, like so.
button = driver.find_element_by_link_text(value)
As you are having a hard time dealing with such simple python syntax, I recommend you first learn the bare basics of the language before trying to write applications with it. There are a lot of free resources out there.
I can recommend W3Schools as a website with text and interactive examples or if you are more of the video type of learner, I can recommend the course by freeCodeCamp.org or a video series by Tech With Tim. Though the last one didn't age really well.

pylatex: how to apply {\centering <x> } around graphics and or text?

I am trying to create the following (type of) code with PyLatex:
{
\centering
\includegraphics{image.png}
\includegraphics{image.png}
}
I am not able to 'group' the \centering command with the curly brackets around the \includegraphics; if I define a new Environment, I always end up with \begin and \end which add spacing.
So, do you know how I can nicely add the curly brackets with the \centering command around a snippet of code like \includegrahics?
To me, the most elegant solution would be something like:
with doc.centering():
doc.append('Some text.')
append(StandAloneGraphic(image))
append(StandAloneGraphic(image2))
How can I define such '''with doc.centering()''' command? Of course, I can hard code this every time, but I want my code to be readable so it would be nice if I could write a nice function for this problem.
I posted this question earlier om Stack Exchange (https://tex.stackexchange.com/questions/490429/pylatex-how-to-apply-centering-x-around-graphic/490442), but over there I got the advice to post here because it is more of a Python programming problem than a PyLatex challenge.
Update: I would like to put teh code below in a nice with.group(): statement:
import pylatex as pl
doc = pl.Document()
doc.preamble.append(pl.Package('showframe'))
doc.append(pl.NoEscape('{'))
doc.append(pl.Command('centering'))
doc.append(pl.StandAloneGraphic('example-image',image_options='width=5cm'))
doc.append(pl.Command('par'))
doc.append(pl.NoEscape('}'))
doc.generate_tex('pylatexdemo')
This piece of code creates the correct output, but is not really readable. I would imagine such solution (but I don't know how to program it); the definition of the group-function is incorrect. My question is: how to implement such group-function?
import pylatex as pl
doc = pl.Document()
doc.preamble.append(pl.Package('showframe'))
def group(content):
doc.append(pl.NoEscape('{'))
doc.append(content)
doc.append(pl.Command('par'))
doc.append(pl.NoEscape('}'))
with doc.group():
doc.append(pl.Command('centering'))
doc.append(pl.StandAloneGraphic('example-image',image_options='width=5cm'))
doc.generate_tex('pylatexdemo')

bibtex to html with pybtex, python 3

I want to take a file of one or more bibtex entries and output it as an html-formatted string. The specific style is not so important, but let's just say APA. Basically, I want the functionality of bibtex2html but with a Python API since I'm working in Django. A few people have asked similar questions here and here. I also found someone who provided a possible solution here.
The first issue I'm having is pretty basic, which is that I can't even get the above solutions to run. I keep getting errors similar to ModuleNotFoundError: No module named 'pybtex.database'; 'pybtex' is not a package. I definitely have pybtex installed and can make basic API calls in the shell no problem, but whenever I try to import pybtex.database.whatever or pybtex.plugin I keep getting ModuleNotFound errors. Is it maybe a python 2 vs python 3 thing? I'm using the latter.
The second issue is that I'm having trouble understanding the pybtex python API documentation. Specifically, from what I can tell it looks like the format_from_string and format_from_file calls are designed specifically for what I want to do, but I can't seem to get the syntax correct. Specifically, when I do
pybtex.format_from_file('foo.bib',style='html')
I get pybtex.plugin.PluginNotFound: plugin pybtex.style.formatting.html not found. I think I'm just not understanding how the call is supposed to work, and I can't find any examples of how to do it properly.
Here's a function I wrote for a similar use case--incorporating bibliographies into a website generated by Pelican.
from pybtex.plugin import find_plugin
from pybtex.database import parse_string
APA = find_plugin('pybtex.style.formatting', 'apa')()
HTML = find_plugin('pybtex.backends', 'html')()
def bib2html(bibliography, exclude_fields=None):
exclude_fields = exclude_fields or []
if exclude_fields:
bibliography = parse_string(bibliography.to_string('bibtex'), 'bibtex')
for entry in bibliography.entries.values():
for ef in exclude_fields:
if ef in entry.fields.__dict__['_dict']:
del entry.fields.__dict__['_dict'][ef]
formattedBib = APA.format_bibliography(bibliography)
return "<br>".join(entry.text.render(HTML) for entry in formattedBib)
Make sure you've installed the following:
pybtex==0.22.2
pybtex-apa-style==1.3

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 ..."

Python Regex To VB.net

I made a program in Python and now I whant to transfert it to vb.net. But I have some difficulties with the vb.net regular expression.... Someone can help me please?
There are my Python regex:
id = re.search('(?<=watch\?v\=)[\w|-]+|(?<=/v/)[\w|-]+', src)
id = id.group(0)
t = re.search('(?<=\&t\=)[\w|-]+', src)
t = t.group()
It's supposed to fin the value of ?v=Value&SomeOtherContent and &t=Value&SomeOtherContent
Thank you
An easy way to parse query strings is by using a NameValueCollection, using the HttpUtility.ParseQueryString method. This also takes care of encoding.
For example:
NameValueCollection parameters = HttpUtility.ParseQueryString("?var1=1&var2=2");

Categories

Resources