Beispiel #1
0
def WriteDocumentListingEarly(body):
    if body == "securitycouncil":
        bSC, bGA = True, False
        WriteGenHTMLhead("Security Council early Documents")
    elif body == "generalassembly":
        bSC, bGA = False, True
        WriteGenHTMLhead("General Assembly early Documents")
    else:
        bSC, bGA = True, True
        WriteGenHTMLhead("All early Documents")

    PVlist = []
    for ldocid in os.listdir(pdfdir):
        if bSC:
            mpv = re.match("(S-PV-(\d+).*?)\.pdf$", ldocid)
            if mpv:
                PVlist.append((int(mpv.group(2)), mpv.group(1)))
    PVlist.sort()

    print '<p>Lists of early Security Council meeting transcripts of unknown vintage.'
    nh = -1
    for num, docid in PVlist:
        if num >= (nh + 1) * 100:
            nh = int(num / 100)
            print "</p>\n\n<h2>%d00's</h2>\n<p>" % nh
        print '<a href="%s">%s</a>' % (EncodeHref({
            "pagefunc": "document",
            "docid": docid
        }), docid)
    print '</p>'
Beispiel #2
0
def WriteDocumentListing(body):
    docyearsdir = os.path.join(indexstuffdir, "docyears")
    if body == "securitycouncil":
        bSC, bGA = True, False
        WriteGenHTMLhead("Security Council Documents")
    elif body == "generalassembly":
        bSC, bGA = False, True
        WriteGenHTMLhead("General Assembly Documents")
    else:
        bSC, bGA = True, True
        WriteGenHTMLhead("All Documents")

    print '<p>This is a table of the numbers of UN documents we have obtained for reference '
    print 'of each kind sorted by year or session.  Click on the link to list the codes of all the documents '
    print 'for that year.</p>'

    print '<h2><b>New:</b> Find some <a href="%s">pre-1994 Security Council Transcripts</a>.</h3>' % EncodeHref(
        {"pagefunc": "scyearearly"})

    print '<table class="doccounttable">'
    print '<tr><th>Year/Session</th>'
    print '<th>Verbatim<br>reports</th>'
    print '<th>Resolutions</th>'
    print '<th>Presidential<br>Statements</th>'
    print '<th>Documents</th>'
    print '</tr>'

    for s in range(max(currentgasession, currentscyear - 1945), 0, -1):
        gadocyearfile = os.path.join(docyearsdir, "ga%d.txt" % s)
        if bGA and os.path.isfile(gadocyearfile):
            dlist = LoadDocYearFile(gadocyearfile)
            print '<tr class="gadocs">'
            print '<td><a href="%s">Session %d</a>' % (EncodeHref(
                {
                    "pagefunc": "gadocuments",
                    "gasession": s
                }), s)
            if not bSC:
                print ' (%s-%s)' % (s + 1945, s + 1946)
            print '</td> '
            print '<td>%d</td> <td>%d</td> <td> </td> <td>%d</td>' % (len(
                dlist["PV"]), len(dlist["RES"]), len(dlist["DOC"]))
            print '</tr>'
        scyear = s + 1945
        scdocyearfile = os.path.join(docyearsdir, "sc%d.txt" % scyear)
        if bSC and os.path.isfile(scdocyearfile):
            dlist = LoadDocYearFile(scdocyearfile)
            print '<tr class="scdocs">'
            print '<td><a href="%s">%d</a></td>' % (EncodeHref({
                "pagefunc": "scdocuments",
                "scyear": scyear
            }), scyear)
            print '<td>%d</td> <td>%d</td> <td>%d</td> <td>%d</td>' % (len(
                dlist["PV"]), len(dlist["RES"]), len(
                    dlist["PRST"]), len(dlist["DOC"]))
            print '</tr>'

    print '</table>'
Beispiel #3
0
def WriteAllNations():
    WriteGenHTMLhead('List of all nations')
    nationactivitydir = os.path.join(indexstuffdir, "nationactivity")

    res = []
    for nat in os.listdir(nationactivitydir):
        if nat[0] != ".":
            nation = re.sub("_", " ", nat[:-4])  # remove .txt
            flaghref = EncodeHref({
                "pagefunc": "flagpng",
                "width": 100,
                "flagnation": nation
            })
            href = EncodeHref({"pagefunc": "nation", "nation": nation})
            res.append((nation, href, flaghref))

    res.sort()
    ncols = 4
    colleng = (len(res) + ncols - 1) / ncols
    print '<table><tr>'
    for j in range(ncols):
        print '<td style="vertical-align:top;"><table>'
        for k in range(j * colleng, min(len(res), (j + 1) * colleng)):
            print '<tr>'
            nation, href, flaghref = res[k]
            print '<td class="smallflag_lis"><a href="%s"><img class="smallflag_lis" src="%s"></a></td>' % (
                href, flaghref)
            print '<td><a href="%s">%s</a></td>' % (href, nation)
            print '</tr>'
        print '</table></td>'
    print '</tr></table>'
