https://unbhistory.lib.unb.ca/index.php?title=Filename.py&feed=atom&action=historyFilename.py - Revision history2024-03-28T12:10:00ZRevision history for this page on the wikiMediaWiki 1.39.5https://unbhistory.lib.unb.ca/index.php?title=Filename.py&diff=511&oldid=prev0:0:0:0:0:0:0:1: Created page with " #!/usr/local/bin/python # Opens a file, grabs its filename - appends it to the top of the file and inserts ENDTITLE after it. # Appends ENDPAGE at the end of the page. impo..."2014-05-07T18:21:36Z<p>Created page with " #!/usr/local/bin/python # Opens a file, grabs its filename - appends it to the top of the file and inserts ENDTITLE after it. # Appends ENDPAGE at the end of the page. impo..."</p>
<p><b>New page</b></p><div><br />
#!/usr/local/bin/python<br />
<br />
# Opens a file, grabs its filename - appends it to the top of the file and inserts ENDTITLE after it.<br />
# Appends ENDPAGE at the end of the page.<br />
<br />
import inspect, os<br />
from sys import argv<br />
<br />
def line_prepender(filename,line):<br />
with open(filename,'r+') as f:<br />
content = f.read()<br />
f.seek(0,0)<br />
f.write(line.rstrip('\r\n') + '\n' + content)<br />
def line_appender(filename,line):<br />
with open(filename, "a") as f:<br />
f.write(line)<br />
<br />
script, filename = argv<br />
filetoOpen = open(filename)<br />
fileName = filetoOpen.name<br />
file = fileName.split("_")[0]<br />
lineattop = file + "\n" + "</div>0:0:0:0:0:0:0:1