Python uploading images to a site through selenium - python

https://gyazo.com/4472adaefcd169a548253d6101041af8
Was recently making a bot to automatically post an "ad" to a site when launched , however i do need pictures and i researched ways to upload pictures all i could find was :Imagepath=os.path.abspath('.\folder1\subfolder2\file1.jpg') driver.find_element_by_id("ImageUploadButton").clear() driver.find_element_by_id("ImageUploadButton").send_keys(Imagepath) and me being new to python or coding in general I have no idea what ".\folder1\subfolder2\file1.jpg" accesses

Make sure you have your actual pathname put in there instead of writing '\folder1\subfolder2\file1.jpg' - that looks like it's just placeholder stuff that the person who wrote the sample code you got put in there to stand in for your actual path.
So if the image you want to upload is in \Volumes\username\bob\Desktop\ and it's called cats.jpg, you need to put '.\Volumes\username\bob\Desktop\cats.jpg' in where '.\folder1\subfolder2\file.jpg' is right now.

Related

Pulling stills from markers with scripting in Davinci Resolve

I've been using Resolve as a way to find images to pull from videos I've shot for use on my website and elsewhere. My problem is Resolve doesn't have a good way of categorizing/looking at stills, I'd like to be able to pull the stills and then look at them in something like Adobe Bridge where I can rate them and organize them.
Right now I just have a timeline with about 400 markers on it, meaning I have to go pull 400 stills. Is there an easy way to use the scripting in Resolve to have the computer pull those stills and dump them to a folder on my desktop?
I tried to run the script from here: https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=119036 but I couldn't get it to run, always getting a syntax error in IDLE or directly in Resolves console. I'd prefer to have the images in a folder by themselves as well, I don't need most of the other information that script would give me.
Thanks for helping me out!

How to deliver an image array from python to Rails

I am new to the world of Web Developing, i am currently using Ruby on Rails to code my webpages.
Here is the problem i am facing right now.
I am trying to make a webapp (using ruby on rails) in which the user must submit an Image(i am using CarrierWave for this) and the program its suppose to do some image processing, recognized objects and count them, so for this task i made a python script which do this automatically(using OpenCV). My problem is that the python script must return a new image which has the objects of interest in rectangles, and then i must store it in the dabase.
Currently i am returning in console where my objects are in the image, and displaying the new image, but i am not able to return the image as an array so that ruby framework can process it and upload it.
A simple view at how i am doing this
In the example1 i am recognizing oranges in the trees.
If anyone can help me or have an idea at how to do it, maybe a different approach could work. I am new in this, i have researched everywhere with no goods results. I didn't want to pose any code because i dont know which part is useful or not. (sorry for my bad english, i am not use to it completely)
To save an image locally into python you need to make an Image object and then save it to a given path.
my_image= Image("simplecv")
my_image.save("my-image.png") # in the current working directory
or to a path :
my_image.save("path/to/img.png")
You can then re-load those files with another language and store them in a database.
More examples on :
http://tutorial.simplecv.org/en/latest/examples/basics.html

Extremely new user to Python. "No module named request" error while trying code to detect image subdomains in a website to extract them to a folder

I may sound rather uninformed writing this, and unfortunately, my current issue may require a very articulate answer to fix. Therefore, I will try to be specific as possible as to ensure that my problem can be concisely understood.
My apologizes for that- as this Python code was merely obtained from a friend of mine who wrote it for me in order to complete a certain task. I myself had had extremely minimal programming knowledge.
Essentially, I am running Python 3.6 on a Mac. I am trying to work out a code that allows Python to scan through a bulk of a particular website's potentially existent subdomains in order to find possibly-existent JPG images files contained within said subdomains, and download any and all of the resulting found files to a distinct folder on my Desktop.
The Setup-
The code itself, named "download.py" on my computer, is written as follows:
import urllib.request
start = int(input("Start range:100000"))
stop = int(input("End range:199999"))
for i in range(start, stop + 1):
filename = str(i).rjust(6, '0') + ".jpg"
url = "http://website.com/Image_" + filename
urllib.request.urlretrieve(url, filename)
print(url)
(Note that the words "website" and "Image" have been substituted for the actual text included in my code).
Before I proceed, perhaps some explanation would be necessary.
Basically, the website in question contains several subdomains that include .JPG images, however, the majority of the exact URLs that allow the user to access these sub-domains are unknown and are a hidden component of the internal website itself. The format is "website.com/Image_xxxxxx.jpg", wherein x indicates a particular digit, and there are 6 total numerical digits by which only when combined to make a valid code pertain to each of the existent images on the site.
So as you can see, I have calibrated the code so that Python will initially search through number values in the aforementioned URL format from 100000 to 199999, and upon discovering any .JPG images attributed to any of the thousands of link combinations, will directly download all existent uncovered images to a specific folder that resides within my Desktop. The aim would be to start from that specific portion of number values, and upon running the code and fetching any images (or not), continually renumbering the code to work my way through all of the possible 6-digit combos until the operation is ultimately a success.
(Possible Side-Issue- Although I am fairly confident that my friend's code is written in a manner so that Python will only download .JPG files to my computer from images that actually do exist on that particular URL, rather than swarming my folder with blank/bare files from every single one of URL attempts regardless of whether that URL happens to be successful or not, I am admittedly not completely certain. If the latter is the case, informing me of a more suitable edit to my code would be tremendously appreciated.)
The Execution-
Right off the bat, the code experienced a large error. I'll list through the series of steps that led to the creation of said error.
#1- Of course, I first copy-pasted the code into a text document, and saved it as "download.py". I saved it inside of a folder named "Images" where I sought the images to be directly downloaded to. I used BBEdit.
#2- I proceeded, in Terminal, to input the commands "cd Desktop/Images" (to account for the file being held within the "Images" folder on my Desktop), followed by the command "Python download.py" (to actually run the code).
As you can see, the error which I obtained following my attempt to run the code was the ImportError: No module named request. Despite me guessing that the answer to solving this is simple, I can legitimately say I have got such minimal knowledge regarding Python that I've absolutely no idea how to solve this.
Hint: Prior to making the download.py file, the folder, and typing the Terminal code the only interactions I made with Python were downloading the program (3.6) and placing it in my toolbar. I'm not even quite sure if I am required to create any additional scripts/text files, or make any additional downloads before a script like this would work and successfully download the resulting images into my "Images" folder as is my desired goal. If I sincerely missed something integral at any point during this long read, hopefully, someone in here can provide a thoroughly detailed explanation as to how to solve my issue.
Finishing statements for those who've managed to stick along this far:
Thank you. I know this is one hell of a read, and I'm getting more tired as I go along. What I hope to get out of this question is
1.) Obviously, what would constitute a direct solution to the "No module named request" Input Error in Terminal. In other words, what I did wrong there or am missing.
2.) Any other helpful information that you know would assist this code, for example, if there is any integral step or condition I've missed or failed to meet that would ultimately cause the entirety of my code to cease to work. If you do see a fault in this, I only ask of you to be specific, as I've not got much experience in the programming world. After all, I know there is a lot of developers out here that are far more informed and experienced than am I. Thanks.
urllib.request is in Python 3 only. When running 'python' on a Mac, you're running Python 2 by default. Try running executing with python3.
python --version
might need to
brew install python3
urllib.request is a Python 3 construct. Most systems run Python 2 as default and this is what you get when you run simply python.
To install Python 3, go to https://brew.sh/ and follow the instructions to install the Hombrew package manager. Then run
brew install python3
python3 download.py