Beispiel #4
0
def WriteIndexStuffSecYear(scyear):
    WriteGenHTMLhead("Security Council Meetings of %s" % scyear)
    allsc = LoadSecRecords("all")
    sl = [(screcord.sdate, screcord) for screcord in allsc
          if (screcord.sdate[:4] == scyear)]
    sl.sort()
    WriteAgendaList([screcord for sdate, screcord in sl])
    return True
Beispiel #5
0
def WriteFrontPageError(pathpartstr, hmap):
    WriteGenHTMLhead(
        "Something is wrong",
        frontpage=False)  # deliberately false, as bad URLs go here
    print "<h1>Did not recognize pathpartstr: '%s'</h1>" % pathpartstr
    print "<h3>hmap:"
    print hmap
    print "</h3>"
Beispiel #6
0
def WriteIndexStuffSec():
    allsc = LoadSecRecords("all")
    WriteGenHTMLhead("Security Council Meetings by topic")
    print '<p><a href="/generalassembly">General Assembly topics</a></p>'
    print '<p><a href="/securitycouncil/documents">Security Council documents</a></p>'
    print '<p><a href="/">Front page</a></p>'
    WriteCollapsedSec(allsc)
    return True
Beispiel #7
0
def WriteIndexStuffAgnum(agnum):
    msess = re.search("-(\d+)$", agnum)  # derive the session if there is one
    nsess = msess and int(msess.group(1)) or 0

    allags = LoadAgendaNames(agnum)

    if nsess:
        agnumlist = agnum.split(",")
        ags = [agrecord for agrecord in allags if agrecord.agnum in agnumlist]
    else:
        # assert agnum in ["condolence", "recent" ]
        ags = [
            agrecord for agrecord in allags if re.match(agnum, agrecord.agnum)
        ]

    agtitle = "Topic of General Assembly"
    WriteGenHTMLhead(agtitle)

    if agnum == "condolence":
        print '<p>According to the <a href="http://www.undemocracy.com/A-520-Rev.16/page_97">procedures of the General Assembly</a>, when there has been a major disaster only '
        print 'the president is permitted to offer condolences to the victims at the start of the meeting.'
        print 'This is probably to avoid the entire day being taken up with every ambassador in turn offering '
        print 'their own expression of sympathy.  This timeline of disasters is incomplete owing to the '
        print 'General Assembly not always being in session.'
        ags.reverse()

    if nsess:
        print '<p><a href="%s">Whole of session %d</a></p>' % (EncodeHref(
            {
                "pagefunc": "gasession",
                "gasession": nsess
            }), nsess)

    #print '<h2><a href="%s">See this agenda all unrolled</a></h2>' % EncodeHref({"pagefunc":"agendanumexpanded", "agendanum":agnum})

    if ags:
        print '<h3>%s</h3>' % ags[0].aggrouptitle
        WriteAgendaList(ags)
    else:
        print '<h3>List appears empty</h3>'
        print len(allags)
        for a in allags[:89]:
            print '<p>' + a.agnum

    return True
Beispiel #8
0
def WriteIndexStuffNation(nation, person):
    WriteGenHTMLhead('Nation page for %s' % nation)
    flaghref = EncodeHref({
        "pagefunc": "flagpng",
        "width": 100,
        "flagnation": nation
    })
    print '<h1>%s</h1>' % nation
    print '<img class="nationpageflag" src="%s">' % flaghref
    snation = re.sub(" ", "_", nation)
    nationdata = GatherNationData(snation)

    if person:
        WriteSpeechInstances(snation, person, nationdata)
    else:
        WriteNationHeading(nation, nationdata)
        WriteMinorityVotes(nation, nationdata)
        WriteAmbassadorList(nation, nationdata)
Beispiel #9
0
def WriteHTMLagnum(agnum, aglist):
    WriteGenHTMLhead("Unrolled: " + aglist[0].aggrouptitle)
    print '<h3><a href="%s">Rolled back up agenda</a></h3><p></p>' % EncodeHref({"pagefunc":"agendanum", "agendanum":agnum})

    prevfhtml = ""
    for agrecord in aglist:
        if agrecord.fhtml == prevfhtml: # avoid repeating the same document more than once when agendas get re-opened
            continue
        prevfhtml = agrecord.fhtml

        fin = open(agrecord.fhtml)
        ftext = fin.read()
        fin.close()
        
        print '<h1>%s</h1>' % agrecord.sdate
        agendanumcurrent = ""
        #continue
        for mdiv in re.finditer(rdivspl, ftext):
            dclass, gid, agendanum = mdiv.group(1), mdiv.group(2), mdiv.group(3)
            stext = mdiv.group(4).strip()
            if dclass == "assembly-chairs":
                WriteAssemblyChair(gid, ftext)   # could always use this for doing the date band
                continue   
            if dclass == "heading":
                continue   # wot are we going to do about this? needs numbers for the javascript links

            if dclass == "subheading":
                agendanumcurrent = agendanum   # this would do some kind of folding down or up when we get there
            if agnum != agendanumcurrent:
                continue   # only printing that which is in this agenda 
            
            dtext = MarkupLinks(stext, "")
            if dclass == "subheading":
                WriteAgendaFlipped(gid, agendanum, dtext, agrecord.docid)
            elif dclass == "spoken": 
                WriteSpoken("", dtext, "")
            elif dclass == "recvote":
                WriteVote("", dtext, False)
            elif re.match("italicline", dclass):
                WriteItalicLine("", dclass, dtext)
            elif dclass == "end-document":
                pass
            else:
                print '<div>UNEXPECTED Class %s</div>' % dclass
