Beispiel #1
0
 def addText(self, data_box):
     text = data_box.getText()
     frame_style = Style(name='FrameStyle', family='graphic')
     debug('Angle: %s', data_box.text_data.angle)
     angle = data_box.text_data.angle
     if angle:
         frame_style = Style(name='FrameStyleRotated', family='graphic')
     x, y, width, height = data_box.getBoundsPrintSize(
         self.current_page_resolution)
     frame = Frame(stylename=frame_style,
                   width=str(width) + 'in',
                   height=str(height) + 'in',
                   x=str(x) + 'in',
                   y=str(y) + 'in',
                   anchortype='paragraph')
     if angle:
         frame.addAttribute(
             'transform', 'rotate (%s) translate (%scm %scm)' %
             (abs(math.radians(angle)), x, y))
     self.current_page.addElement(frame)
     textbox = TextBox()
     frame.addElement(textbox)
     for line in text.split('\n'):
         textbox.addElement(
             P(stylename=self.__handleFrameStyle(data_box.text_data),
               text=line))
Beispiel #2
0
        if w > 720:
            h = float(h) * 720.0 / float(w)
            w = 720.0
        if h > 540.0:
            w = float(w) * 540.0 / float(h)
            h = 540.0

        page = Page(stylename=dpstyle, masterpagename=masterpage)
        doc.presentation.addElement(page)
        titleframe = Frame(stylename=titlestyle,
                           width="720pt",
                           height="56pt",
                           x="40pt",
                           y="10pt")
        page.addElement(titleframe)
        textbox = TextBox()
        titleframe.addElement(textbox)
        textbox.addElement(P(text=picture))

        offsetx = 400.0 - w / 2.0
        photoframe = Frame(stylename=photostyle,
                           width="%fpt" % w,
                           height="%fpt" % h,
                           x="%fpt" % offsetx,
                           y="56pt")
        page.addElement(photoframe)
        href = doc.addPicture(pict_dir + "/" + picture)
        photoframe.addElement(Image(href=href))

    doc.save(outputfile)
