Пример #1
0
    def start(self, db_session, logger, process_name):
        try:
            smtp_server = db_session.query(SMTPServer).first()
            if smtp_server is None:
                logger.error('mailer: SMTP Server has not been specified')
                return

            email_job = db_session.query(EmailJob).filter(
                EmailJob.id == self.job_id).first()
            if email_job is None:
                logger.error('Unable to retrieve email job: %s' % self.job_id)
                return

            sendmail(logger=logger,
                     server=smtp_server.server,
                     server_port=smtp_server.server_port,
                     sender=smtp_server.sender,
                     recipient=email_job.recipients,
                     message=email_job.message,
                     use_authentication=smtp_server.use_authentication,
                     username=smtp_server.username,
                     password=smtp_server.password,
                     secure_connection=smtp_server.secure_connection)

            db_session.delete(email_job)
            db_session.commit()

        finally:
            db_session.close()
Пример #2
0
    def start(self, db_session, logger, process_name):
        try:
            smtp_server = db_session.query(SMTPServer).first()
            if smtp_server is None:
                logger.error('mailer: SMTP Server has not been specified')
                return

            email_job = db_session.query(EmailJob).filter(EmailJob.id == self.job_id).first()
            if email_job is None:
                logger.error('Unable to retrieve email job: %s' % self.job_id)
                return

            sendmail(
                logger=logger,
                server=smtp_server.server,
                server_port=smtp_server.server_port,
                sender=smtp_server.sender,
                recipient=email_job.recipients,
                message=email_job.message,
                use_authentication=smtp_server.use_authentication,
                username=smtp_server.username,
                password=smtp_server.password,
                secure_connection=smtp_server.secure_connection)

            db_session.delete(email_job)
            db_session.commit()

        finally:
            db_session.close()
Пример #3
0
def findfoc(images, doplot=False):

    focus = []
    fwhm = []
    flux = []
    for im in images:
        head = pyfits.getheader(im)
        foc = head['DFOCRAW']
        focus.append(foc)
        w, f = tharfwhm(im, silent=True)
        fwhm.append(w)
        flux.append(f)

    p = np.polyfit(focus, fwhm, 4)
    xmod = np.linspace(min(focus), max(focus), 200)
    yfit = np.polyval(p, xmod)

    bestfoc = xmod[np.argmin(yfit)]
    bestflux = flux[np.argmin(fwhm)]

    bestfoc += ucscoff

    offset = startfoc - bestfoc

    pl.plot(focus, fwhm, 'ko', markersize=10)
    pl.plot(xmod, yfit, 'b-')
    pl.ylabel('FWHM [px]')
    pl.xlabel('DEWARFOCRAW')
    pl.legend([
        'Best focus (w/ offset): %4.3f px\n@ %d' %
        (np.min(yfit), int(round(bestfoc)))
    ],
              numpoints=1,
              loc='best')
    pl.savefig('dewar_focus.png')
    if doplot: pl.show()

    apflog("Found best focus at DEWARFOCRAW=%d" % int(round(bestfoc)))
    apflog("FHWM = %4.3f" % np.min(yfit))
    apflog("Max peak counts = %4.0f" % bestflux)
    apflog("Offset from previous value = %+4.0f" % offset)

    import mailer
    msgbody = """Focused the Levy spectograph at %s Pacific local time.
Found best focus (including offset) at DEWARFOCRAW=%d
Change from previous focus = %4.0f
FHWM = %4.3f pixels
Max peak counts = %4.0f ADU\n
""" % (datetime.strftime(datetime.now(), format="%Y-%m-%d %H:%M"),
       int(round(bestfoc)), int(round(offset)), np.min(yfit), bestflux)
    mailer.sendmail(msgbody,
                    'Levy Focus',
                    toaddr=mailer.contacts.ucbgroup,
                    attachments=['dewar_focus.png'])

    return int(round(bestfoc))