Beispiel #10
0
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>"
Beispiel #11
0
def WriteWebcastIndexPage(body, wcdate):
    if body == "securitycouncil":
        urlt, year = "sc.html", "2008"
        sbody = "Security Council"
        if wcdate and "2003" <= wcdate[:4] < nowyear:
            year = wcdate[:4]
            if year == "2004":
                urlt = "sc2004.htm"  # anomaly
            else:
                urlt = "sc%s.html" % year
    else:  # body == "generalassembly"
        urlt, year = "ga.html", nowyear
        sbody = "General Assembly"
        if wcdate and "2003" <= wcdate[:4] < nowyear:
            year = wcdate[:4]
            if year <= "2004":
                urlt = "ga2004.htm"  # doubling up and no l
            else:
                urlt = "ga%s.html" % year
    url = "http://www.un.org/webcast/%s" % urlt

    WriteGenHTMLhead("%s webcast index for %s" % (sbody, year))
    print "<h2>Skinned index page</h2>"
    print '<p>The original webcast archive page for %s is <a href="%s">here</a>.' % (
        sbody, url)
    print 'Unfortunately, it lacks local anchors to the rows in the table which would have made it '
    print 'possible to directly link to them.  Nor does it include links to the UN documents that are referenced '
    print 'by their code-number.  The main UN page for webcasts is <a href="http://www.un.org/webcast">here</a>.</p>'

    spip = ScrapeParseWCIndexPage(url)

    print '<table id="wclist">'
    prevdate = ""
    for rl in spip:
        if rl[0] != prevdate:
            print '<tr id="d%s">' % rl[0]
            prevdate = rl[0]
        else:
            print '<tr>'
        print '<td class="wcdate">%s</td>' % LongDateNB(rl[0])
        print '<td class="wccont">%s</td>' % rl[1]
        print "</tr>"
    print "</table>"
Beispiel #12
0
def WriteWikiPage():
    WriteGenHTMLhead("Wikipedia references")
    bigwikitable = BigWikipediaTable()
    print '<div id="wplinks">'
    print '<h3>Wikipedia table</h3>'
    print '<p>List of incoming links from Wikipedia from wikipedia articles.</p>'
    print '<table class="wpreftab">'
    print '<tr> <th>N</th> <th>Document</th> <th>First</th> <th>Last</th> </tr>'

    for bigwikirow in bigwikitable:
        if re.search("index.php", bigwikirow[4]):
            continue
        print '<tr>',
        print '<td>%d</td>' % bigwikirow[2]
        print '<td><a href="%s">%s</a></td>' % (bigwikirow[3], bigwikirow[4])
        print '<td>%s</td><td>%s</td>' % (bigwikirow[1].strftime("%Y-%m-%d"),
                                          bigwikirow[0].strftime("%Y-%m-%d"))
        print '</tr>'
    print '</table>'
    print '</div>'
Beispiel #13
0
def WriteIndexStuff(nsess):
    WriteGenHTMLhead("General Assembly Session %d (%d-%d)" %
                     (nsess, nsess + 1945, nsess + 1946))
    allags = LoadAgendaNames(None)

    print '<p>',
    tlinks = []
    if nsess > 1:
        tlinks.append(GetSessionLink(nsess - 1, False))
    tlinks.append('<a href="%s">All sessions</a>' %
                  (EncodeHref({"pagefunc": "gatopics"})))
    tlinks.append(GetSessionLink(nsess, True))  # documents
    if nsess < currentgasession:
        tlinks.append(GetSessionLink(nsess + 1, False))
    print ' | '.join(tlinks),
    print '</p>'

    ags = [agrecord for agrecord in allags if agrecord.nsess == nsess]
    print '<h3>Full list of topics discussed</h3>'
    print '<p>Several topics may be discussed on each day, and each topic may be discussed over several days.</p>'
    WriteCollapsedAgendaList(ags, True)
