¶ wbgrecent.py
2009-06-13 18:23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | """Summary=======Walks through all your blog entries and comments and makes a list ofall the entries that were either written in the last 14 days or havecomments written in the last 14 days. It then generates a veryhard-coded html representation of them and semi-abuses the flavour template yearmonthsummary which I use for my wbgarchivesplugin.This plugin requires no installation. Just drop it in and the urlwill be:: $baseurl/recentto see the recent activity.----Permission is hereby granted, free of charge, to any personobtaining a copy of this software and associated documentationfiles (the "Software"), to deal in the Software without restriction,including without limitation the rights to use, copy, modify,merge, publish, distribute, sublicense, and/or sell copies of theSoftware, and to permit persons to whom the Software is furnishedto do so, subject to the following conditions:The above copyright notice and this permission notice shall beincluded in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIESOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE ANDNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERSBE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN ANACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.Copyright 2004-2007 Will GuaraldiSUBVERSION VERSION: $Id: wbgrecent.py,v 2872b22e2ace 2011/10/27 07:08:25 zoomquiet+hg $Revisions:2007-07-07 - Converted documentation to reST.2005-11-11 - Pulled into new VCS.1.5 - (26 October, 2005) pulled into new VCS1.1 - (09 December, 2004) fixed the timestamp and date_head issues1.0 - (31 August, 2004) initial writing"""__author__ = "Will Guaraldi - willg at bluesock dot org"__version__ = "$Date: 2011/10/27 07:08:25 $"__description__ = "Summary of recent blog activity."from Pyblosxom import tools, entriesimport time, os, glob, urllibdef verify_installation(request): return 1def new_entry(request, title, body): """ Takes a bunch of variables and generates an entry out of it. It creates a timestamp so that conditionalhttp can handle it without getting all fussy. """ entry = entries.base.EntryBase(request) entry['title'] = title entry['filename'] = title + "/recent" entry['file_path'] = title entry._id = title + "::recent" entry["template_name"] = "yearsummarystory" entry["nocomments"] = "yes" entry.setTime(time.localtime()) entry.setData(body) return entryINIT_KEY = "wbgrecent_initiated"def cb_date_head(args): request = args["request"] data = request.getData() if data.has_key(INIT_KEY): args["template"] = "" return argsdef get_comment_text(cmt): f = open(cmt[1], "r") lines = f.readlines() title = "No title" author = "Unknown" for mem in lines: mem = mem.rstrip() if mem.find("<title> @ 2009-06-13 18:23 - ") == 0: title = mem.replace("<title>", "").replace("</title>", "") title = urllib.unquote(title) elif mem.find("<author>") == 0: author = mem.replace("<author>", "").replace("</author>", "") author = urllib.unquote(author) return "(%s) comment from %s" % \ (time.strftime("%m/%d/%Y %H:%M", time.localtime(cmt[0])), \ author)def cb_filelist(args): request = args["request"] pyhttp = request.getHttp() data = request.getData() config = request.getConfiguration() if not pyhttp["PATH_INFO"].startswith("/recent"): return datadir = config["datadir"] baseurl = config.get("base_url", "") cmntdir = config.get("comment_dir", datadir + os.sep + "comments") cmntext = config.get("comment_ext", ".cmt") data["blog_title"] = config.get("blog_title", "") + " - recent activity" data[INIT_KEY] = 1 config['num_entries'] = 9999 marker = time.time() - (60 * 60 * 24 * 14) # get all the entries allentries = tools.Walk(request, datadir) debug = [] stuff = [] for mem in allentries: timetuple = tools.filestat(request, mem) entrytstamp = time.mktime(timetuple) tstamp = entrytstamp absolute_path = mem[len(datadir):mem.rfind(os.sep)] fn = mem[mem.rfind(os.sep)+1:mem.rfind(".")] cmtexpr = os.path.join(cmntdir + absolute_path, fn + '-*.' + cmntext) cmtlist = glob.glob(cmtexpr) cmtlist = [ (os.stat(m)[8], m) for m in cmtlist] cmtlist.sort() cmtlist.reverse() # we want the most recent mtime from either the entry or # any of its comments if len(cmtlist) > 0: if tstamp < cmtlist[0][0]: tstamp = cmtlist[0][0] # if the mtime is more recent than our marker, we toss the # stuff into our list of things to look at. if tstamp > marker: stuff.append( [tstamp, entrytstamp, mem, cmtlist] ) stuff.sort() stuff.reverse() # time stamp and blog entry e = "</author> |




