Beispiel #1
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 #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 WriteCollapsedAgendaList(aglist, bDiced):
    aggroupm = {}
    for agrecord in aglist:
        aggroupm.setdefault(agrecord.agnum, []).append(agrecord)
    aggtitles = [(ag[0].aggrouptitle, ag[0].agnum) for ag in aggroupm.values()]
    aggtitles.sort()

    print '<ul class="aglistgroup">'

    print '<li><a href="%s" class="aggroup">Condolences</a></li>' % EncodeHref(
        {
            "pagefunc": "agendanum",
            "agendanum": "condolence"
        })  # special case

    if bDiced:
        for aggt, agnum in aggtitles:
            aggl = {}
            for agrecord in aggroupm[agnum]:
                aggl.setdefault((agrecord.sdate, agrecord.docid), []).append(
                    (agrecord.gid, agrecord))
            agglks = aggl.keys()
            agglks.sort()
            agglk = min(agglks)
            agrecord = min(aggl[agglk])[1]
            href = EncodeHref({
                "pagefunc": "meeting",
                "docid": agrecord.docid,
                "gadice": agrecord.gid
            })
            print '<li>%d %s <a href="%s" class="aggroup">%s</a></li>' % (
                len(agglks), agrecord.sdate, href, aggt)
        print '</ul>'
        return

    for aggt, agnum in aggtitles:
        print '<li>',
        print '<a href="%s" class="aggroup">%s</a>' % (EncodeHref(
            {
                "pagefunc": "agendanum",
                "agendanum": agnum
            }), aggt)
        print '<ul>',
        aggl = {}
        for agrecord in aggroupm[agnum]:
            aggl.setdefault((agrecord.sdate, agrecord.docid), []).append(
                (agrecord.gid, agrecord))
        agglks = aggl.keys()
        agglks.sort()
        for agglk in agglks:
            agrecord = min(aggl[agglk])[1]
            print '<a href="%s">%s</a>' % (agrecord.GetHref(), agrecord.sdate),
        print '</ul>'
        print '</li>'
Beispiel #4
0
def WriteAgenda(gid, agnum, dtext, docid):
    print '<div class="agendaitem" id="%s">' % gid
    if agnum:
        lkothdisc = '<a href="%s">More on this topic</a>' % EncodeHref({"pagefunc":"agendanum", "agendanum":agnum})
        flippedhcode = '%s_%s' % (docid, gid)
        lkflipagenda = '<a href="%s#%s">Flip</a>' % (EncodeHref({"pagefunc":"agendanumexpanded", "agendanum":agnum}), flippedhcode)
        #print '<div class="otheraglink">%s %s</div>' % (lkothdisc, lkflipagenda)
        print '<div class="otheraglink">%s</div>' % lkothdisc
    
    print dtext
    print '</div>'
Beispiel #5
0
def GetSessionLink(nsess, bdocuments):
    if nsess < 49:
        bdocuments = True
    if bdocuments:
        return '<a href="%s">Session %d</a>' % (EncodeHref({
            "pagefunc": "gasession",
            "gasession": nsess
        }), nsess)
    return '<a href="%s">Session %d documents</a>' % (EncodeHref(
        {
            "pagefunc": "gadocuments",
            "gasession": nsess
        }), nsess)
Beispiel #6
0
def WebcastLink(body, wcdate):
    if body == "securitycouncil" and wcdate >= "2003-01-09":
        return EncodeHref({
            "pagefunc": "webcastindex",
            "body": "securitycouncil",
            "date": wcdate
        })
    if body == "generalassembly" and wcdate >= "2003-07-03":
        return EncodeHref({
            "pagefunc": "webcastindex",
            "body": "generalassembly",
            "date": wcdate
        })
    return ""