Beispiel #14
0
def WriteIndexStuffGA():
    WriteGenHTMLhead("All General Assembly Topics")

    print '<p><a href="%s">Security Council Topics</a></p>' % EncodeHref(
        {"pagefunc": "sctopics"})
    print '<h3>Topics that span more than one year</h3>'
    print '<ul class="aglistgroup">'
    print '<li><a href="%s" class="aggroup">Condolences</a></li>' % EncodeHref(
        {
            "pagefunc": "agendanum",
            "agendanum": "condolence"
        })  # special case
    print '</ul>'

    print '<h3>General Assembly Sessions topics by year</h3>'
    print '<ul>'
    for nsess in range(currentgasession, 48, -1):
        print '<li>',
        print GetSessionLink(nsess, True),
        print '(%d-%d)' % (nsess + 1945, nsess + 1946)
        print '</li>',
    print '</ul>'
    return
Beispiel #15
0
def WriteIndexStuffDocumentsYear(docyearfile):
    msc = re.search("sc(\d+).txt$", docyearfile)
    mga = re.search("ga(\d+).txt$", docyearfile)
    if msc:
        WriteGenHTMLhead("Security Council %s Documents" % msc.group(1))
        nscyear = int(msc.group(1))

        print '<table class="prevnextmeeting"><tr>'
        if nscyear > 1946:
            print '<td><a href="%s">Year %d</td>' % (EncodeHref({
                "pagefunc":
                "scdocuments",
                "scyear": (nscyear - 1)
            }), nscyear - 1)
        else:
            print '<td></td>'

        nsess = max(1, min(currentgasession, nscyear - 1945))
        print '<td><a href="%s">Session %d</td>' % (EncodeHref(
            {
                "pagefunc": "gadocuments",
                "gasession": nsess
            }), nsess)

        if nscyear < currentscyear:
            print '<td><a href="%s">Year %d</td>' % (EncodeHref({
                "pagefunc":
                "scdocuments",
                "scyear": (nscyear + 1)
            }), nscyear + 1)
        else:
            print '<td></td>'
        print '</tr></table>'

    else:
        WriteGenHTMLhead("General Assembly Session %s Documents" %
                         mga.group(1))
        nsess = int(mga.group(1))

        print '<table class="prevnextmeeting"><tr>'
        if nsess > 1:
            print '<td><a href="%s">Session %d</td>' % (EncodeHref({
                "pagefunc":
                "gadocuments",
                "gasession": (nsess - 1)
            }), nsess - 1)
        else:
            print '<td></td>'

        nscyear = max(1946, min(currentscyear, nsess + 1945))
        print '<td><a href="%s">year %d</td>' % (EncodeHref({
            "pagefunc": "scdocuments",
            "scyear": nscyear
        }), nscyear)

        if nsess > 1:
            print '<td><a href="%s">Session %d</td>' % (EncodeHref({
                "pagefunc":
                "gadocuments",
                "gasession": (nsess + 1)
            }), nsess + 1)
        else:
            print '<td></td>'
        print '</tr></table>'

    dlists = LoadDocYearFile(docyearfile)

    if dlists["RES"]:
        print "<h3>Resolutions</h3>"
        print '<p>'
        for docid in dlists["RES"]:
            print '<a href="%s">%s</a>' % (EncodeHref({
                "pagefunc": "document",
                "docid": docid
            }), docid)
        print '</p>'

    if dlists["DOC"]:
        print "<h3>Documents</h3>"
        print '<p>'
        for docid in dlists["DOC"]:
            print '<a href="%s">%s</a>' % (EncodeHref({
                "pagefunc": "document",
                "docid": docid
            }), docid)
        print '</p>'

    if dlists["PRST"]:
        print "<h3>Presidential Statements</h3>"
        for docid in dlists["PRST"]:
            print '<a href="%s">%s</a>' % (EncodeHref({
                "pagefunc": "document",
                "docid": docid
            }), docid)
        print '</p>'

    if dlists["PV"]:
        print "<h3>Verbatim Reports</h3>"
        for docidh in dlists["PV"]:
            if docidh[-5:] == ".html":
                if msc:
                    print '<a href="%s">%s</a>' % (EncodeHref(
                        {
                            "pagefunc": "meeting",
                            "docid": docidh[:-5]
                        }), docidh)
                else:
                    print '<a href="%s">%s</a>' % (EncodeHref(
                        {
                            "pagefunc": "meeting",
                            "docid": docidh[:-5]
                        }), docidh)
            else:
                print '<a href="%s">%s</a>' % (EncodeHref({
                    "pagefunc": "document",
                    "docid": docid
                }), docid)
        print '</p>'
