PowerPoint: Edit filepath in image pasted as object link - python

Note: (not sure if I should put this here or on Super User)
I paste images into PowerPoints as a link, so that it updates when I update the source. Like this:
Usually, I update the image by modifying the original and then updating the link, like this:
However, if I open it from another computer, it can't update the link because it can't find the file. I'm assuming because it uses an absolute filepath and my file is in a Dropbox-like system, so the %USERPROFILE% part of the path (like JohnDoe in C:\Users\JohnDoe\Dropbox) is different for each computer.
So I thought I could search the OOXML version of the file to see that filepath and then modify it on my own. However, I tried searching it with Python and BeautifulSoup4, but couldn't find anything.
Any idea how I can modify or find this path to the linked object?
UPDATE: I found this
answer, it worked! really helped me, thanks.

Related

Is there a method for displaying a folder onscreen?

I am creating a program in Python that requires the user to place images into an Input folder, and then take images out of an Output folder. As this will become an application, the Input and Output folders will be very difficult to navigate to, being buried in the app's contents.
I am looking for a way to open folders onscreen so that a user can add or remove their own files from these folders, without knowing the exact location of the folders they are interacting with.
I am thoroughly stumped on this problem, and I appreciate all of your time.
Thank you very much.
*Edit: I am working on MacOS
If the program is intended for use on windows, it seems like you could use the solution here, where you could open explorer as a sub process and then open the path to the file.
For example
import subprocess
subprocess.Popen(r'explorer /select, FilePath')
You could also use os, and os.startfile(FilePath).

Sumo's not finding the file.net.xml when I try to open the file.sumocfg

I'm searching for a solution because I'm blocked and I don't understand why.
I'm a new user of Sumo, and to make my directory much clearer and less messy, I create a New Directory in the Directory where I put all files related to the sumocfg file I was working on (net.xml and rou.xml including sumocfg)
But now when I want to open the sumocfg file, it claims that the net.xml file is not found by searching it in the older directory it was.
Here is the error brought
Errorfile
And my problem is that he is searching the net.xml file in the path "Sumo/FirstIntersection.net.xml" instead of "Sumo/FirstIntersection/FirstIntersection.net.xml"
And I don't know why because when I open a simulation, I locate the good path.
Opening Simulation
I hope I was clear in describing the problem encountered.
Have some of you encountered the same issue?
Thanks in advance for your replies.
The sumocfg file is an XML file which you can modify with your favorite text editor. In your case it probably contains an absolute path to your network, that's why it does not work. You can simply change it to a relative path though. So instead of <net-file value="/full/path/to/FirstIntersection.net.xml"/> it should read <net-file value="FirstIntersection.net.xml"/>

Internet Shortcut in python

I have a problem. Let's say I have a website (e.g. www.google.com). Is there any way to create a file with a .url extension linking to this website in python? (I am currently looking for a flat, and I am trying to save shortcuts on my hard drive only to apartment offers posted online matching my expectations ) I've tried to use the os and requests module to create such files, but with no success. I would really appreciate the help. (I am using python 3.9.6 on Windows 10)
This is pretty straightforward. I had no idea what .URL files were before seeing this post, so I decided to drag its URL to my desktop. It created a file with the following contents which I viewed in Notepad:
[InternetShortcut]
URL=https://stackoverflow.com/questions/68304057/internet-shortcut-in-python
So, you just need to write out the same thing via Python, except replace the URL with the one you want:
test_url = r'https://www.google.com/'
with open('Google.url','w') as f:
f.write(f"""[InternetShortcut]
URL={test_url}
""")
With regards to your current attempts:
I've tried to use os and requests module to create such file
It's not clear what you're using requests or os for, since you didn't provide a Minimal Reproduceable Example of what you'd tried so far; so, if there's a more complex element to this that you didn't specify, such as automatically generating the file while you're in your browser, or something like that, then you need to update your question to include all of your requirements.

Google Chrome cannot read and write to its data directory : selenium

Here's the issue i am facing now.
I could launch chrome driver. However my selenium code suddenly doesnt work and pops up above image.
Hope someone can shed light as i couldn't find a solution online. .
Generally BarthRid's answer is correct, providing full path to userdata folder works with Chrome 90+. But if you store userdata folder in the same directory as your script, you can use pathlib to manage things more easily.
import pathlib
script_directory = pathlib.Path().absolute()
options.add_argument(f"user-data-dir={script_directory}\\userdata")
This way allows you to store actual script's directory in a variable, and via formatted string put it in selenium's options argument. Useful while dealing with multiple instances.
I had a similar problem to yours and #scott degen.
options.add_argument line of your pasted screenshot
I changed mine from:
options.add_argument("user-data-dir=selenium")
to the full directory, and it seems to be working better now.
options.add_argument("user-data-dir=C:\environments\selenium")
I changed mine from:
options.add_argument("user-data-dir=selenium")
to the full directory, and it seems to be working better now.
dir_path = os.getcwd()
chrome_option.add_argument(f'user-data-dir={dir_path}/selenium')
It seems Chrome changes its Current Working Directory during startup and so the relative path won't work. You can try to convert the user-data-dir to absolute path then pass to chrome. See Bug: 1058347

How do I get hgweb to actually display the repository I want?

I am having an infuriating experience with IIS7, Python 2.6, Mercurial 1.7.2, and hgweb.cgi.
After battling for an afternoon getting hgweb.cgi to work, I finally got it to render in the browser using hgweb.cgi and IIS7. I can now see a blank rendering of the web server, that is, a header with no repositories listed.
Now, according to the multipe sites I've read after scouring through Google results, I know that I have to update my hgweb.config file to point to some repositories.
However, for the life of me, I can't get it to list my repository using either the [paths] or [collections] entries.
I have the following directory structure, (simplified but illustrative...):
c:\code
c:\code\htmlwriter
c:\code\CommandLineProjects\Clean
The latter two directories have mercurial repositories in them.
I am trying to publish the repository in c:\code\htmlwriter
Now, if I make this entry in hgweb.config
[paths]
htmlwriter = c:\code\htmlwriter
I get nothing listed in my output.
If I put
[paths]
htmlwriter = c:\code\*
I get something, but not what I want, i.e. this:
htmlwriter/CommandLineProjects/Clean
(Note that the about drills down one directory level farther than I want it to).
I can't seem to find any combination of paths, asterisks, or anything else that will serve up the repository in c:\code\htmlwriter. It appears to always want to go one level deeper than I want it to, or to show nothing.
I know that my hgweb.config file is being read because I can change the style tag in it and it changes what is rendered.
I have read and re-read multiple time a number of resources on the web, but they all say what I'm trying should be working. For instance, I followed this instructions to the letter with no good results:
http://www.jeremyskinner.co.uk/mercurial-on-iis7/
Anyone have any suggestions?
I had about the same luck with hgweb.cgi, and ended up going a different route with wsgi and a "pure python" mercurial install.
I wrote a pretty comprehensive answer here.
I'll answer my own question:
The solution is that the path listed in the [paths] section is relative to the directory where the hgweb.config file is residing.
So, if you have your repository in:
c:\code\myrepo
and your hgweb.config file is in:
C:\inetpub\hgcgi
then the entry in your hgweb.config file needs to be:
/myrepo = ../../code/myrepo
That was the trick -- to put the correct relative path.
I was never able to get hgweb.cgi to work with a repo on a different drive.

Categories