Beispiel #7
0
def WriteCouncilAttendees(gid, dtext):
    pcatt = re.findall('<p[^>]*>(.*?)</p>', dtext)
    assert len(pcatt) == 15, dtext
    rows = [ [ "President:", [ ] ], [ "Members:", [ ] ] ]
    res = None
    for catt in pcatt:
        name, nation, place = None, None, None
        for cl, val in re.findall('<span class="([^"]*)">([^<]*)</span>', catt):
            if cl == "nation":
                nation = val
            elif cl == "place":
                place = val
            elif cl == "name" and not name: # sometimes we get two names here
                name = val
        assert name and nation and place, dtext
        
        if place == "president":
            res = nation
            rows[0][1].append((name, nation))
        else:
            rows[1][1].append((name, nation))
    assert res, dtext

    # line-wrap the rows (in future we'll have speaking and non-speaking rows)
    while len(rows[-1][1]) > 3:
        rows.append([ "", rows[-1][1][3:] ])
        del rows[-2][1][3:]

    print '<div class="council-attendees" id="%s">' % gid
    print '<table>'
    for rowlab, rowcont in rows:
        print '<tr>'
        print '<th>%s</th>' % rowlab
        for name, nation in rowcont:
            hrefflag = EncodeHref({"pagefunc":"flagpng", "width":100, "flagnation":nation})
            print '<td><img class="smallflag_sca" src="%s"></td>' % hrefflag,
            hrefname = EncodeHref({"pagefunc":"nationperson", "nation":nation, "person":name})
            print '<td><a class="name" href="%s">%s</a>' % (hrefname, name),
            print '<br>'
            hrefnation = EncodeHref({"pagefunc":"nation", "nation":nation})
            print '<a class="nation" href="%s">%s</a></td>' % (hrefnation, nation)
        if rowlab == "President:":
            print '<td></td>'
            print '<td colspan="3">(The Presidency changes each month to the next member in alphabetical order)</td>'
        print '</tr>'
    print '</table>'
    print '</div>'
    return res
Beispiel #8
0
def WriteAmbassadorList(nation, nationdata):
    # group by ambassadors
    ambmap = {}
    for mp in nationdata:
        if mp["lntype"] == "ambassador":
            ambmap.setdefault(mp["name"], set()).add(
                (mp["sdate"], mp["docid"]))

    amblist = []
    for name, sdatedocs in ambmap.iteritems():
        sk = re.search("(\S+)$", name).group(1)  # last name
        amblist.append((sk, name, sdatedocs))

    amblist.sort()

    print '<h3>Ambassadors</h3>'
    print '<p>People who have spoken in the General Assembly or Security Council in the name of %s.  Sometimes ministers or heads of state take the place of the official ambassador of the day.</p>' % nation

    print '<table class="nationambassadortable" style="background-color:lightgray;">'
    print '<tr><th>Name</th><th>Speeches</th><th>First</th><th>Last</th></tr>'
    for ambl in amblist:
        href = EncodeHref({
            "pagefunc": "nationperson",
            "nation": nation,
            "person": ambl[1]
        })
        sdatedocs = ambl[2]
        ndocs = len(sdatedocs)
        firstdate = min(sdatedocs)[0]
        lastdate = max(sdatedocs)[0]
        print '<tr><td><a href="%s">%s</a></td>  <td>%d</td> <td>%s</td> <td>%s</td></tr>' % (
            href, ambl[1], ndocs, LongDate(firstdate), LongDate(lastdate))
    print '</table>'
Beispiel #9
0
 def GetHref(self, highlight=None, gid=None):
     params = {"pagefunc": "scmeeting", "scmeeting": self.scmeeting}
     if highlight:
         params['highlightdoclink'] = highlight
     if gid:
         params['gid'] = gid
     return EncodeHref(params)
Beispiel #10
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 #11
0
def WriteAgendaFlipped(gid, agnum, dtext, docid):
    print '<div class="subheading" id="%s_%s">' % (docid, gid)
    if agnum:
        lkflap = '<a href="%s">Flap</a>' % (EncodeHref({"pagefunc":"meeting", "docid":docid, "gid":gid}))
        print '<div class="otheraglink">%s</div>' % lkflap

    print dtext
    print '</div>'
Beispiel #12
0
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>'
Beispiel #13
0
 def GetHref(self, highlight=None, gid=None):
     params = {
         "pagefunc": "gameeting",
         "gasession": self.nsess,
         "gameeting": self.nmeeting,
         "gid": self.gid
     }
     if highlight:
         params['highlightdoclink'] = highlight
     if gid:
         params['gid'] = gid
         #params['gadice'] = gid  # makes the link do the section ; only works if gid is for the header!
     return EncodeHref(params)