How to loop over hundreds of images in Qulatrics - help needed to implement code

I would like to use Qualtrics to get ratings for over 700 images (i.e., participants will have to indicate how negative or positive they find them). The question will be exactly the same for each image, yet there seems to be no straightforward way to just create the question once and then loop over all the images I want participants to rate. Obviously, I don't really want to write the same question 700 times.
I found a relevant answer here on Stack Overflow that seems to suggest a good solution - here it is: Randomization in Qualtrics using Photos or Graphics and Loop and Merge . My question, however, is not a mere duplicate of this, as I have troubles running the web scraping code at the bottom (I am a very inexperienced coder with limited Python knowledge), thus have some follow-up questions.
I tried running the above mentioned code a number of different ways (I have BeautifulSoup and Selenium):
1) create a .py file (e.g., getURL.py) with all the code suggested, and then just run it from the PowerShell (the only way I know how to run python code) with
python getURL.py
This opens up a Chrome browser (data:,), but the file it creates in the end is empty. I'm guessing by the time I navigate to the library the code has already run and reached the end of the for loop.
2) I tried running it line by line in the Python interpreter in the PowerShell, like this: I would go through the first block, that would bring up the Browser, then I'd navigate to the photo library within the browser (am I supposed to do anything other than just brining up the site in the browser?). Once that's done I'd move on to the next block of code with the for loop - I'd paste it into the interpreter, either as a block or line by line - but python just doesn't seem to execute that.
Could anyone tell me how to run that code?
ALTERNATIVELY: does anyone know an easier way a) to get Qualtrics to loop over images, or b) to get a list of 700 URLs quickly?
Thank you very much for the help.
You didn't say where the images are stored. If they are stored in Qualtrics this is fairly easy:
Get a list of photo urls or image ids (If photos are stored in your Qualtrics library, go Account Setting/Qualtrics IDs. Then click on the library where the photos are stored. Copy the image ids and paste them in a spreadsheet.)
Edit your spreadsheet as needed.
Copy and paste your urls or image ids from the spreadsheet into the loop & merge setup. This can be done all at one time.
Create your question in the loop & merge block. Include an html <img> tag in the appropriate place. You'll pipe your url or image id into the appropriate place in the src attribute. For example, if you are using image ids with a name in field 1 and the image id in field 2, the html might look like:
<img src="https://survey.qualtrics.com/ControlPanel/Graphic.php?IM=${lm://Field/2}" alt="${lm://Field/1}" border="0">

Website Links to Downloadable Files Don't Seem to Update

I have a problem with links on my website. Please forgive me if this is asked somewhere else, but I have no idea how to search for this.
A little background on the current situation:
I've created a python program that randomly generates planets for a sci-fi game. Each created planet is placed in a text file to be viewed at a later time. The program asks the user how many planets he/she wants to create and makes that many text files. Then, after all the planets are created, the program zips all the files into a file 'worlds.zip'. A link is then provided to the user to download the zip file.
The problem:
The first time I run this everything works perfectly fine. When run a second time, however, and I click the link to download the zip file it gives me the exact same zip file as I got the first time. When I ftp in and download the zip file directly I get the correct zip file, despite the link still being bad.
Things I've tried:
When I refresh the page the link is still bad. When I delete all my browser history the link is still bad. I've tried a different browser and that didn't work. I've attempted to delete the file from the web server and that didn't solve the problem. Changing the html file providing the link worked once, but didn't work a second time.
Simplified Question:
How can I get a link on my web page to update to the correct file?
I've spent all day trying to fix this. I don't mind looking up information or reading articles and links, but I don't know how to search for this, so even if you guys just give me links to other sites I'll be happy (although directly answering my question will always be appreciated :)).
I don't know anything about Python, but in PHP, in some fopen modes, if a file is trying to be made with the same name as an existing file, it will cancel the operation.

Categories