def ShortWikipediaTableM(nentries): c = GetDBcursor() c.execute("SELECT max(ltime) AS mtime, count(*), referrer, reftitle FROM unlog_incoming WHERE refdomain = 'en.wikipedia.org' GROUP BY reftitle ORDER BY mtime DESC LIMIT %d;" % nentries) lres = c.fetchall() res = [ ] for wpref in lres: dt = wpref[0].strftime("%Y-%m-%d;%H:%M") #res.append((LongDate(dt[:10]), dt[11:], wpref[1], wpref[2], ConvertName(wpref[3]))) res.append({"timeago":TimeAgo(wpref[0]), "count":wpref[1], "referrer":wpref[2], "title":ConvertName(wpref[3])}) return res
def BigWikipediaTable(): #wprefs = ReadLogReferrers("logpages_wikipedia.txt") #wprefs.extend(ReadLogReferrers("logpages_wikipedia_1.txt")) #wprefs.extend(ReadLogReferrers("logpages_wikipedia_2.txt")) c = GetDBcursor() c.execute("SELECT max(ltime) AS mtime, min(ltime), count(*), referrer, reftitle FROM unlog_incoming WHERE refdomain = 'en.wikipedia.org' GROUP BY reftitle ORDER BY reftitle;") lres = c.fetchall() res = [ ] # wikiname, docid, page, date, wikifullurl for wpref in lres: res.append((wpref[0], wpref[1], wpref[2], wpref[3], ConvertName(wpref[4]))) #wrefpage = Wikiredirect(mref.group(2)) #wikifullurl = "%s%s%s" % (mref.group(1), wrefpage, mref.group(3) or "") #res.append((ConvertName(wrefpage), wpref[2], wpref[3], wpref[0], wikifullurl)) #res.sort() return res
def WriteRochesterPage(): WriteGenHTMLhead('Uni Rochester Stuff') c = GetDBcursor() qsel = "SELECT ldate, nation, un_divisions.docid, un_divisions.href, motiontext, vote FROM un_divisions " qlj = "LEFT JOIN un_votes ON un_votes.docid=un_divisions.docid AND un_votes.href=un_divisions.href" c.execute( "%s %s WHERE body='GA' AND vote is not null AND un_divisions.docid REGEXP 'A-49' ORDER BY nation LIMIT 20000" % (qsel, qlj)) rows = c.fetchall() print '<table class="special">' for row in rows: lrow = [str(r) for r in row] lrow[4] = '<a href="%s#%s">%s</a>' % (EncodeHref({ "pagefunc": "meeting", "docid": lrow[2] }), lrow[3], lrow[4]) print "<tr><td>", "</td><td>".join(lrow), "</td></tr>" print "</table>"
def WriteNationHeading(nation, nationdata): c = GetDBcursor() fnation = re.sub(" ", "_", nation) c.execute( """SELECT nation, date_entered, date_left, continent, missionurl, wikilink, fname FROM un_nations WHERE fname='%s' or nation="%s" """ % (fnation, nation)) ns = c.fetchone() if ns: nation = ns[0] print '<ul class="nationstats">' print '<li>%s has been a member of the United Nations since <em>%s</em></li>' % ( nation, LongDate(ns[1].isoformat())) if ns[2].year != 9999: print '<li>%s left or was renamed in <em>%s</em></li>' % ( nation, LongDate(ns[2].isoformat)) if ns[4]: print '<li>Contact <a href="%s">the ambassador for %s</a></li>' % ( ns[4], nation) else: print '<li>%s is not in <a href="http://www.un.int/index-en/index.html">the list of countries with webpages</a> at the UN.</li>' % nation print '<li>Read the <a href="%s">Wikipedia page for %s</a></li>' % ( ns[5], nation) print '<li>%s is part of the <i>%s</i> block</li>' % (nation, ns[3]) c.execute("""SELECT count(*), min(ldate), max(ldate) FROM un_votes LEFT JOIN un_divisions ON un_divisions.docid=un_votes.docid AND un_divisions.href=un_votes.href WHERE nation=\"%s\" AND vote<>'absent'""" % nation) a = c.fetchone() if a and a[1]: print '<li>%s has participated in %d votes since <em>%s</em>,' % ( nation, a[0], LongDate(a[1].isoformat())) print 'most recently on <em>%s</em></li>' % LongDate( a[2].isoformat()) print '</ul>' csvdata = None for mp in nationdata: if mp["lntype"] == "csvdata": csvdata = mp if nation in scpermanentmembers: print '<p>%s is a <a href="http://en.wikipedia.org/wiki/United_Nations_Security_Council#Permanent_members">permanent member</a> of the Security Council.</p>' % nation if currentscyear not in scelectedmembersyear: print '<p>List of elected members not yet updated; please remind [email protected] to do it.</p>' elif nation in scelectedmembersyear[currentscyear]: print '<p>%s is an <a href="http://en.wikipedia.org/wiki/United_Nations_Security_Council#Elected_members">elected member</a> of the Security Council.</p>' % nation
def WriteSpeechInstances(snation, person, nationdata): c = GetDBcursor() print '<h3>Speeches by the ambassador whose name matches "%s"</h3>' % person print '<ul>' prevdocid = "" for mp in nationdata: if mp["lntype"] == "ambassador" and DownPersonName( mp["name"]) == person and mp["docid"] != prevdocid: href = EncodeHref({ "pagefunc": "meeting", "docid": mp["docid"], "gid": mp["gid"] }) desc, sdate = LookupAgendaTitle(mp["docid"], mp["gid"], c) print '<li>%s %s <a href="%s">%s</a></li>' % ( mp["sdate"], mp["name"], href, desc or mp["sdate"]) prevdocid = mp["docid"] print '</ul>' return recs = XapLookup("nation:%s name:%s class:spoken" % (snation, person)) if not recs: print '<p>No results found</p>' return print '<ul>' for rec in recs: srec = rec.split("|") gidspeech = srec[0] docid = srec[1] gidsubhead = srec[4] agtitle, sdate = LookupAgendaTitle(docid, gidspeech, c) href = EncodeHref({ "pagefunc": "meeting", "docid": docid, "gid": gidspeech }) print '<li>%s <a href="%s">%s</a></li>' % (sdate or "", href, agtitle or docid) print '</ul>'
def WriteMinorityVotes(nation, nationdata): c = GetDBcursor() qsel = "SELECT un_divisions.docid, un_divisions.href, ldate, motiontext, vote, favour, against, abstain, absent FROM un_divisions " qlj = "LEFT JOIN un_votes ON un_votes.docid=un_divisions.docid AND un_votes.href=un_divisions.href AND un_votes.nation=\"%s\"" % nation c.execute( "%s %s WHERE body='GA' AND vote is not null ORDER BY minority_score LIMIT 20" % (qsel, qlj)) minority = c.fetchall() minorityvotes = [] scminorityvotes = [] for mp in nationdata: if mp["lntype"] == "minorityvote": minorityvotes.append(mp) elif mp["lntype"] == "scminorityvote": scminorityvotes.append(mp) if not minorityvotes and not scminorityvotes: return print '<h3 style="clear:both">Minority votes in the General Assembly</h3>' print '<p>Sometimes these votes highlight an issue where there is a difference from the majority of the international community.</p>' print '<p style="margin-top: 1em"><b>%s...</b></p>' % nation print '<table class="minorityvote">' for mp in minority: print '<tr><td class="col1">' (docid, href, ldate, motiontext, vote, favour, against, abstain, absent) = mp mvotes = favour + against + abstain if vote == "against": print 'voted %s <b>against</b>' % MinorityVoteWordsOutOf( against, mvotes) elif vote == "favour": print 'voted %s <b>in favour</b> of ' % MinorityVoteWordsOutOf( favour, mvotes) elif vote == "abstain": print 'voted %s to <b>abstain</b> on' % MinorityVoteWordsOutOf( abstain, mvotes) elif vote == "absent": print 'was <b>absent</b> with <b>%d</b> other nation%s when %d voted' % ( absent - 1 or "zero", absent != 2 and "s" or "", mvotes) else: print ' error vote ', vote, ':::' print '</td>' print '<td class="col3"><a href="%s">%s</a></td>' % (EncodeHref( { "pagefunc": "meeting", "docid": docid, "gid": href }), motiontext) print '<td class="col2"><i>%s</i></td>' % LongDate( ldate.strftime("%Y-%m-%d")) print '</tr>' print '</table>' #print '<ul>' #for mp in minorityvotes: # print '<li>%s - <a href="%s">%s</a></li>' % (LongDate(mp["date"]), EncodeHref({"pagefunc":"meeting", "docid":mp["docid"], "gid":mp["gid"]}), mp["description"]) #print '</ul>' if not scminorityvotes: return print '<h3 style="clear:both">Minority votes in the Security Council</h3>' print '<p>For a permanent member a vote against constitutes a veto.</p>' print '<ul class="scminorityvote">' for mp in scminorityvotes: sdesc = "Description" c.execute("SELECT heading, ldate FROM un_scheadings WHERE docid='%s'" % mp["docid"]) a = c.fetchone() if a: sdesc = re.sub("<[^>]*>", "", a[0]).strip() if not sdesc: sdesc = "Ediscription" print '<li>%s - <a href="%s">%s</a></li>' % ( LongDate(mp["date"]), EncodeHref({ "pagefunc": "meeting", "docid": mp["docid"], "gid": mp["gid"] }), sdesc) print '</ul>'
def WritePDFpreview(docid, pdfinfo, rfr, bscrapedoc): parsed = (pdfinfo.mgapv or pdfinfo.mscpv) WriteGenHTMLhead('%s %s' % (pdfinfo.pdfc, pdfinfo.desc)) code = pdfinfo.pdfc if bscrapedoc: sys.path.append("../scraper") from unscrapedoc import ScrapePDFdoc mess = ScrapePDFdoc(code, pdfinfo.pdffile) print mess pdfpreviewf = os.path.join(pdfpreviewdir, code + ".jpg") if os.path.isfile(pdfpreviewf): pass #print '<img style="float:right" src="/pdfpreviewjpg/%s">' % code resurl, reswref = GenWDocLink(pdfinfo, None, None) if rfr == 'wikipedia': print '<div id="rightdoclinks">' print '<p>Links for wikipedians</p>' print '<ul>' print '<li><a href="http://en.wikipedia.org/wiki/Wikipedia:WikiProject_United_Nations">WikiProject United Nations</li>' print '<li><a href="http://www.undemocracy.com/incoming">Other wikipedia articles</a> which link to undemocracy.com</li>' print '<li><a href="/">Front page of undemocracy.com</a></li>' print '<li><a href="http://www.guardian.co.uk/technology/2008/mar/13/internet.politics">Newspaper article about this project</a>.</li>' print '</ul>' print '</div>' pdflink = os.path.exists(pdfinfo.pdffile) and EncodeHref({"pagefunc":"nativepdf", "docid":code}) if pdflink: print '<p style="text-align:center; padding-bottom: 2em; padding-top: 2em;"><a class="pdfview" href="%s">' % pdflink print '<img style="vertical-align: sub" src="/images/pdficon_large.gif" alt="(PDF)" border="0">' print 'View PDF document' print '</a></p>' print '<p>This is a holding page for the official document with <a href="http://en.wikipedia.org/wiki/United_Nations_Document_Codes">code</a> <i><b>%s</b></i>.' % code print 'The United Nations does not enable direct links to most of their documents.' print '</p>' print '<p style="padding-top:0.5em">Using this webpage, you can --</p>' print '<ul class="d">' if pdfinfo.mgapv or pdfinfo.mscpv: pfile = os.path.join(htmldir, pdfinfo.pdfc + ".html") if os.path.isfile(pfile): print '<li class="d">Go to <a href="%s">HTML version</a> of this transcript</li>' % (EncodeHref({"pagefunc":"meeting", "docid":code})) else: print '<li class="d">There is no parsed version for this verbatim report.</li>' if pdflink: print '<li class="d"><a href="%s">View as PDF</a></li>' % pdflink print '<li class="d">Or click on individual pages--</li>' print '<li class="d">' npages = pdfinfo.pages == -1 and 5 or pdfinfo.pages for n in range(npages): print '<a href="%s">Page %d</a>' % (EncodeHref({"pagefunc":"pdfpage", "docid":code, "page":(n+1)}), n + 1), if pdfinfo.pages == -1: print '(Accurate page-count unknown.)' print '</li>' lundlink = re.sub('[\-"]', "/", pdfinfo.pdfc) if re.match("S/PV/\d", lundlink): # handle mistaken dash in these cases lundlink = re.sub('PV/', 'PV.', lundlink) undlink = "http://www.un.org/Docs/journal/asp/ws.asp?m=" + lundlink print '<li class="d">Try linking directly to <a href="%s">%s</a></li>' % (undlink, undlink) if not pdflink: print '<li class="d">No document available on undemocracy.com server.', if bscrapedoc: print '<b>Document scraping attempt failed, unfortunately.</b></li>' else: print 'Click <a href="%s"><b>here</b></a> to try and request it. (new feature!)</li>' % EncodeHref({"pagefunc":"document", "docid":code, "scrapedoc":True}) print '<li class="d"><a href="http://www.un.org/documents/">UN Documentation Centre</a></li>' if pdfinfo.bGA: print '<li class="d">See all <a href="/generalassembly/documents">General Assembly documents</a>.</li>' if pdfinfo.bSC: print '<li class="d">See all <a href="/securitycouncil/documents">Security Council documents</a>.</li>' print '<li class="d">Ready-made URL link: <input style="text" readonly value="%s"></li>' % resurl print '<li class="d">Ready-made <a href="http://en.wikipedia.org/wiki/Help:Footnotes">wikipedia link</a> ' print 'using <a href="http://en.wikipedia.org/wiki/Template:UN_document">Template:UN_document</a>: ' print '<input style="text" readonly value="%s"></li>' % reswref print '</ul>' c = GetDBcursor() if pdfinfo.pvrefs: print '<h3>References to this document</h3>' print '<p>List of all post-1994 meetings of the Security Council or General Assembly where this document was specifically mentioned.</p>' print '<ul class="docrefs">' for pvrefk in sorted(pdfinfo.pvrefsing.keys()): mcode = pvrefk[1] hmap = { "pagefunc":"meeting", "docid":mcode, "highlightdoclink":code } hmap["gid"] = min(pdfinfo.pvrefsing[pvrefk]) agtitle, sdate = LookupAgendaTitle(mcode, hmap["gid"], c) print '<li>%s <a href="%s">%s</a></li>' % (pvrefk[0], EncodeHref(hmap), (agtitle or mcode)) print '</ul>' print '</body>' print '</html>'