Beispiel #14
0
def WritePrevNext(pdfinfo, gadice):
    if not pdfinfo.prevmeetingdetails and not pdfinfo.nextmeetingdetails:
        return
    #print '<div class="prevnexmeeting">'
    #thislink = EncodeHref({"pagefunc":"meeting", "docid":pdfinfo.pdfc})
    #print '<p><a href="%s">This meeting held on %s from %s to %s</a></p>' % (pdfinfo.sdate, pdfinfo.time, pdfinfo.rosetime)
    print '<table>'
    print '<tr class="meeting-date"><th>Date</th><td><b>%s</b></td></tr>' % LongDate(pdfinfo.sdate)
    if not gadice:
        print '<tr class="meeting-time"><th>Started</th><td>%s</td></tr>' % pdfinfo.time
        print '<tr class="meeting-rosetime"><th>Ended</th><td>%s</td></tr>' % pdfinfo.rosetime
    print '</table>'

    
    if not (pdfinfo.prevmeetingdetails or pdfinfo.nextmeetingdetails or gadice):
        return
    
    print '<ul>'
    if gadice:
        currlink = EncodeHref({"pagefunc":"meeting", "docid":pdfinfo.pdfc, "gid":gadice})
        print '<li><a href="%s" title="Full meeting"><b>Full meeting</b></a></li>' % currlink
    if not gadice and pdfinfo.prevmeetingdetails:
        prevlink = EncodeHref({"pagefunc":"meeting", "docid":pdfinfo.prevmeetingdetails[0]})
        print '<li><a href="%s" title="Previous meeting: finished %s %s">Previous meeting</a></li>' % (prevlink, pdfinfo.prevmeetingdetails[1], pdfinfo.prevmeetingdetails[2])
    if not gadice and pdfinfo.nextmeetingdetails:
        nextlink = EncodeHref({"pagefunc":"meeting", "docid":pdfinfo.nextmeetingdetails[0]})
        print '<li><a href="%s" title="Next meeting: started %s %s">Next meeting</a></li>' % (nextlink, pdfinfo.nextmeetingdetails[1], pdfinfo.nextmeetingdetails[2])
    webcastlink = WebcastLink(pdfinfo.bSC and "securitycouncil" or "generalassembly", pdfinfo.sdate)
    if webcastlink:
        print '<li><a href="%s" title="Goto entry in list of webcasts">Webcast Video</a></li>' % (webcastlink)
    
    print '<li>&nbsp;</li>'
    if pdfinfo.bGA:
        print '<li><a href="%s">Entire session</a></li>' % (EncodeHref({"pagefunc":"gasession", "gasession":pdfinfo.nsess}))
    if pdfinfo.bSC:
        print '<li><a href="/securitycouncil">All meetings</a></li>'

    print '</ul>'
