I'm very new to Python (attempting to write my very first script!). My goal is to match up string contained in one file, lets call in tmp.txt, which contains a game name (i.e Marvel vs. Capcom 2 (USA)) within the file. The current contents of my tmp.txt file is:
/home/pi/RetroPie/roms/dreamcast/media/screenshot/Marvel vs. Capcom 2 (USA).png
/home/pi/RetroPie/roms/dreamcast/media/wheel/Marvel vs. Capcom 2 (USA).png
I want to then use this text (i.e the contents between the last backslash and the last period, then search for the first line that contains the same string within the game & /game bounds within a different file (i.e gamelist.xml). I then want to store the name, desc, release date, and other variables to be used within my program until I hit the next line that shows in the file. The file then can be closed.
<game>
<path>./Marvel vs. Capcom 2 (USA).gdi</path>
<name>Marvel vs. Capcom 2</name>
<desc>Marvel vs. Capcom 2: New Age of Heroes is a fighting game, developed and published by Capcom. It is the fourth game in the Marvel vs. Capcom series of fighting games. With the fourth installment of this series, Capcom simplified the player controls to make the gameplay more accessible to the wider audience of casual players. The button configuration was trimmed down to 4 main buttons and 2 assist buttons. The game also features a different air-combo system and 3 on 3 tag, compared to the 2 on 2 tag from previous games in the series.</desc>
<image>~/.emulationstation/downloaded_images/dreamcast/Marvel vs. Capcom 2 (USA)-image.jpg</image>
<releasedate>20000630T000000</releasedate>
<developer>Capcom</developer>
<publisher>Capcom</publisher>
<genre>Fighting</genre>
<players>2</players>
<playcount>7</playcount>
<lastplayed>20220318T234747</lastplayed>
</game>
Would anyone be able to help me write a function that achieves the above goals? If the match doesn’t exist, I’d also like to be able to catch/handle an error as well by storing text in a separate variable that contains something along the lines of “Error: No metadata available for the available game title.”
Would appreciate any feedback on the above or even how I phrased my question wrongly (i.e not enough information, poor wording, etc) so that I can ask better questions.
Hopefully I’ve been clear enough. Would appreciate any help! From a Python beginner.