Beispiel #16
0
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>'
Beispiel #17
0
def WriteIndexSearch(search):
    WriteGenHTMLhead("Searching for '%s'" % search)
    recs = XapLookup(search)
    if not recs:
        print '<p>No results found</p>'
        return True

    allags = LoadAgendaNames(None)  # very inefficient, but get it done
    aglookup = {}
    for agrecord in allags:
        aglookup[(agrecord.docid, agrecord.gid)] = agrecord

    allsc = LoadSecRecords("all")
    sclookup = {}
    for screcord in allsc:
        sclookup[screcord.docid] = screcord

    highlights = SplitHighlight(search)

    print '<div id="search-results">'
    for rec in recs:
        # id of para, document number, byte offset start, byte length, heading id
        srec = rec.split("|")
        #print "xap records", srec
        gidspeech = srec[0]
        docid = srec[1]
        byte_start = int(srec[2])
        byte_len = int(srec[3])
        gidsubhead = srec[4]

        # extract record using byte offset
        fullfilename = os.path.join(undata, "html", docid + '.html')
        f = open(fullfilename)
        f.seek(byte_start)
        content = f.read(byte_len)
        f.close()

        # really nasty search highlighting
        words = re.split("<[^>]*>|</[^>]*>|(\S+)", content)
        words = [x for x in words if x]
        firstword = 0
        for i in range(len(words)):
            word = words[i]
            if re.match(highlights[1], word) and not firstword:
                firstword = i
        roundwords = words[firstword - 50:firstword + 50]
        extract_text = " ".join(roundwords)
        extract_text = extract_text.replace(
            "</p>", "")  # XXX why does split not cover this?
        extract_text = MarkupLinks(extract_text, search)

        if re.match("A", docid):
            agrecord = aglookup.get((docid, gidsubhead), None)
            if agrecord:
                print '<h2>General Assembly: %s</h2>' % (agrecord.GetDesc(
                    search, gidspeech))
                print extract_text
                del aglookup[(docid,
                              gidsubhead)]  # quick hack to avoid repeats
        if re.match("S", docid):
            screcord = sclookup.get(docid, None)
            if screcord:
                print '<h2>Security Council: %s</h2>' % (screcord.GetDesc(
                    search, gidspeech))
                print '<p>' + extract_text + '</p>'
                del sclookup[docid]
    print '</div>'
Beispiel #18
0
def WritePDFpreviewpage(pdfinfo, npage, highlightrects, highlightedit):
    WriteGenHTMLhead("%s page %d" % (pdfinfo.desc, npage))
    code = pdfinfo.pdfc

    hmap = {"pagefunc":"pdfpage", "docid":code}
    resurl, reswref = GenWDocLink(pdfinfo, npage, highlightrects)
    print '<div id="docpagespecs">'
    
    print '<p><i>This</i> is page <b>%s</b>' % npage
    fulldoc = EncodeHref({"pagefunc":"document", "docid":code})
    if pdfinfo.pages == -1:
        print ' of a <a href="%s"><b>Document</b></a> with an unknown number of pages.</p>' % fulldoc
    else:
        print ' of a <b>%d</b> page <a href="%s"><b>Document</b></a>.</p>' % (pdfinfo.pages, fulldoc)

    lpages = [ ]
    lpages.append('Go to')
    if npage != 1:
        hmap["page"] = npage - 1
        lpages.append(' <a href="%s">previous page</a>' % EncodeHref(hmap))
    else:
        lpages.append(' <a href="%s">full document</a>' % fulldoc)
    if pdfinfo.pages == -1 or npage + 1 <= pdfinfo.pages:
        hmap["page"] = npage + 1
        lpages.append(' or <a href="%s">next page</a>' % EncodeHref(hmap))
    print '<p>%s</p>' % "".join(lpages)
    
    hmap["page"] = npage
    hmap["highlightrects"] = highlightrects
    hmap["highlightedit"] = False

    print '</div>'

    print '<div id="highlightcontrols">'
    #print '<p>' # <span class="linktabfleft">URL:</span> <input style="text" readonly value="%s">' % resurl
    print '<textarea rows="2" cols="50" style="float:right;font-size:75%%" readonly>%s</textarea>' % reswref
    print '<div class="linktabfleft">wiki<br/>templ:</div> '
    #print '<input type="text" style="font-size:50%%" size="100" readonly value="%s"></p>' % reswref

    if highlightrects:
        hmap["highlightrects"] = [ ]
        print '<a href="%s">Without any highlight</a>.' % EncodeHref(hmap),
        if len(highlightrects) > 1:
            for ih in range(len(highlightrects)):
                hmap["highlightrects"] = highlightrects[:]
                del hmap["highlightrects"][ih]
                print '<a href="%s">Without highlight %d</a>' % (EncodeHref(hmap), ih + 1),

        hmap["highlightrects"] = highlightrects

    if highlightedit:
        print '<script src="/cropper/lib/prototype.js" type="text/javascript"></script>' 
        print '<script src="/cropper/lib/scriptaculous.js?load=builder,dragdrop" type="text/javascript"></script>'
        print '<script src="/cropper/cropper.js" type="text/javascript"></script>'
        print """<script type="text/javascript">
                    Event.observe(window, 'load',
                              function() { new Cropper.Img('pdfpageid', { onEndCrop: onEndCrop }); } );

                function onEndCrop( coords, dimensions )
                {
                    var achl = document.getElementById('consdhighlight');
                    var imgl = document.getElementById('pdfpageid');
                    lhref = achl.href.substring(0, achl.href.lastIndexOf('/') + 1);
                    ix1 = Math.ceil(coords.x1 * 1000 / imgl.width);
                    iy1 = Math.ceil(coords.y1 * 1000 / imgl.width);
                    ix2 = Math.ceil(coords.x2 * 1000 / imgl.width); 
                    iy2 = Math.ceil(coords.y2 * 1000 / imgl.width);
                    rs = "rect_" + ix1 + "," + iy1 + "_" + ix2 + "," + iy2; 
                    achl.href = lhref + rs; 
                };
                </script>"""

        print 'Click and drag with your mouse to highlight the area of text you want.'
        hmap["highlightedit"] = False
        print '<div style="font-size:8;float:right">Thanks to <br><a href="http://www.defusion.org.uk/code/javascript-image-cropper-ui-using-prototype-scriptaculous/">Dave Spurr</a>.</div>'
        print '<br><a href="%s">Leave editing mode</a>' % (EncodeHref(hmap))
        print '<a id="consdhighlight" href="%s/"><b>Consolidate highlight</b></a>' % EncodeHref(hmap)
    else:
        hmap["highlightedit"] = True
        print '<a href="%s"><b>Add new highlight</b></a>' % EncodeHref(hmap)

    del hmap["highlightedit"]
    print '</div>'

    hmap["pagefunc"] = "pagepng"
    hmap["width"] = 800
    print '<div class="pdfpagediv"><img id="pdfpageid" src="%s"></div>' % EncodeHref(hmap)

    print '<p style="clear:both">%s</p>' % "".join(lpages)