Beispiel #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
0
def maintrunk(pathpart):

    form = cgi.FieldStorage()
    pathpartstr = (pathpart or '').strip('/')
    pathparts = [s for s in pathpartstr.split('/') if s]
    referrer = os.getenv("HTTP_REFERER") or ''
    ipaddress = os.getenv("REMOTE_ADDR") or ''
    useragent = os.getenv("HTTP_USER_AGENT") or ''

    if False:  # on strike condition
        print "Content-type: text/html\n"
        print "<h1>UNDEMOCRACY.COM is on strike</h1>"
        print '<h2>For the official source of documents, go <a href="http://www.un.org/documents/">here</a></h2>'
        print '<h2>For the scraped and parsed data, go <a href="http://seagrass.goatchurch.org.uk/~undemocracy/undata/">here</a></h2>'
        print '<h2>For the explanation, go <a href="http://www.freesteel.co.uk/wpblog/2007/11/undemocracycom-goes-on-strike/">here</a></h2>'
        print '<p>Thank you.  (2007-11-20)</p>'
        sys.exit()

    hmap = DecodeHref(pathparts, form)

    # used to spot what anchor tag the user was sent to
    if hmap["pagefunc"] == "imghrefrep":
        LogIncomingDoc(hmap["imghrefrep"], "imghrefrep", referrer, ipaddress,
                       useragent)
        sys.exit(0)
    elif hmap["pagefunc"] == "pdfpreviewjpg":
        WritePdfPreviewJpg(hmap["docid"])
        sys.exit(0)

    # Redirect if the URL isn't in its canonical form
    remadeurl = EncodeHref(hmap)
    #    print "Content-type: text/html\n"; print hmap; print "ello"; print remadeurl; print pathpartstr; sys.exit()
    if remadeurl != "/" + pathpartstr and not re.match('^/rubbish/',
                                                       remadeurl):
        if re.search("meeting_",
                     pathpartstr) and not re.match("meeting_", remadeurl):
            print "Status: 302 Moved Temporarily"
        else:
            print "Status: 301 Moved Permanently"
        print "Location: %s\n" % remadeurl
        return

    pagefunc = hmap["pagefunc"]
    SetBodyID(hmap["pagefunc"])

    if pagefunc == "front":
        LogIncomingDB("front", "", referrer, ipaddress, useragent, remadeurl)
        WriteFrontPage()
    elif pagefunc == "about":  # no longer exists
        print "Content-type: text/html\n"
        #WriteAboutPage()
        recsc = LoadSecRecords("recent")[:12]
        recag = LoadAgendaNames("recent")[:8]
        wikirefs = ShortWikipediaTableM(12)
        searchlist = GetUnlogList("search", 100)
        x = loader.render_to_string(
            'frontpage.html', {
                'searchlist': searchlist,
                'trail': 'locise',
                'secrecords': recsc,
                'garecords': recag,
                'wikirefs': wikirefs,
                'settings': settings
            })
        print x
        #print "<h1>ggggggg</h1>"
        return
    elif pagefunc == "incoming":
        LogIncomingDB(pagefunc, "", referrer, ipaddress, useragent, remadeurl)
        WriteWikiPage()
    elif pagefunc == "search":
        LogIncomingDB(pagefunc, hmap["searchvalue"], referrer, ipaddress,
                      useragent, remadeurl)
        WriteIndexSearch(hmap["searchvalue"])
    elif pagefunc == "nationlist":
        LogIncomingDB(pagefunc, "", referrer, ipaddress, useragent, remadeurl)
        WriteAllNations()
    elif pagefunc == "special":
        LogIncomingDB(pagefunc, "", referrer, ipaddress, useragent, remadeurl)
        WriteRochesterPage()

    elif pagefunc == "gasession":
        LogIncomingDB(pagefunc, "", referrer, ipaddress, useragent, remadeurl)
        WriteIndexStuff(hmap["gasession"])
    elif pagefunc == "gatopics":
        LogIncomingDB(pagefunc, "", referrer, ipaddress, useragent, remadeurl)
        WriteIndexStuffGA()
    elif pagefunc == "agendanum":
        LogIncomingDB(pagefunc, hmap["agendanum"], referrer, ipaddress,
                      useragent, remadeurl)
        WriteIndexStuffAgnum(hmap["agendanum"])
    elif pagefunc == "gadocuments":
        LogIncomingDB(pagefunc, hmap["docyearfile"], referrer, ipaddress,
                      useragent, remadeurl)
        WriteIndexStuffDocumentsYear(hmap["docyearfile"])

    elif pagefunc == "gameeting":
        LogIncomingDB(hmap["docid"], hmap["gadice"] or "0", referrer,
                      ipaddress, useragent, remadeurl)
        WriteHTML(hmap["htmlfile"], hmap["pdfinfo"], hmap["gadice"],
                  hmap["highlightdoclink"])
    elif pagefunc == "agendanumexpanded":
        LogIncomingDB(pagefunc, hmap["agendanum"], referrer, ipaddress,
                      useragent, remadeurl)
        aglist = LoadAgendaNames(hmap["agendanum"])
        WriteHTMLagnum(hmap["agendanum"], aglist)
    elif pagefunc == "scmeeting":
        LogIncomingDB(hmap["docid"], "0", referrer, ipaddress, useragent,
                      remadeurl)
        WriteHTML(hmap["htmlfile"], hmap["pdfinfo"], "",
                  hmap["highlightdoclink"])

    elif pagefunc == "sctopics":
        LogIncomingDB(pagefunc, "", referrer, ipaddress, useragent, remadeurl)
        WriteIndexStuffSec()
    elif pagefunc == "scyear":
        LogIncomingDB(pagefunc, hmap["scyear"], referrer, ipaddress, useragent,
                      remadeurl)
        WriteIndexStuffSecYear(hmap["scyear"])
    elif pagefunc == "scyearearly":
        LogIncomingDB(pagefunc, "early", referrer, ipaddress, useragent,
                      remadeurl)
        WriteDocumentListingEarly("securitycouncil")
    elif pagefunc == "scdocuments":
        LogIncomingDB(pagefunc, hmap["docyearfile"], referrer, ipaddress,
                      useragent, remadeurl)
        WriteIndexStuffDocumentsYear(hmap["docyearfile"])
    elif pagefunc == "pdf":
        LogIncomingDB(pagefunc, "pdf", referrer, ipaddress, useragent,
                      remadeurl)
        WritePDF(hmap["pdffile"])
    elif pagefunc == "document":
        rfr = LogIncomingDB(hmap["docid"], "0", referrer, ipaddress, useragent,
                            remadeurl)
        WritePDFpreview(hmap["docid"], hmap["pdfinfo"], rfr,
                        hmap.get("scrapedoc"))
    elif pagefunc == "documentlist":
        LogIncomingDB(pagefunc, "", referrer, ipaddress, useragent, remadeurl)
        WriteDocumentListing(hmap["body"])

    elif pagefunc == "pdfpage":  # this is the html doc containing the page
        LogIncomingDB(hmap["docid"], "page_%s" % hmap["page"], referrer,
                      ipaddress, useragent, remadeurl)
        WritePDFpreviewpage(hmap["pdfinfo"], hmap["page"],
                            hmap["highlightrects"], hmap["highlightedit"])
        #LogIncomingDoc(hmap["docid"], "page_" + str(hmap["page"]), referrer, ipaddress, useragent)

    elif pagefunc == "nation":
        LogIncomingDB(pagefunc, hmap["nation"], referrer, ipaddress, useragent,
                      remadeurl)
        WriteIndexStuffNation(hmap["nation"], "")
    elif pagefunc == "nationperson":
        LogIncomingDB(pagefunc, "%s/%s" % (hmap["nation"], hmap["person"]),
                      referrer, ipaddress, useragent, remadeurl)
        WriteIndexStuffNation(hmap["nation"], hmap["person"])

    elif hmap[
            "pagefunc"] == "pagepng":  # this is the actual image bitmap of the page
        #print 'Content-type: text/html\n\n<h1>%s</h1>' % hmap["pngfile"]
        #sys.exit(0)
        WritePNGpage(hmap["pdffile"], hmap["page"], hmap["width"],
                     hmap["pngfile"], hmap["highlightrects"])
        sys.exit(0)

    elif hmap["pagefunc"] == "webcastindex":
        WriteWebcastIndexPage(hmap["body"], hmap["date"])

    else:
        WriteFrontPageError(pathpartstr, hmap)

    WriteGenHTMLfoot()
