def get_username(user_id, request): """ Return username given user_id. user_id may also be the 'anon:' format. """ if not user_id or user_id.startswith('anon'): return None return user.User(request, id=user_id).propercased_name
def doRSS(request): """ set up the RSS file """ rss_init_text = ( '<?xml version="1.0" ?>\n' '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">\n' '<channel><title>%s Events Board</title><link>%s</link>' '<description>' 'Events occuring soon, taken from the %s Events Board.' '</description><language>en-us</language>\n' '</channel>\n' '</rss>\n' % (request.config.sitename, Page("Events Board", request).link_to(), request.config.sitename)) creator_text = 'The %s Robot' % request.config.sitename rss_dom = xml.dom.minidom.parseString(rss_init_text) channel = rss_dom.getElementsByTagName("channel")[0] # Check to see if the event has already passed import string, re current_time = request.user.getFormattedDateTime(time.time(), global_time=True) year_cut = string.split(current_time," ")[0] current_year = string.split(year_cut, "-")[0] month_cut = string.split(current_time," ")[0] current_month = string.split(month_cut,"-")[1] day_cut = string.split(current_time," ")[0] current_day = string.split(day_cut,"-")[2] hour_cut = string.split(current_time," ")[1] current_hour = string.split(hour_cut,":")[0] string_month = findMonth(current_month) rss_text = [] events = [] timenow = time.time() today_struct = time.gmtime(timenow+request.config.tz_offset) today = list(today_struct[0:3]) + [0,0,0,0,0,0] today = calendar.timegm(today) - request.config.tz_offset tomorrow_struct = time.gmtime(timenow+60*60*24+request.config.tz_offset) tomorrow = list(tomorrow_struct[0:3]) + [0,0,0,0,0,0] tomorrow = calendar.timegm(tomorrow) - request.config.tz_offset request.cursor.execute( """SELECT uid, event_time, posted_by, text, location, event_name from events where event_time >= %(today)s and event_time < %(tomorrow)s and wiki_id=%(wiki_id)s""", {'today':today, 'tomorrow':tomorrow, 'wiki_id':request.config.wiki_id}) result = request.cursor.fetchone() while result: events.append(result) result = request.cursor.fetchone() for event in events: event_time_unix = event[1] # stupid date stuff time_struct = time.gmtime(event_time_unix+request.config.tz_offset) year = time_struct[0] month = time_struct[1] day = time_struct[2] hour = time_struct[3] minute = time_struct[4] posted_by = event[2] event_location = event[4] event_name = event[5] id = event[0] text = event[3] if event_name: processed_name = wikiutil.simpleStrip(request,event_name) else: processed_name = '' processed_text = doParse(text,request) processed_location = doParse(event_location,request) if int(hour) > 12 : read_hour = int(hour) - 12 if not int(minute) == 0: ptime = str(read_hour) + ":" + str(minute) + " PM" else: ptime = str(read_hour) + ":00" + " PM" elif int(hour) == 0: if not int(minute) == 0: ptime = "12:" + str(minute) + " AM" else: ptime = "12:00 AM" elif int(hour) == 12: if not int(minute) == 0: ptime = "12:" + str(minute) + " PM" else: ptime = "12:00 PM" else: if not int(minute) == 0: ptime = str(hour) + ":" + str(minute) + " AM" else: ptime = str(hour) + ":00 AM" total_date = "%s, %s %s" % ( datetoday(int(day), int(month), int(year)), findMonth(month), day) item = rss_dom.createElement("item") rss_text = [] rss_text.append('<b>Date:</b> %s<br>\n' '<b>Time:</b> %s<br>\n' '<b>Location:</b> %s<br><br>\n' '%s (Posted by %s)\n' % (total_date, ptime, processed_location, processed_text, user.getUserLink(request, user.User(request, name=posted_by), absolute=True))) item_guid = rss_dom.createElement("guid") item_guid.setAttribute("isPermaLink","false") item_guid.appendChild(rss_dom.createTextNode(''.join(str(id)))) item.appendChild(item_guid) item_description = rss_dom.createElement("description") item_description.appendChild(rss_dom.createTextNode(''.join(rss_text))) item_title = rss_dom.createElement("title") item_title.appendChild(rss_dom.createTextNode(processed_name)) item.appendChild(item_title) item_link = rss_dom.createElement("link") item_link.appendChild(rss_dom.createTextNode( Page("Events Board", request).url(relative=False))) item.appendChild(item_link) item_date = rss_dom.createElement("dc:date") item_date.appendChild(rss_dom.createTextNode( "%s-%s-%s" % (current_year,current_month,current_day))) item.appendChild(item_date) creator = rss_dom.createElement("dc:creator") creator.appendChild(rss_dom.createTextNode(creator_text)) item.appendChild(creator) item.appendChild(item_description) channel.appendChild(item) the_xml = rss_dom.toxml() return the_xml
pages(request, f) files(request, f) events(request, f) security(request, f) map(request, f) end_wiki(request, f) f.write(xml_footer) f.close() if __name__ == '__main__': command_line = True sys.stdout.write("Enter the wiki shortname: ") wiki_name = raw_input().strip().lower() req = request.RequestDummy(wiki_name=wiki_name) print " 1) Admin grab -- everything no matter what" print " 2) Unprivileged user grab -- only what non-logged in" print " public can see." grab_level = raw_input().strip() if grab_level == '2': command_line = False request.user = user.User(req) export(req, wiki_name=wiki_name) req.db_disconnect()
just_files = False just_pages = False just_maps = False if len(sys.argv) > 1: if sys.argv[1] == '--just_files': just_files = True elif sys.argv[1] == '--just_pages': just_pages = True elif sys.argv[1] == '--just_maps': just_maps = True sys.stdout.write("Enter the wiki shortname: ") wiki_name = raw_input().strip().lower() req = request.RequestDummy(wiki_name=wiki_name) print " 1) Admin grab -- everything no matter what" print " 2) Unprivileged user grab -- only what non-logged in" print " public can see." grab_level = raw_input().strip() if grab_level == '2': command_line = False req.user = user.User(req) export(req, wiki_name=wiki_name, just_pages=just_pages, just_files=just_files, just_maps=just_maps) req.db_disconnect()