SHOW:
|
|
- or go back to the newest paste.
| 1 | #!/usr/bin/python | |
| 2 | #/home/clockworkpc/bin/casetagcreator.py | |
| 3 | ||
| 4 | # Released under a GPLv3 Licence by Clockwork PC 2012 | |
| 5 | # www.clockworkpc.com.au | |
| 6 | ||
| 7 | # You are entitled to the following four freedoms: | |
| 8 | # Freedom 0: To run this program for any purpose | |
| 9 | # Freedom 1: To study how this program works and change it to make it do what you wish | |
| 10 | # Freedom 2: To redistribute copies so you can help your neighbour | |
| 11 | # Freedom 3: To distribute copies of your modified version to others | |
| 12 | ||
| 13 | import os | |
| 14 | import glob | |
| 15 | - | os.system("touch " + masterCaseFile)
|
| 15 | + | import fnmatch |
| 16 | import fileinput | |
| 17 | import re | |
| 18 | import sys | |
| 19 | import datetime | |
| 20 | ||
| 21 | masterCaseFile = (os.getenv("HOME")+"/Dropbox/Deakin/Tiddlywiki/TiddlyTags/MasterFiles/master_tiddlycases.txt")
| |
| 22 | os.system("touch " + "'" + masterCaseFile + "'")
| |
| 23 | ||
| 24 | now = datetime.datetime.now() | |
| 25 | nowstring = str(now.strftime("%Y%m%d%H%M"))
| |
| 26 | ||
| 27 | def caseTagGenerator(): | |
| 28 | ||
| 29 | caseTagFile = (os.getenv("HOME")+"/Dropbox/Deakin/Tiddlywiki/TiddlyTags/CaseTags/caseTags_for_" + tiddlyCase + ".txt")
| |
| 30 | os.system("touch " + "'" + caseTagFile + "'")
| |
| 31 | ||
| 32 | running = True | |
| 33 | ||
| 34 | while running: | |
| 35 | caseTagQ = raw_input("Enter a case tag: ")
| |
| 36 | if caseTagQ != "": | |
| 37 | caseTag = "[[" + caseTagQ + "]]" | |
| 38 | f = open(caseTagFile, "a") | |
| 39 | - | if caseParagraph == "": |
| 39 | + | f.write(caseTag + " ") |
| 40 | f.close() | |
| 41 | - | tiddlyCase = "[[" + caseParty1 + " v " + caseParty2 + " (" + caseYear + ") " + caseCitation + "]]"
|
| 41 | + | else: |
| 42 | running=False | |
| 43 | - | tiddlyCase = "[[" + caseParty1 + " v " + caseParty2 + " [" + caseYear + "] " + caseCitation + "]]" |
| 43 | + | with open(caseTagFile) as myfile: |
| 44 | - | |
| 44 | + | caseTags = (list(myfile)[-1]) |
| 45 | - | elif caseJudge == "": |
| 45 | + | print caseTags |
| 46 | global caseTags | |
| 47 | - | tiddlyCase = "[[" + caseParty1 + " v " + caseParty2 + " (" + caseYear + ") " + caseCitation + "]] at " + caseParagraph
|
| 47 | + | |
| 48 | def caseInfoSheet(): | |
| 49 | - | tiddlyCase = "[[" + caseParty1 + " v " + caseParty2 + " [" + caseYear + "] " + caseCitation + "]] at " + caseParagraph |
| 49 | + | |
| 50 | global tiddlyCase | |
| 51 | global caseJudge | |
| 52 | ||
| 53 | - | tiddlyCase = "[[" + caseParty1 + " v " + caseParty2 + " (" + caseYear + ") " + caseCitation + "]] at " + caseParagraph + " per " + caseJudge
|
| 53 | + | |
| 54 | now1 = datetime.datetime.now() | |
| 55 | - | tiddlyCase = "[[" + caseParty1 + " v " + caseParty2 + " [" + caseYear + "] " + caseCitation + "]] at " + caseParagraph + " per " + caseJudge |
| 55 | + | #print str(now1.strftime("%Y%m%d%H%M"))
|
| 56 | print "" | |
| 57 | - | print tiddlyCase |
| 57 | + | |
| 58 | print "" | |
| 59 | - | f = open(masterCaseFile, "a") |
| 59 | + | |
| 60 | - | f.write(tiddlyCase+'\n') |
| 60 | + | |
| 61 | - | f.close() |
| 61 | + | |
| 62 | print "" | |
| 63 | - | xCowsayLine = "xcowsay --time=1 " + "'" + tiddlyCase + "'" |
| 63 | + | |
| 64 | - | print xCowsayLine |
| 64 | + | |
| 65 | ||
| 66 | - | os.system(xCowsayLine) |
| 66 | + | |
| 67 | 2. Square brackets? | |
| 68 | ||
| 69 | - | newCaseQ = raw_input("""
|
| 69 | + | |
| 70 | print "" | |
| 71 | caseCitation = raw_input("Enter the case citation: ")
| |
| 72 | print "" | |
| 73 | caseParagraph = raw_input("Enter the case paragraph, number only: ")
| |
| 74 | print "" | |
| 75 | caseJudge = raw_input("Enter the name of the judge or justice, e.g. Kirby J or Kirby and Hughes JJ: ")
| |
| 76 | print "" | |
| 77 | textBookPage = raw_input("What page number in the textbook does this citation appear on? ")
| |
| 78 | now2 = datetime.datetime.now() | |
| 79 | #print str(now2.strftime("%Y%m%d%H%M"))
| |
| 80 | - | newCaseQ = int(raw_input("""
|
| 80 | + | |
| 81 | ||
| 82 | if caseJudge == "": | |
| 83 | if caseYearQ == "1": | |
| 84 | tiddlyCase = caseParty1 + " v " + caseParty2 + " (" + caseYear + ") " + caseCitation
| |
| 85 | tiddlyCaseP = "*[[" + caseParty1 + " v " + caseParty2 + " (" + caseYear + ") " + caseCitation + "]]" + " (on page " + textBookPage + ")"
| |
| 86 | tiddlyCasePP = "*[[" + caseParty1 + " v " + caseParty2 + " (" + caseYear + ") " + caseCitation + "]] at " + caseParagraph + " (on page " + textBookPage + ")"
| |
| 87 | tiddlyCasePPJ = "*[[" + caseParty1 + " v " + caseParty2 + " (" + caseYear + ") " + caseCitation + "]] at " + caseParagraph + " (on page " + textBookPage + ")"
| |
| 88 | f = open(masterCaseFile, "a") | |
| 89 | - | os.system("xcowsay 'Alright then, goodbye'")
|
| 89 | + | f.write(tiddlyCasePPJ + '\n') |
| 90 | - | elif newCaseQ == 1: |
| 90 | + | f.close() |
| 91 | - | os.system('clear')
|
| 91 | + | |
| 92 | tiddlyCase = caseParty1 + " v " + caseParty2 + " [" + caseYear + "] " + caseCitation | |
| 93 | - | os.system('clear')
|
| 93 | + | tiddlyCaseP = "*[[" + caseParty1 + " v " + caseParty2 + " [" + caseYear + "] " + caseCitation + "]]" + " (on page " + textBookPage + ")" |
| 94 | - | print """ |
| 94 | + | tiddlyCasePP = "*[[" + caseParty1 + " v " + caseParty2 + " [" + caseYear + "] " + caseCitation + "]] at " + caseParagraph + " (on page " + textBookPage + ")" |
| 95 | - | I'm not sure what you want, but let's add another case! |
| 95 | + | tiddlyCasePPJ = "*[[" + caseParty1 + " v " + caseParty2 + " [" + caseYear + "] " + caseCitation + "]] at " + caseParagraph + " (on page " + textBookPage + ")" |
| 96 | - | """ |
| 96 | + | f = open(masterCaseFile, "a") |
| 97 | f.write(tiddlyCasePPJ + '\n') | |
| 98 | f.close() | |
| 99 | elif caseParagraph == "": | |
| 100 | if caseYearQ == "1": | |
| 101 | tiddlyCase = caseParty1 + " v " + caseParty2 + " (" + caseYear + ") " + caseCitation
| |
| 102 | tiddlyCaseP = "*[[" + caseParty1 + " v " + caseParty2 + " (" + caseYear + ") " + caseCitation + "]]" + " (on page " + textBookPage + ")"
| |
| 103 | tiddlyCasePPJ = "*[[" + caseParty1 + " v " + caseParty2 + " (" + caseYear + ") " + caseCitation + "]]" + " (on page " + textBookPage + ")"
| |
| 104 | f = open(masterCaseFile, "a") | |
| 105 | f.write(tiddlyCasePPJ + '\n') | |
| 106 | f.close() | |
| 107 | elif caseYearQ == "2": | |
| 108 | tiddlyCase = caseParty1 + " v " + caseParty2 + " [" + caseYear + "] " + caseCitation | |
| 109 | tiddlyCaseP = "*[[" + caseParty1 + " v " + caseParty2 + " [" + caseYear + "] " + caseCitation + "]]" + " (on page " + textBookPage + ")" | |
| 110 | tiddlyCasePPJ = "*[[" + caseParty1 + " v " + caseParty2 + " [" + caseYear + "] " + caseCitation + "]]" + " (on page " + textBookPage + ")" | |
| 111 | f = open(masterCaseFile, "a") | |
| 112 | f.write(tiddlyCasePPJ + '\n') | |
| 113 | f.close() | |
| 114 | else: | |
| 115 | if caseYearQ == "1": | |
| 116 | tiddlyCase = caseParty1 + " v " + caseParty2 + " (" + caseYear + ") " + caseCitation
| |
| 117 | tiddlyCaseP = "*[[" + caseParty1 + " v " + caseParty2 + " (" + caseYear + ") " + caseCitation + "]]" + " (on page " + textBookPage + ")"
| |
| 118 | tiddlyCasePP = "*[[" + caseParty1 + " v " + caseParty2 + " (" + caseYear + ") " + caseCitation + "]] at " + caseParagraph + " (on page " + textBookPage + ")"
| |
| 119 | tiddlyCasePPJ = "*[[" + caseParty1 + " v " + caseParty2 + " (" + caseYear + ") " + caseCitation + "]] at " + caseParagraph + " per [[" + caseJudge + "]] (on page " + textBookPage + ")"
| |
| 120 | f = open(masterCaseFile, "a") | |
| 121 | f.write(tiddlyCasePPJ + '\n') | |
| 122 | f.close() | |
| 123 | elif caseYearQ == "2": | |
| 124 | tiddlyCase = caseParty1 + " v " + caseParty2 + " [" + caseYear + "] " + caseCitation | |
| 125 | tiddlyCaseP = "*[[" + caseParty1 + " v " + caseParty2 + " [" + caseYear + "] " + caseCitation + "]]" + " (on page " + textBookPage + ")" | |
| 126 | tiddlyCasePP = "*[[" + caseParty1 + " v " + caseParty2 + " [" + caseYear + "] " + caseCitation + "]] at " + caseParagraph + " (on page " + textBookPage + ")" | |
| 127 | tiddlyCasePPJ = "*[[" + caseParty1 + " v " + caseParty2 + " [" + caseYear + "] " + caseCitation + "]] at " + caseParagraph + " per [[" + caseJudge + "]] (on page " + textBookPage + ")" | |
| 128 | f = open(masterCaseFile, "a") | |
| 129 | f.write(tiddlyCasePPJ + '\n') | |
| 130 | f.close() | |
| 131 | print tiddlyCasePPJ | |
| 132 | global tiddlyCasePPJ | |
| 133 | global tiddlyCase | |
| 134 | ||
| 135 | def caseJudgeFileGenerator(): | |
| 136 | caseJudgeFolder = (os.getenv("HOME")+"/Dropbox/Deakin/Tiddlywiki/TiddlyTags/TiddlyJudges/")
| |
| 137 | caseJudgeFile = (os.getenv("HOME")+"/Dropbox/Deakin/Tiddlywiki/TiddlyTags/TiddlyJudges/" + caseJudge + ".txt")
| |
| 138 | ||
| 139 | os.system("touch " + "'" + "'" + caseJudgeFile + "'")
| |
| 140 | g = open(caseJudgeFile, "a") | |
| 141 | g.write("<div title=" + '"' + caseJudge + '"' + ' modifier="TheCriticalG" created="' + str(now.strftime("%Y%m%d%H%M")) + '" modified=2"' + str(now.strftime("%Y%m%d%H%M")) + '" tags="' + caseTags + '"changecount="2">' + '\n' + "<pre>" + tiddlyCase + "</pre>" + '\n' + "</div>" + '\n')
| |
| 142 | ||
| 143 | def caseNotesGenerator(): | |
| 144 | global caseComment | |
| 145 | ||
| 146 | caseNoteFolder = (os.getenv("HOME")+"/Dropbox/Deakin/Tiddlywiki/TiddlyTags/CaseNotes/")
| |
| 147 | caseNoteFile = caseNoteFolder + tiddlyCase | |
| 148 | caseNoteQ = raw_input("Enter the relevant principle or note: ")
| |
| 149 | os.system("touch " + "'" + caseNoteFile + "'")
| |
| 150 | ||
| 151 | running=True | |
| 152 | ||
| 153 | while running: | |
| 154 | if caseNoteQ != "": | |
| 155 | caseNote = caseNoteQ + ":" + '\n' + tiddlyCasePPJ | |
| 156 | h = open(caseNoteFile, "a") | |
| 157 | h.write("<div title=" + '"' + tiddlyCase + '"' + ' modifier="TheCriticalG" created="' + str(now.strftime("%Y%m%d%H%M")) + '" modified=2"' + str(now.strftime("%Y%m%d%H%M")) + '" tags="' + caseTags + '"changecount="2">' + '\n' + "<pre>" + caseNote + "</pre>" + '\n' + "</div>" + '\n')
| |
| 158 | h.close() | |
| 159 | running=False | |
| 160 | else: | |
| 161 | running=False | |
| 162 | ||
| 163 | def advancedcaseJudgeFileGenerator(): | |
| 164 | global caseJudgeFile | |
| 165 | ||
| 166 | if caseJudge != "": | |
| 167 | for file in os.listdir(caseJudgeFolder): | |
| 168 | if not fnmatch.fnmatch(file, caseJudgeFile): | |
| 169 | os.system("touch " + "'" + caseJudgeFile + "'")
| |
| 170 | g = open(caseJudgeFile, "a") | |
| 171 | g.write("<div title=" + '"' + caseJudge + '"' + ' modifier="TheCriticalG" created="' + str(now.strftime("%Y%m%d%H%M")) + '" modified=2"' + str(now.strftime("%Y%m%d%H%M")) + '" tags="' + caseTags + '"changecount="2">' + '\n' + "<pre>" + tiddlyCaseP + "</pre>" + '\n' + "</div>" + '\n')
| |
| 172 | elif fnmatch.fnmatch(file, JudgeFile): | |
| 173 | for file in os.listdir(caseJudgeFolder): | |
| 174 | if fnmatch.fnmatch(file, caseJudgeFile): | |
| 175 | foundFile = caseJudgeFolder + fnmatch.fnmatch(file, caseJudgeFile) | |
| 176 | for line in fileinput.input([foundFile], inplace=1): | |
| 177 | line = line.replace("</div>", tiddlyCaseP + '\n' + "</div>")
| |
| 178 | print line, | |
| 179 | for line in fileinput.input([foundFile], inplace=1): | |
| 180 | line = line.replace('" changecount', ' ' + caseTags +'"' + " changecount")
| |
| 181 | print line, | |
| 182 | ||
| 183 | ||
| 184 | def newCaseTest(): | |
| 185 | newCaseQ = (raw_input("""
| |
| 186 | Do you want to add another case? | |
| 187 | ||
| 188 | 1. Yes | |
| 189 | 2. No | |
| 190 | ||
| 191 | Enter your selection: """)) | |
| 192 | if newCaseQ == 2: | |
| 193 | running = False | |
| 194 | os.system("clear")
| |
| 195 | running = True | |
| 196 | while running: | |
| 197 | caseInfoSheet() | |
| 198 | caseTagGenerator() | |
| 199 | caseJudgeFileGenerator() | |
| 200 | caseNotesGenerator() | |
| 201 | newCaseTest() |