Beispiel #22
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 #23
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 #24
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 #25
0
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>'
Beispiel #26
0
def WriteSpoken(gid, dtext, councilpresidentnation):
    print '<div class="speech" id="%s">' % gid
    respek = '<h3 class="speaker"> <span class="name">([^<]*)</span>(?: <span class="(nation|non-nation)">([^<]*)</span>)?(?: <span class="language">([^<]*)</span>)? </h3>'
    mspek = re.search(respek, dtext)
    if not mspek:
        dtext = re.sub('<span class="search-highlight">(.*?)</span>', '\\1', dtext)
        mspek = re.search(respek, dtext)
    assert mspek, dtext[:300]
    name, nationtype, nation, language = mspek.group(1), mspek.group(2), mspek.group(3), mspek.group(4)
    print '<cite>',


    # build up the components of the speaker
    nationlink = nation and EncodeHref({"pagefunc":"nation", "nation":nation})
    if nationlink:
        nationblock = '<a class="nation" href="%s">(%s)</a>' % (nationlink, nation)
    elif nation:
        nationblock = '<span class="nation">(%s)</span>' % nation
    else:
        nationblock = ""

    # the country links still go from the flag
    flagnation = nation
    if councilpresidentnation:
        if name == "The President":
            nation = councilpresidentnation
            flagnation = nation
    if not flagnation:
        if re.match("The(?: Deputy)? Secretary-General", name):
            flagnation = "United Nations"
            nation = name
        elif not councilpresidentnation and re.match("The(?: Acting)? President", name):
            flagnation = "%s of the General Assembly" % name
    if not flagnation:
        flagnation = "Unknown"
    if re.search("for General Assembly", flagnation):
        flagnation = "Secretariat"
    
    flagimg = EncodeHref({"pagefunc":"flagpng", "width":100, "flagnation":flagnation})
    flaglink = nation and EncodeHref({"pagefunc":"nation", "nation":nation})

    if nation and name and not re.search("President", name):
        personlink = EncodeHref({"pagefunc":"nationperson", "nation":nation, "person":name})
    else:
        personlink = ""

    if flaglink:
        print '<a href="%s">' % flaglink,
    print '<img class="smallflag" src="%s">' % flagimg,
    if flaglink:
        print '</a>',

    if personlink:
        print '<a class="name" href="%s">%s</a>' % (personlink, name),
    else:
        print '<span class="name">%s</span>' % name

    print nationblock
    print '</cite>'

    print dtext[mspek.end(0):]

    print '</div>'
Beispiel #27
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>'