#! /usr/bin/env python # automatic writing of a 'diary' into static web pages, originally # written by Risto A. Paju (http://www.iki.fi/teknohog/) in April 2000 # Changes - December 2000: # split the enormous whatsupFile into reasonable chunks (i.e. months) # and tocFile into chunks of year # Major changes in November 2002 using regular expressions and pure # strings instead of lists and search-kluges # Future ideas: # * put templates into separate files # * organize the resulting files in directories, or more sensible date-names # * use templates for everything -- no hardcoded entry patterns # * generate TOC dynamically from the main whatsup file headings import time, string, re, tempfile, os, sys #editor = "zile -f auto-fill-mode" editor = os.environ["EDITOR"] whatsupLink = "index.php" basedir = os.path.dirname(sys.argv[0]) dateString = time.ctime(time.time()) #dateList = string.split(dateString) dateList = dateString.split() Weekday = dateList[0] Month = dateList[1] Day = dateList[2] Time = dateList[3] Year = dateList[4] TimeZone = time.tzname[1] timeTuple = time.localtime(time.time()) intMonth = timeTuple[1] intYear = timeTuple[0] Months = ['JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER'] title = "what's up" tocFile = "subtoc-" + Year + ".html" newFileHeader = "
(" + str(intYear-1) + ")\n" newTocFooter = "" def Nodify(temp): text = r"(.*?)" # includes grouping href = "http://everything2.org/?node=" # not used as a regex, only a sub pa\ttern temp = re.sub(r'\[' + text + r'\|' + text + r'\]', r'\2', temp) # pipelink temp = re.sub(r'\[' + text + r'\]', r'\1', temp) # ordinary hardlink return temp def ReadFile(file): File = open(file, "r") contents = File.read() File.close() return contents def WriteFile(filename, content): File = open(filename, "w") File.write(content) File.close() # I'm not sure if I ever want this.. Varkaudessa 9.1.2003 #if len(sys.argv) == 2: # location = sys.argv[1] entryHeading = Weekday + ', ' + Month + ' ' + Day shortDate = Day + '-' + Month + '-' + Year whatsupFile = Month + "-" + Year + ".php" today = 0 # by default #do we need a new whatsupFile? if not os.path.exists(os.path.join(basedir, whatsupFile)): newMonth = 1 else: newMonth = 0 whatsup = ReadFile(os.path.join(basedir, whatsupFile)) #check if there already is an entry today if re.search(shortDate, whatsup): today = 1 else: today = 0 #make entry if today == 0: entry = '
\n<" + Time[:5] + " " + TimeZone + ">
\n"
entry += timeThing
# A relevant suffix is good for editors with modes
tmp = tempfile.mktemp(".WHATS-UP.html")
WriteFile(tmp, "")
check = ReadFile(tmp)
os.system(editor + " " + tmp)
entryBody = ReadFile(tmp)
os.remove(tmp)
if entryBody == check:
print("Hiljast' on?")
sys.exit()
#reply = raw_input("[Nodify] it?")
#if re.match('y', reply, re.I):
# entryBody = Nodify(entryBody)
entry += entryBody + '\n'
if newMonth:
whatsup = newFileHeader + entry + newFileFooter
else:
# entry goes just before previous day's heading, or if there isn't one, just before footer.
pattern = '