Beispiel #19
0
def WriteFrontPage():
    WriteGenHTMLhead("Front page", frontpage=True)

    print '''
        <div style="padding: 1ex; margin: 3px; background-color:#f9b5b5; border: thin red solid; margin-top:0em; float:right; width:260px">
                        <form method="post" action="http://www.theunsays.com/cgi-bin/emailnotify/singleform.cgi" id="singleform" name="singleform" >                           
                        <strong>Email me when</strong> <input type="text" value="anything" size="9" onclick="this.value=''" name="keyword" /> appears in a press release.      
                        <strong>Email:</strong> <input type="text" size="15" value="your address" onclick="this.value=''" name="email" />                                      
                        <input type="hidden" name="source" value="undemocracy.com" />                                                                                          
                        <input type="submit" onclick=" if ( document.singleform.keyword.value == 'anything' ) {document.singleform.keyword.value = ''; }                       
                                                      if ( document.singleform.email.value == 'your address' ) {alert('email address missing'); return false; }                
                                        " value="signup" />                                                                                                                    
                        </form>  
        </div>

            <p style="margin-top:1em"><b>This website</b> gives easy access to the transcripts (since 1994) of 
             two of the five principal 
             <a href="http://en.wikipedia.org/wiki/United_Nations_System" title="Wikipedia article about the United Nations System"><b>United Nations bodies</b></a>.</p>  
             
             <p style="margin-top:0.5em">The 
             <a href="http://en.wikipedia.org/wiki/United_Nations#Security_Council" title="Wikipedia article describing the Security Council"><b>Security Council</b></a> 
             can authorize war and international sanctions.</p>

             <p style="margin-top:0.5em">The 
             <a href="http://en.wikipedia.org/wiki/United_Nations#General_Assembly" title="Wikipedia article describing the United Nations General Assembly"><b>General Assembly</b></a>
             directs the business of the United Nations and 
             recommends international treaties.
             

             <div style="padding: 1ex; margin: 3px; background-color:#f9b5b5; border: thin red solid; margin-top:0em; float:right; width:260px">Media: 
             <a href="http://www.guardian.co.uk/technology/2008/mar/13/internet.politics">Newspaper article 13 March</a>, 
             <a href="http://video.google.com/videoplay?docid=5811193931753907681&hl=en-GB">4 minute video presentation</a>,
             <a href="http://citizenreporter.org/2008/01/bm241-making-better-use-of-the-united-nations/">Podcast interview</a>.
             <br/>
             Notes on the <a href="http://www.freesteel.co.uk/wpblog/category/whipping/un/">creator's blog</a>.
             <br/>
             <b>New:</b> Links to <a href="http://www.undemocracy.com/generalassembly/webcastindex">webcasts</a>.</div>
             
         <p style="margin-top:0.5em">Find out what <a href="/nations" title="List all nations and their ambassadors who speak"><b>your nation</b></a> has been doing in this international forum.</p>

             <p style="margin-top:1em; margin-bottom:0.5em"><b style="background:#b3f1d7;">The third column</b> lists 
             recent visits from Wikipedia readers.
             <i>This is the best place to start browsing, 
             because only some of documents are very interesting and you are unlikely to get lucky
             if you click at random.</i></p>'''

    print '''<p style="margin-botton:1em"><b>Note</b>: While Security Council meetings are on-line within 
             hours, General Assembly transcripts go on-line three months after
             the meeting (although the videos are up immediately).  The start of the 63rd 
             session is <a href="http://www.un.org/ga/63/meetings63.shtml"><b>here</b></a>.</p>'''

    print '<div id="sectors">'
    print '<div id="securitycouncil">'
    print '<h2>Security Council</h2>'

    print '<p><a href="/securitycouncil" title="Comprehensive list of meetings by date according to agenda item">Meetings by topic</a></p>'
    print '<p><a href="/securitycouncil/documents" title="Table of documents of the Security Council by year">All documents</a></p>'

    print '<h3>Recent meetings</h3>'
    recentsc = LoadSecRecords("recent")[:12]
    print '<ul class="cslist">'
    for screcord in recentsc:
        print '<li>%s</li>' % re.sub(
            "--", " - ", screcord.GetDesc())  # sub to allow word wrapping
    print '</ul>'

    print '</div>'

    print '<div id="generalassembly">'
    print '<h2>General Assembly</h2>'

    print '<p><a href="/generalassembly" title="Table of sessions which link to comprehensive lists of agenda items">Meetings by topic</a></p>'
    print '<p><a href="/generalassembly/documents" title="All documents of the General Assembly">All documents</a></p>'

    print '<h3>Recent meetings</h3>'

    recentags = LoadAgendaNames("recent")[:8]
    print '<ul class="cslist">'
    for agrecord in recentags:
        print '<li>%s</li>' % agrecord.GetDesc()
    print '</ul>'

    print '</div>'

    txtaboutus = """
    <h2>Information</h2>
    <p><b>This site</b> has nothing to do with the <b><a href="http://www.un.org/english">real UN website</a></b> 
    or any part of the United Nations itself.  It has been supported by no organization. 
    It is merely a citizens' attempt to provide Web 2.0 compliant access to 
    many of the important official UN documents 
    (eg <a href="http://en.wikipedia.org/wiki/United_Nations_Security_Council">Security Council Resolutions</a> 
    and <a href="http://en.wikipedia.org/wiki/United_Nations_General_Assembly">General Assembly votes</a>)
    which feature in the news.</p>

    <p><b>For</b> background information about the UN and its structure, as well as the meaning and purpose of these documents, 
    check out <a href="http://en.wikipedia.org/wiki/United_Nations">United Nations on Wikipedia</a>
    and read the related articles.  
    Why not help to <a href="http://en.wikipedia.org/wiki/Wikipedia:WikiProject_United_Nations">improve them</a>?</p>
    
    <p><b>For</b> a quick tour of the sets of documents that are available here, look at
    <a href="http://www.undemocracy.com/United_States/bush">President Bush</a> of
    <a href="http://www.undemocracy.com/United_States">The United States</a>, or
    <a href="http://www.undemocracy.com/Iran/ahmadinejad">President Ahmadinejad</a> of
    <a href="http://www.undemocracy.com/Iran">Iran</a>, as well as
    <a href="http://www.undemocracy.com/S-RES-242(1967)">all speeches</a>
    that refer to <a href="http://en.wikipedia.org/wiki/United_Nations_Security_Council_Resolution_242">Resolution 242</a>.</p>

    <p><b>Questions</b> about this website in particular are answered by:
    <a href="http://www.publicwhip.org.uk/faq.php#organisation">Who?</a>
    <a href="http://en.wikipedia.org/wiki/United_Nations_Document_Codes">What?</a>
    <a href="http://www.freesteel.co.uk/wpblog/category/whipping/un/">When?</a>
    <a href="http://www.freesteel.co.uk/wpblog/">Where?</a>
    <a href="http://www.freesteel.co.uk/wpblog/2007/09/the-purpose-of-the-undemocracycom-site/"><b>Why?</b></a>
    <a href="http://www.freesteel.co.uk/wpblog/2007/09/how-does-undemocracycom-work/">How?</a>, and finally
    <a href="http://www.freesteel.co.uk/wpblog/2007/09/undemocracy-needs-your-help/">What can I do to help?</a>.</p>
    
    <p><b>You</b> can leave comments on some of those links, or email <a href="mailto:[email protected]">[email protected]</a>.
    Don't be shy.  
    This project is a hobby begun by volunteers who recognized that the accessibility of these vital documents 
    was so limited they had to do something about it themselves, since there was no evidence it was 
    going to happen by itself.</p>"""

    shortwikitable = ShortWikipediaTable(12)
    if True:
        print '<div id="wpblogincoming">'
        print '<h2>Wikipedia referring articles</h2>'
        print '<p><a href="/incoming" title="Wikipedia articles which link to documents available on this website">All incoming citations</a></p>'
        print '<p><i>(<a href="http://en.wikipedia.org/wiki/Portal:United_Nations" title="Wikipedia project: United Nations Portal">Portal:United Nations</a>)</i></p>'
        print '<h3>Recently followed citations</h3>'
        print '<ul class="cslist">'
        for shortwikirow in shortwikitable:
            # shortwikirow[0] date, shortwikirow[1] time, shortwikirow[2] count
            print '<li>%s %s (%s) <a href="%s">%s</a></td> </li>' % (
                shortwikirow[0], shortwikirow[1], shortwikirow[2],
                shortwikirow[3], shortwikirow[4])

        print '</ul>'
        print '<p><a href="/incoming" title="Wikipedia articles which link to documents available on this website">more...</a></p>'
        print '</div>'

    print '<div id="aboutfooter">'
    print txtaboutus
    print '</div>'
