Software Collection/gen: Difference between revisions
(Created page with "This is the code and process used to generate the Software Collection page's HTML. == Preparing CSV == The CSV file from the Google sheet and folder of photos from the form need to be downloaded. You will need to add the file names to the CSV as the drive links aren't usable outside of Google. Currently all file names must sequentially match form responses and the sheet data cannot be reordered for the following responses to work. Generate a list of the photo file...") |
No edit summary |
||
Line 55: | Line 55: | ||
print("</table>") | print("</table>") | ||
print("</div>") | print("</div>") | ||
</pre> | |||
== Alternative == | |||
Download the CSV data, cut it down to just the new data (whole file needed so google sheets will quote multiple entries in cell), then use the following script to generate SoftwareSummary template objects and link the manually uploaded files to them | |||
<pre> | |||
#!/usr/bin/python3 | |||
import sys | |||
import csv | |||
with open( str(sys.argv[1]), 'r' ) as theFile: | |||
reader = csv.DictReader(theFile) | |||
for line in reader: | |||
print("{{"+"SoftwareSummary|Photo=|Title={}|Year={}|Platforms={}|Media Format={}|UPC={}|Notes Other={}|Box Condition={}|Notes Condition={}".format(line['Title'],line['Year'],line['Platform'],line['Media Format'],line['UPC'],line['Notes: Other'],line['Box Condition'],line['Notes: Condition'])+"}}") | |||
</pre> | </pre> |
Latest revision as of 15:12, 11 August 2023
This is the code and process used to generate the Software Collection page's HTML.
Preparing CSV
The CSV file from the Google sheet and folder of photos from the form need to be downloaded. You will need to add the file names to the CSV as the drive links aren't usable outside of Google. Currently all file names must sequentially match form responses and the sheet data cannot be reordered for the following responses to work.
Generate a list of the photo files in the folder:
unzip *.zip cd photos echo "Photo" >> ../photos.txt ls >> ../photos.txt cd ..
Prep the data CSV and file list then make a merged CSV:
cat Collection\ -\ Big\ Box\ Software.csv | tr "\r" " " > collection.csv while read line; do echo ",\"$line\"" >> photos.csv; done < photos.txt paste -d " " collection.csv photos.csv > db.csv
HTML Generation
With the final CSV made pass it as a parameter to the following python script to generate the HTML for the page:
#!/usr/bin/python3 import sys import csv print("This is a list of software in my collection. I do not own the respective copyright's to the original artwork, photos are for refrence only. Feel free to use the photo, with consideration of the original copyright holders, if you need refrence material as well.") with open( str(sys.argv[1]), 'r' ) as theFile: reader = csv.DictReader(theFile) for line in reader: print("<div class=\"inline-thing\">") print("<h2>"+line['Title']+"</h2>") print("[[File:"+line['Photo']+"|150px|left]]") print("<table class=\"wikitable\">") print("<tr><td>Box Year:</td><td>"+line['Year']+"</td></tr>") print("<tr><td>Platform(s):</td><td>"+line['Platform']+"</td></tr>") print("<tr><td>Media Format:</td><td>"+line['Media Format']+"</td></tr>") print("<tr><td>UPC:</td><td>"+line['UPC']+"</td></tr>") print("<tr><td>Notes Other:</td><td>"+line['Notes: Other']+"</td></tr>") print("<tr><td>Box Condition:</td><td>"+line['Box Condition']+"</td></tr>") print("<tr><td>Notes Condition:</td><td>"+line['Notes: Condition']+"</td></tr>") print("</table>") print("</div>")
Alternative
Download the CSV data, cut it down to just the new data (whole file needed so google sheets will quote multiple entries in cell), then use the following script to generate SoftwareSummary template objects and link the manually uploaded files to them
#!/usr/bin/python3 import sys import csv with open( str(sys.argv[1]), 'r' ) as theFile: reader = csv.DictReader(theFile) for line in reader: print("{{"+"SoftwareSummary|Photo=|Title={}|Year={}|Platforms={}|Media Format={}|UPC={}|Notes Other={}|Box Condition={}|Notes Condition={}".format(line['Title'],line['Year'],line['Platform'],line['Media Format'],line['UPC'],line['Notes: Other'],line['Box Condition'],line['Notes: Condition'])+"}}")