Beispiel #3
0
def do_job(job):
    """Do something"""
    warnings = get_warnings(job['sts'], job['ets'], job['wfo'], job['wtype'])

    mydir = "%s/%s" % (TMPDIR, job['jobid'])
    if not os.path.isdir(mydir):
        os.makedirs(mydir)
    os.chdir(mydir)

    basefn = "%s-%s-%s-%s-%s" % (job['wfo'], job['wtype'].replace(
        ",", "_"), job['radar'], job['sts'].strftime("%Y%m%d%H"),
                                 job['ets'].strftime("%Y%m%d%H"))
    outputfile = "%s.odp" % (basefn, )

    doc = OpenDocumentPresentation()

    # We must describe the dimensions of the page
    pagelayout = PageLayout(name="MyLayout")
    doc.automaticstyles.addElement(pagelayout)
    pagelayout.addElement(
        PageLayoutProperties(margin="0pt",
                             pagewidth="800pt",
                             pageheight="600pt",
                             printorientation="landscape"))

    # Style for the title frame of the page
    # We set a centered 34pt font with yellowish background
    titlestyle = Style(name="MyMaster-title2", family="presentation")
    titlestyle.addElement(ParagraphProperties(textalign="center"))
    titlestyle.addElement(TextProperties(fontsize="34pt"))
    titlestyle.addElement(GraphicProperties(fillcolor="#ffff99"))
    doc.styles.addElement(titlestyle)

    # Style for the title frame of the page
    # We set a centered 34pt font with yellowish background
    indexstyle = Style(name="MyMaster-title", family="presentation")
    indexstyle.addElement(ParagraphProperties(textalign="center"))
    indexstyle.addElement(TextProperties(fontsize="28pt"))
    indexstyle.addElement(GraphicProperties(fillcolor="#ffffff",
                                            stroke="none"))
    doc.styles.addElement(indexstyle)

    # Style for the photo frame
    photostyle = Style(name="MyMaster-photo", family="presentation")
    doc.styles.addElement(photostyle)

    # Every drawing page must have a master page assigned to it.
    masterpage = MasterPage(name="MyMaster", pagelayoutname=pagelayout)
    doc.masterstyles.addElement(masterpage)

    dpstyle = Style(name="dp1", family="drawing-page")
    # dpstyle.addElement(DrawingPageProperties(transitiontype="automatic",
    #   transitionstyle="move-from-top", duration="PT5S"))
    doc.automaticstyles.addElement(dpstyle)

    # Title slide
    page = Page(masterpagename=masterpage)
    doc.presentation.addElement(page)
    frame = Frame(stylename=indexstyle,
                  width="720pt",
                  height="500pt",
                  x="40pt",
                  y="10pt")
    page.addElement(frame)
    textbox = TextBox()
    frame.addElement(textbox)
    textbox.addElement(P(text="IEM Raccoon Report"))

    frame = Frame(stylename=indexstyle,
                  width="720pt",
                  height="500pt",
                  x="40pt",
                  y="150pt")
    page.addElement(frame)
    textbox = TextBox()
    frame.addElement(textbox)
    textbox.addElement(P(text="WFO: %s" % (job['wfo'], )))
    textbox.addElement(
        P(text=("Radar: %s Product: %s"
                "") % (job['radar'], job['nexrad_product'])))
    textbox.addElement(P(text="Phenomenas: %s" % (job['wtype'], )))
    textbox.addElement(
        P(text="Start Time: %s UTC" % (job['sts'].strftime("%d %b %Y %H"), )))
    textbox.addElement(
        P(text="End Time: %s UTC" % (job['ets'].strftime("%d %b %Y %H"), )))
    textbox.addElement(P(text=""))
    textbox.addElement(P(text="Raccoon Version: %s" % (__REV__, )))
    textbox.addElement(
        P(text="Generated on: %s" %
          (datetime.datetime.utcnow().strftime("%d %b %Y %H:%M %Z"))))
    textbox.addElement(P(text=""))
    textbox.addElement(
        P(text="Bugs/Comments/Yelling?: daryl herzmann [email protected]"))

    i = 0
    for warning in warnings:
        # Make Index page for the warning
        page = Page(masterpagename=masterpage)
        doc.presentation.addElement(page)
        titleframe = Frame(stylename=indexstyle,
                           width="700pt",
                           height="500pt",
                           x="10pt",
                           y="10pt")
        page.addElement(titleframe)
        textbox = TextBox()
        titleframe.addElement(textbox)
        textbox.addElement(
            P(text="%s.O.NEW.K%s.%s.W.%04i" %
              (job['sts'].year, job['wfo'], warning['phenomena'],
               warning['eventid'])))
        textbox.addElement(
            P(text="Issue: %s UTC" %
              (warning['issue'].strftime("%d %b %Y %H:%M"), )))
        textbox.addElement(
            P(text="Expire: %s UTC" %
              (warning['expire'].strftime("%d %b %Y %H:%M"), )))
        textbox.addElement(
            P(text="Poly Area: %.1f sq km (%.1f sq mi) [%.1f%% vs County]" %
              (warning['polyarea'], warning['polyarea'] * 0.386102,
               warning['polyarea'] / warning['countyarea'] * 100.0)))
        textbox.addElement(
            P(text="County Area: %.1f square km (%.1f square miles)" %
              (warning['countyarea'], warning['countyarea'] * 0.386102)))

        url = ("http://iem.local/GIS/radmap.php?"
               "layers[]=places&layers[]=legend&layers[]=ci&layers[]=cbw"
               "&layers[]=sbw&layers[]=uscounties&layers[]=bufferedlsr"
               "&lsrbuffer=15")
        url += "&vtec=%s.O.NEW.K%s.%s.W.%04i" % (job['sts'].year, job['wfo'],
                                                 warning['phenomena'],
                                                 warning['eventid'])

        cmd = "wget -q -O %i.png '%s'" % (i, url)
        os.system(cmd)
        photoframe = Frame(stylename=photostyle,
                           width="480pt",
                           height="360pt",
                           x="160pt",
                           y="200pt")
        page.addElement(photoframe)
        href = doc.addPicture("%i.png" % (i, ))
        photoframe.addElement(Image(href=href))
        i += 1

        times = []
        now = warning['issue']
        while now < warning['expire']:
            times.append(now)
            now += datetime.timedelta(minutes=15)
        times.append(warning['expire'] - datetime.timedelta(minutes=1))

        for now in times:
            page = Page(stylename=dpstyle, masterpagename=masterpage)
            doc.presentation.addElement(page)
            titleframe = Frame(stylename=titlestyle,
                               width="720pt",
                               height="56pt",
                               x="40pt",
                               y="10pt")
            page.addElement(titleframe)
            textbox = TextBox()
            titleframe.addElement(textbox)
            textbox.addElement(
                P(text="%s.W.%04i Time: %s UTC" %
                  (warning['phenomena'], warning['eventid'],
                   now.strftime("%d %b %Y %H%M"))))

            if job['nexrad_product'] == 'N0U':
                if now < SUPER_RES:
                    n0qn0r = 'N0V'
                else:
                    n0qn0r = 'N0U'
            else:
                if now < SUPER_RES:
                    n0qn0r = 'N0R'
                else:
                    n0qn0r = 'N0Q'

            url = "http://iem.local/GIS/radmap.php?"
            url += "layers[]=ridge&ridge_product=%s&ridge_radar=%s&" % (
                n0qn0r, job['radar'])
            url += "layers[]=sbw&layers[]=sbwh&layers[]=uscounties&"
            url += "layers[]=lsrs&ts2=%s&" % ((
                now + datetime.timedelta(minutes=15)).strftime("%Y%m%d%H%M"), )
            url += "vtec=%s.O.NEW.K%s.%s.W.%04i&ts=%s" % (
                job['sts'].year, job['wfo'], warning['phenomena'],
                warning['eventid'], now.strftime("%Y%m%d%H%M"))

            cmd = "wget -q -O %i.png '%s'" % (i, url)
            os.system(cmd)
            photoframe = Frame(stylename=photostyle,
                               width="640pt",
                               height="480pt",
                               x="80pt",
                               y="70pt")
            page.addElement(photoframe)
            href = doc.addPicture("%i.png" % (i, ))
            photoframe.addElement(Image(href=href))
            i += 1

    doc.save(outputfile)
    del doc
    cmd = "unoconv -f ppt %s" % (outputfile, )
    subprocess.call(cmd, shell=True)
    pptfn = "%s.ppt" % (basefn, )
    print("Generated %s with %s slides" % (pptfn, i))
    if os.path.isfile(pptfn):
        print('...copied to webfolder')
        shutil.copyfile(pptfn, "/mesonet/share/pickup/raccoon/%s" % (pptfn, ))
        # Cleanup
        os.chdir(TMPDIR)
        subprocess.call("rm -rf %s" % (job['jobid'], ), shell=True)
    else:
        print("Uh oh, no output file, lets kill soffice.bin")
        subprocess.call("pkill --signal 9 soffice.bin", shell=True)
        add_job(job)
Beispiel #4
0
        fname = os.path.join(pict_dir, imgfname)
        page = Page(stylename=dpstyle, masterpagename=masterpage)
        doc.presentation.addElement(page)

        note = Notes(stylename=dpstyle)
        page.addElement(note)
        noteframe = Frame(stylename=prstyle,
                          layer="layout",
                          width="16.799cm",
                          height="13.364cm",
                          x="2.1cm",
                          y="14.107cm",
                          placeholder="true",
                          classname="notes")
        note.addElement(noteframe)
        notetextbox = TextBox()
        notetextbox.addElement(P(text=notes[i] if (i in notes) else ""))
        noteframe.addElement(notetextbox)

        photoframe = Frame(stylename=photostyle,
                           width=str(w) + "pt",
                           height=str(h) + "pt",
                           x="0pt",
                           y="0pt")
        page.addElement(photoframe)
        href = doc.addPicture(fname)
        photoframe.addElement(Image(href=href))

        i += 1

    doc.save(args["<output>"])