Beispiel #20
0
def WriteAboutPage():
    WriteGenHTMLhead("About Us")
    fin = open("aboutpage.html")
    print fin.read()
    fin.close()
Beispiel #21
0
def WriteHTML(fhtml, pdfinfo, gadice, highlightth):
    WriteGenHTMLhead(pdfinfo.desc)  # this will be the place the date gets extracted from
    print '<div style="display: none;"><img id="hrefimg" src="" alt=""></div>'
    #print '<input id="hrefimgi">%s</input>' % gadice
    print '<script type="text/javascript">document.getElementById("hrefimg").src = HrefImgReport(location.href);</script>'

    agnums = gadice and pdfinfo.GetAgnum(gadice) or ""

    resurl, reswref = GenWDocLink(pdfinfo, None, None)
    print '<div id="upperdoclinks">'
    print '</div>'

    print '<div id="meta">'
   # print gadice, agnums
    WritePrevNext(pdfinfo, gadice)
    
    print '<div id="metadoclinks">'
    print '<h3>Links for full page</h3>'
    print '<p><span class="linktabfleft">URL:</span> <input style="text" readonly value="%s"></p>' % resurl
    print '<p><span class="linktabfleft"><a href="http://en.wikipedia.org/wiki/Help:Footnotes">wiki:</a></span>' 
    print '<input style="text" readonly value="%s"></p>' % reswref
    print '</div>'

    WriteInstructions()
    print '</div>'
    print '<div id="documentwrap">'

    if False and gadice and agnums:
        for agnum in agnums.split(","):
            aglist = LoadAgendaNames(agnum)
            print '<table class="agendatable">'
            print '<caption>agenda %s</caption>' % agnum
            for agrecord in aglist:
                print '<tr><td>'
                if (agrecord.docid, agrecord.gid) != (pdfinfo.pdfc, gadice):
                    href = EncodeHref({"pagefunc":"meeting", "docid":agrecord.docid, "gadice":agrecord.gid})
                    print '%s <a href="%s">%s</a>' % (agrecord.sdate, href, agrecord.agtitle)
                else:
                    print '%s %s' % (agrecord.sdate, agrecord.agtitle)
                print '</td></tr>'
            print '</table>'

    fin = open(fhtml)
    ftext = fin.read().decode('latin-1')
    fin.close()
    councilpresidentnation = None  # gets set if we have a council-attendees

    agendanumcurrent = ""
    agendagidcurrent = ""
    for mdiv in re.finditer(rdivspl, ftext):
        dclass, gid, agendanum = mdiv.group(1), mdiv.group(2), mdiv.group(3)
        dtext = mdiv.group(4).strip()
        dtextmu = MarkupLinks(dtext, highlightth)
        if dclass == "spoken":
            if not gadice or agendagidcurrent == gadice:
                WriteSpoken(gid, dtextmu, councilpresidentnation)
        elif dclass == "subheading":
            if agendagidcurrent and (not gadice or agendagidcurrent == gadice):
                print '</div>\n\n'
            agendagidcurrent = gid
            if agendagidcurrent and (not gadice or agendagidcurrent == gadice):
                print '<div class="discussion">'
            if not gadice or agendagidcurrent == gadice:
                WriteAgenda(gid, agendanum, dtextmu, pdfinfo.pdfc)
        elif dclass == "recvote":
            if not gadice or agendagidcurrent == gadice:
                WriteVote(gid, dtextmu, pdfinfo.bSC)
        elif dclass == 'heading':
            longdate = WriteDataHeading(gid, dtext)
        elif dclass == "assembly-chairs":
            if not gadice:
                WriteAssemblyChair(gid, dtextmu)
        elif dclass == "council-attendees":
            councilpresidentnation = WriteCouncilAttendees(gid, dtext)  # value used to dereference "The President" in the Security Council
        elif dclass == "council-agenda":
            print '<div class="%s" id="%s">' % (dclass, gid)
            print dtextmu
            print '</div>'

        elif re.match("italicline", dclass):
            if not gadice or agendagidcurrent == gadice:
                WriteItalicLine(gid, dclass, dtextmu)
        else:  # all cases should have been handled
            print '<div class="%s" id="%s">' % (dclass, gid)
            print dtext, '</div>'
    if agendagidcurrent and (not gadice or agendagidcurrent == gadice):
        print '</div>'
    print '</div>'