I am trying to build an APA citation generator, asking the user for name of author, date, etc. And returning the correct reference structure. When it comes to citing a book, the title has to come in italics. I found a way for the output to come in italics using
f'\033[3m{title}\033[0m'
The problem is that I want the user to be able to copy and paste the reference in their document, however if you try to copy the output on the console, and paste it anywhere, the italic formatting is lost.
This is the part of the code:
reference = lastname + ", " + name[0] + ". " + "(" + year + "). " + f'\033[3m{title}\033[0m' + ". " + place + ": " + editorial + "."
Related
I am currently trying to send information to an input field in Chrome. I am working with variables when using the driver.find_element function.
What I have tried:
ProjectID = '"' + str('driver.find_element(By.XPATH, "//input[#ID=' + "'" + '_obj__TIMESHEETITEMS_' + str(rowCounter) + '_-_obj__PROJECTID' + "']" + '").send_keys(' + "'" + str(nonProjects['Projects'][rowCounter-2]) + "'" + ')') + '"'
After the variables are applied, it looks like this when applying print(ProjectID):
"driver.find_element(By.XPATH, "//input[#ID='_obj__TIMESHEETITEMS_2_-_obj__PROJECTID']").send_keys('OMSH001')"
I also tried without the quotation marks in the front:
ProjectID = str('driver.find_element(By.XPATH, "//input[#ID=' + "'" + '_obj__TIMESHEETITEMS_' + str(rowCounter) + '_-_obj__PROJECTID' + "']" + '").send_keys(' + "'" + str(nonProjects['Projects'][rowCounter-2]) + "'" + ')')
Which looks like this when applying print(ProjectID):
driver.find_element(By.XPATH, "//input[#ID='_obj__TIMESHEETITEMS_2_-_obj__PROJECTID']").send_keys('OMSH001')
I am calling the variable with:
driver.execute_script(ProjectID)
The error I am getting without the quotation marks is that the driver is not defined. When applying the quotation marks, that error goes away, but then the program does not do anything.
Any help is greatly appreciated, as I have been stuck on this error for days.
When looking at your examples, it seems as if you would try to use the selenium api in execute_script and this is obviously not possible.
ProjectID = '"' + str('driver.find_element(By.XPATH, "//input[#ID=' + "'" + '_obj__TIMESHEETITEMS_' + str(rowCounter) + '_-_obj__PROJECTID' + "']" + '").send_keys(' + "'" + str(nonProjects['Projects'][rowCounter-2]) + "'" + ')') + '"'
driver.execute_script(ProjectID)
The execute_script method executes the given JavaScript code directly in your browser and therefore whatever you want to do must be pure JavaScript.
It seems to me, as if in your example you do not need execute_script in the first place as you only directly call the selenium api.
I was not really able to fully unterstand your code, but would strongly suggest to simplify it it into something like this:
xpath = "//input[#ID='{}{}_-_obj__PROJECTID]".format(_obj__TIMESHEETITEMS_, rowCounter)
element = driver.find_element(By.XPATH, xpath)
element.send_keys(str(nonProjects["Projects"][rowCounter - 2]))
Im trying to parse a website and save its contents to CSV file but on line
brand = make_rating_sp[0].img["title"].title()
I get the typescript error
for container in containers:
make_rating_sp = container.div.select("a")
brand = make_rating_sp[0].img["title"].title()
product_name = container.div.select("a")[2].text
shipping = container.findAll("li", {"class": "price-ship"})[0].text.strip().replace("$",
"").replace(" Shipping", "")
print("brand: " + brand + "\n")
print("product_name: " + product_name + "\n")
print("shipping: " + shipping + "\n")
f.write(brand + ", " + product_name.replace(",", "|") + ", " + shipping + "\n")
You are most likely seeing IndexError: list index out of range, but you may also encounter problems if the make_rating_sp list contains elements, but the specific a tag at the specified index does not contain an img tag.
Try adding something like:
brand = ""
try:
brand = make_rating_sp[0].img["title"].title()
except:
pass
Often in Python you will want to catch specific exceptions, but in this instance a generic solution is probably sufficient.
newby/hobbycoder here.
I wrote a script which runs through a .M3U files and downloads all referenced media. (previews for my record store).
now i manage to get the correct path from the download function this exact way, but for some weird reason the following loop just returns ".mp3"
#write id3 tags
i = 1
for file in os.listdir("/Users/username/Desktop/transmisson"):
artist = str(nucontainer[i][2].replace("/", ""))
track = str(nucontainer[i][1].replace("/",""))
album = str(nucontainer[i][3].replace("/", ""))
filetype = ".mp3"
fullfilename = "/Users/username/Desktop/transmisson/"
+ artist + " - " + track + " - " + album + filetype
EDIT
artist, track, album, filetype all return the correct string
if i concatenate them, they return what i expect
as soon as i add ".mp3" it al goes pear shaped
EDIT
this gives the same problem.
write id3 tags
i = 0
while i < len(nucontainer):
artist = nucontainer[i][2].replace("/", "")
track = nucontainer[i][1].replace("/","")
album = nucontainer[i][3].replace("/", "")
filename = artist + " - " + track + " - " + album + ".mp3"
print filename
i += 1
Separate the paths in os.path.join with commas.
filename = artist + " - " + track + " - " + album + filetype
fullfilename = os.path.join('/Users/username/Desktop/transmisson/', filename)
Your problem might be that you don't 'return' or store anything. Right now, it just loops through the whole directory. Don't you want to store all the fullfilename data or something?
Edit: You don't seem to actualy do something wih file in the loop. Right now you are only referencing i, but i is not defined in your code.
Edit2: Based on your comment that nucontainer is a list of lists, I would assume that you should do something like this:
for i, file in enumerate(os.listdir("/Users/username/Desktop/transmisson")):
artist = str(nucontainer[i][2].replace("/", ""))
track = str(nucontainer[i][1].replace("/",""))
album = str(nucontainer[i][3].replace("/", ""))
filetype = ".mp3"
fullfilename = "/Users/username/Desktop/transmisson/"
+ artist + " - " + track + " - " + album + filetype
I seem to be having an issue with looping through the data that I pulled from a url in my Alexa skill, here is my sample code:
def get_elevator_status():
session_attributes = {}
card_title = "Septa Elevator Status"
reprompt_text = ""
should_end_session = False
response = urllib2.urlopen(API_BASE_URL + "/elevator")
septa_elevator_status = json.load(response)
for elevators in septa_elevator_status['results']:
speech_output = "The following elevators are out of service." "On " + elevators['line'] + " at station " + elevators['station'] + " the " + elevators['elevator'] + " elevator has " + elevators['message']
If I run the code in python shell and print out the results (if there are multiple outages) it prints out all lines. But when I test my Alexa skill and ask for outages it only reports back one result even though there are multiple elevator outages. Am I missing something for this to work? Should this code loop through and say all results found right?
can you post the 'response' json, my guess is that the json is not formed correctly
While looping through the result set everytime you are overwriting speech_output with that particular elevators. Instead, you have to concatenate every result to speech_output.
for elevators in septa_elevator_status['results']:
speech_output = speech_output + " <s> The following elevators are out of service." "On " + elevators['line'] + " at station " + elevators['station'] + " the " + elevators['elevator'] + " elevator has " + elevators['message'] + "</s>"
<s> is the sentence tag, use it only if you are using SSML.
I've tried appending a '/n' as shown in the code below however the output is still just one block of text that extends from one line to the next, rather than creating a new line after each list entry like I want
final_presentation_text = ["You are " + diet, "Your calorie limit
is " + str(calorie_count),
"Your diet has " + str(calorie_number),
" Your carbs target is " +
str(carbs_target),
" Your diet has " + str(carbs_number)]
for lines in final_presentation_text:
final_presentation.insert(1.0, lines + '/n')
It's backslash ("\") and then "n" for a new line, i.e. "\n", not forward slash.