I have a CSV file, which contains patch names, their release date and some other info in separate columns. I am trying to write a Python script that will ask the user for a Patch name and once it gets the input, will check if the Patch is in the CSV file and print out the Release Date.
So far, I have written the following piece of code, which I based based on this answer.
import csv
patch = raw_input("Please provide your Patchname: ")
with open("CSV_File1.csv") as my_file1:
reader = csv.DictReader(my_file1)
for row in reader:
for k in row:
if row[k] == patch:
print "According to the CSV_File1 database: "+row[k]
This way I get the Patch name printed on the screen. I don't know how to traverse the column with the Dates, so that I can print the date that corresponds to the row with the Patch name that I provided as input.
In addition, I would like to check if that patch is the last released one. If it isn't, then print the latest one along with its release date. My problem is that the CSV file contains patch names of different software versions, so I can't just print the last of the list. For example:
PatchXXXYY,...other columns...,Release Date,... <--- (this is the header row of the CSV file)
Patch10000,...,date
Patch10001,...,date
Patch10002,...,date
Patch10100,...,date
Patch10101,...,date
Patch10102,...,date
Patch10103,...,date
Patch20000,...,date
...
So, if my input is "Patch10000", then I should get its release date and the latest available Patch, which in this case would be Patch10002, and its release date. But NOT Patch20000, as that would be a different software version. A preferable output would like this:
According to the CSV_File1 database: Patch10100 was released on "date". The latest available patch is "Patch10103", which was released on "date".
That's because the "XXX" digits in the PatchXXXYY above, represent the software version, and the "YY" the patch number. I hope this is clear.
Thanks in advance!