Пример #4
0
def findfoc(images, doplot=False):


    focus = []
    fwhm = []
    flux = []
    for im in images:
        head = pyfits.getheader(im)
        foc = head['DFOCRAW']
        focus.append(foc)
        w,f = tharfwhm(im, silent=True)
        fwhm.append(w)
        flux.append(f)

    p = np.polyfit(focus, fwhm, 4)
    xmod = np.linspace(min(focus), max(focus), 200)
    yfit = np.polyval(p, xmod)

    bestfoc = xmod[np.argmin(yfit)]
    bestflux = flux[np.argmin(fwhm)]

    bestfoc += ucscoff
    
    offset = startfoc - bestfoc
    
    pl.plot(focus,fwhm, 'ko', markersize=10)
    pl.plot(xmod, yfit, 'b-')
    pl.ylabel('FWHM [px]')
    pl.xlabel('DEWARFOCRAW')
    pl.legend(['Best focus (w/ offset): %4.3f px\n@ %d' % (np.min(yfit),int(round(bestfoc)))], numpoints=1, loc='best')
    pl.savefig('dewar_focus.png')
    if doplot: pl.show()

    apflog("Found best focus at DEWARFOCRAW=%d" % int(round(bestfoc)))
    apflog("FHWM = %4.3f" % np.min(yfit))
    apflog("Max peak counts = %4.0f" % bestflux)
    apflog("Offset from previous value = %+4.0f" % offset)

    import mailer
    msgbody = """Focused the Levy spectograph at %s Pacific local time.
Found best focus (including offset) at DEWARFOCRAW=%d
Change from previous focus = %4.0f
FHWM = %4.3f pixels
Max peak counts = %4.0f ADU\n
""" % (datetime.strftime(datetime.now(), format="%Y-%m-%d %H:%M"), int(round(bestfoc)), int(round(offset)), np.min(yfit), bestflux)
    mailer.sendmail(msgbody, 'Levy Focus', toaddr=mailer.contacts.ucbgroup, attachments=['dewar_focus.png'])

    return int(round(bestfoc))
Пример #5
0
#delta range checks
delta = current_price - old_price

#print "Current " + str(current_price)
#print "Old " + str(old_price)

contents = ""

if delta > 10:
    contents += "BTC rose by 10 USD since last tick!";
elif delta > 25:
    contents += "BTC rose by 25 USD since last tick!";
elif delta > 50:
    contents += "BTC rose by 50 USD since last tick! Sell!";

if delta < -10:
    contents += "BTC fell by 10 USD since last tick!";
elif delta < -25:
    contents += "BTC fell by 25 USD since last tick!";
elif delta < -50:
    contents += "BTC fell by 50 USD since last tick! Buy!";

#notify
if contents:
    import mailer
    mailer.sendmail(contents)
    
    
    

Пример #6
0
    'https://www.leboncoin.fr/locations/1003044602.htm?ca=22_s',
    'https://www.leboncoin.fr/locations/1003550639.htm?ca=22_s',
    'https://www.leboncoin.fr/locations/1004306753.htm?ca=22_s',
    'http://www.seloger.com/annonces/locations/appartement/cagnes-sur-mer-06/le-cros-de-cagnes/98672799.htm?ci=60018,60027,60152,60161&idtt=1&idtypebien=1,2&org=advanced_search&pxmax=800&surfacemin=35',
    'http://www.seloger.com/annonces/locations/appartement/cagnes-sur-mer-06/le-cros-de-cagnes/98672799.htm?ci=60018,60027,60152,60161&idtt=1&idtypebien=1,2&org=advanced_search&pxmax=800&surfacemin=30'
    'http://www.seloger.com/annonces/locations/appartement/cagnes-sur-mer-06/le-cros-de-cagnes/98672799.htm?ci=60018,60027,60152,60161&idtt=1&idtypebien=1,2&org=advanced_search&pxmax=800&surfacemin=40',
    'https://www.leboncoin.fr/locations/1001732980.htm?ca=22_s',

]

res=[]
for key, urlname in dicts.items():
    result=globals()[key].parse(urlname)
    if result is None:
        msg='Problem with parser: '+d
        mailer.sendmail(msg)
        sys.exit(msg)
    res += result



message=''
for r in res:
    r['price per meter'] = float(r['price'])/float(r['surface'])

res.sort( key=lambda x: x['price per meter'])

def formatMsg(d, hyperlink=False):
    s="<td>"
    if hyperlink: s+= '<a href="'+ r['url'] + '">'
    s+='<font size="5">' + d.encode('ascii','ignore') + '</font>'