def main():
    for phone, url in test.items():
        page = requests.get(url)
        if (page.ok != True):
            sendErrorReport()
            break

        tree = html.fromstring(page.content)
        notifyMeEle = tree.xpath(
            "/html/body/div[1]/div/div[3]/div[2]/div[1]/div[1]/div[2]/div/button"
        )
        if (len(notifyMeEle) != 0):
            value = str(notifyMeEle[0].text).lower()
            if value != "notify me":
                continue
        else:
            buyNowEle = tree.xpath(
                "/html/body/div[1]/div/div[3]/div[2]/div[1]/div[1]/div[2]/div/ul/li[2]/form/button"
            )
            if (len(buyNowEle) != 0):
                value = str(buyNowEle[0].text).lower()
                if "buy now" in value:
                    sendMail()
            else:
                sendErrorReport()
                continue
示例#2
0
                    else:
                            # HTML body
                            today = datetime.date.today()

                            # Add CVE to known CVE List, increase CVE tally
                            known_cve_list.append(cve.strip())
                            new_cve_count += 1

                            html = ('<html> <head> <style> table, th, td {{ border: 1px solid black; }} </style> </head>'
                                    ' <body> <table style="width:100%"> <tr> <th style="width:10%">CVE</th>'
                                    ' <th style="width:20%">Title</th> <th style="width:70%">Description</th><th>Matched word</th></tr> <tr> '
                                    '<td><a href="{0}">{1}</a></td> <td>{2}</td> <td>{3}</td> <td><b>{4}</td> </tr> </table> <br></body> '
                                    '</html><br> Generated on {5}'.format(url, cve, title, description, white_word, today))

                            # Custom written mailer, google how to mail in email markup
                            mailer.sendMail(['to_address@domain'], 'from_address@domain' ,
                                            'NIST Vulnerability detected: {0}: {1}'.format(cve, title), html)

                else:
                    wrekt += '{0}, {1}, {2}, {3}, {4} <br>'.format(((time.time() - cve_epoch) / 60), time.time(), cve_epoch,
                                                               title, cve)

# If no new CVE's are discovered, send out debug email. To be removed later
if new_cve_count == 0:
    mailer.sendMail(['to_addr@domain'], 'from_addr@domain' , 'No NIST Vulnerability detected', wrekt)

# Write out known affected CVE's for historical purposes
with open('/root/dooley/nist/cve_history.txt','w+') as cve_history:
    for known_cve in known_cve_list:
        cve_history.write('{0}\n'.format(known_cve))
示例#3
0
def send_mail():
    info = request.get_json(force=True)
    info['receivers'] = users[info['name']]
    sendMail(config, info['receivers'], info['subject'], info['text'])
    return 'ok'
 def sendEmail(self, payload):
     if(self.email != ""):
         sendMail(self.email, payload)
     else:
         print("No email address for UID " + str(self.ident))
示例#5
0
文件: runner.py 项目: juanurquijo/SF
def main(source, dest, runtype):
    # runtype 1 - the one run at midnight
    # runtype 2 - the final day's run
    global logger
    logger = utils.createLogger("runner")
    if not os.path.isdir(source):
        print "invalid directory "+source
        sys.exit(1)
        
    if not prepareDestDir(dest):
        sys.exit(1)
    import datetime
    today = datetime.datetime(2012, 12, 21).now()
    pfile = os.path.join(source, "prev_%s.csv"%runtype)    
    nfile = os.path.join(source, "now_%s.csv"%runtype)        
    backup(source, today, runtype)
    # abort if there is no prev file
    if not os.path.isfile(pfile):
        logger.error("There is no previous file "+pfile)
        sendMail(None, "**** Stormpost SF Error", "There is no previous file "+pfile)
        
        sys.exit(1)
    
    import p2
    bx = utils.getSFSiteCred()
    p2.main(int(runtype), nfile, bx[0], bx[1], bx[2])
    if not os.path.isfile(nfile):
        restorePrev(source, runtype)
        return
        
        
    import diff
    adds, deletes = diff.diff(nfile, pfile)
    print adds, deletes
    tosend = []

    jlt_to_old = {
        "JLT Pharma":"Pharma Global",
        "JLT Constr":"Constr Global",
        "JLT Insur":"Insur Global",
        "JLT Bank":"Bank Global",
        "JLT Telecom":"Telecom Global",
        "JLT Asset & Wealth":"Asset & Wealth Global",
        "JLT Lawyers":"Lawyers Global",
        "JLT Media":"Media Global"}
    global_to_new = {
        "Pharma Global":"Pharma Global Advisen",
        "Constr Global":"Constr Global Advisen",
        "Insur Global":"Insur Global Advisen",
        "Bank Global":"Bank Global Advisen",
        "Telecom Global":"Telecom Global Advisen",
        "Asset & Wealth Global":"Asset & Wealth Global Advisen",
        "Lawyers Global":"Lawyers Global Advisen",
        "Media Global":"Media Global Advisen"}

    
    def createSPFiles(which, decor):
        import string
        for w in which.keys():
            if w in jlt_to_old.keys(): k = jlt_to_old[w]
            else:
                if w in global_to_new: k = global_to_new[w]
                else:
                    k = w
            if decor == "":
                fn = k.replace(" ", "_").replace("/", "_") + "_%04d_%02d_%02d.txt"%(today.year, today.month, today.day)
            else:
                fn = k.replace(" ", "_").replace("/", "_") + "_%s_%04d_%02d_%02d.txt"%(decor,today.year, today.month, today.day)            
            fn = os.path.join(dest, fn)
            tosend.append(fn)
            op = open(fn, "w").write(string.join(which[w], "\n"))
    
    createSPFiles(adds, "")
    createSPFiles(deletes, "remove")
    
    logger.debug("Files to send "+str(tosend))
    sys.exit(0)
示例#6
0
def main(sf_csv_file, sp_email_map, maxupds, sendto):
    logger = utils.createLogger("spsfsync.py")



    b = utils.getSFSiteCred()
    workdir = os.path.join(tempdir, utils.temp_name("sfupdworkdir"))
    os.mkdir(workdir)
    
    rc,upds, splits, manifest_map  = \
        __create_sf_updates(sf_csv_file, workdir, sp_email_map, 
        maxupds)
    if rc != 0 or upds == 0:
        if rc != 0:
            logger.error("sp_get_status returned with error %d"%rc)
        else:
            logger.info("There were no updates")
        return rc
    
    logger.debug("THERE ARE %d updates and %d splits"%(upds, len(splits)))
    
    # loop splits here
    # then cat the logfile
    cgood = 0
    cbad = 0

    goodfile = os.path.join(tempdir, utils.temp_name("goodups.txt"))
    badfile = os.path.join(tempdir, utils.temp_name("badupds.txt"))
    logger.debug("GOODFILE "+goodfile)
    
    good = open(goodfile, "w")
    bad = open(badfile, "w")

    updlogfile = os.path.join(tempdir, utils.temp_name("spsynclogfile.csv")) # yes reuse

    ktest = 0
    for spl in splits:
        rc = sfupdspstatus.main(b[0], b[1], b[2], spl, updlogfile)

        csv_spl = csv.reader(open(spl))
        up_file = open(updlogfile)
        csv_log = csv.reader(up_file)

        first = True
        for row_upd in csv_spl:
            row_log = csv_log.next()
            if first:
                first = False
                continue
            lid = row_upd[0]
            try:
                (email, fromv) = manifest_map[lid]
                cto = row_upd[1]

                success = row_log[1].lower()
                error = row_log[3]
                if success == "true":
                    cgood = cgood + 1
                    good.write(email+" changed from "+fromv+" to "+cto+"\n")
                    good.flush()
                else:
                    cbad = cbad + 1
                    bad.write(email+" failed to update from "+fromv+" to "+cto+" "+error+"\n")
                    bad.flush()

            except KeyError:
                logger.error("ID not found "+lid)
        up_file.close()
        ktest = ktest + 1
#        if ktest > 4: break ## remove this
    
    good.close()
    bad.close()
    att = []
    att.append((goodfile, "goodups.txt"))
    if cbad > 0: att.append((badfile, "badupds.txt"))
    logger.debug(str(att))
    sendMail(sendto, "%d SF Stormpost_Reason__c updated, %d failed"%(cgood, cbad), "spsfcync", att)    
    return rc
示例#7
0
        msg = msg + "%d Successful adds to %s \n"%(len(good_adds), listname)
        __make_att("good_sp_add.txt", good_adds)
        need_mail = True

    if len(bad_adds) > 0:
        msg = msg + "%d Failed adds to %s \n"%(len(bad_adds), listname)
        __make_att("bad_sp_add.txt", bad_adds)
        need_mail = True



    if len(removed) > 0:
        msg = msg + "%d Successful unsubs from %s \n"%(len(removed), listname)
        __make_att("good_sp_del.txt", removed)
        need_mail = True
    
    
    if need_mail:
        sendMail(send_emails_to, "Stormpost updates from %s"%listname, msg, att)
    return 0



    return 0

if __name__ == "__main__":
    if len(sys.argv) != 5:
        usage() 
        sys.exit(1)
    sys.exit(main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]))
示例#8
0
        msg = msg + "%d Failed adds to SP \n"%len(bad_adds)
        __make_att("bad_sp_add.txt", bad_adds)
        need_mail = True



    if len(good_dels) > 0:
        msg = msg + "%d Successful unsubs from SP \n"%len(good_dels)
        __make_att("good_sp_del.txt", good_dels)
        need_mail = True

    if len(bad_dels) > 0:
        msg = msg + "%d Failed unsubs from SP "%len(bad_dels)
        __make_att("bad_sp_del.txt", bad_dels)
        need_mail = True
    
    
    if need_mail:
        sendMail(send_emails_to, "Stormpost updates from SF", msg, att)
    return 0
    
    
def usage():
    print "spsfsync_runner.py archive_dir"
    # archive_dir must have a now file
    
if __name__ == "__main__":
    if len(sys.argv) != 2:
        print usage()
        sys.exit(-1)
    sys.exit(main(sys.argv[1], 0))
示例#9
0
文件: sf.py 项目: juanurquijo/SF
 def __getException(self, dom):
     msg = getDataAtTag(dom, "exceptionMessage")
     if msg is not None:
         sendMail(None, "******** SF to Stormpost error **********", msg)
         raise SFException(msg)
            'span[class="restParamLabel"]')[0].getText() == "Zachm.":
        cloud = forecast[i].select('span[class="restParamValue"]')[0].getText()
    elif forecast[i].select(
            'span[class="restParamLabel"]')[0].getText() == "Wiatr":
        windSpeedRaw = forecast[i].select(
            'span[class="restParamValue"]')[0].getText()[0:7]
        windSpeed = float(speedRegEx.search(str(windSpeedRaw)).group(1))
        windDirRaw = forecast[i].select('span[class="windDirectionArrow"]')
        windDir = degRegEx.search(str(windDirRaw)).group(1)
    elif forecast[i].select(
            'span[class="restParamLabel"]')[0].getText()[1:] == "nieg":
        snowRaw = forecast[i].select(
            'span[class="restParamValue"]')[0].getText()
        snow = float(precipRegEx.search(snowRaw).group(1).replace(',', '.'))
    elif forecast[i].select(
            'span[class="restParamLabel"]')[0].getText()[3:] == "nienie":
        press = forecast[i].select('span[class="restParamValue"]')[0].getText()

sunrise = sun[0].getText()
sunset = sun[1].getText()

for name in addressBook:
    desc = hello(name) +"\n\n"+\
       current(generic, tempFeelNow, pressNow, cloudNow, rainNow, snowNow, windSpeedNow, windDirNow, humidNow) +"\n\n"+\
       forecasted(tempFeel, press, cloud, rain, snow, windSpeed, windDir) +"\n"+\
       sunTime(sunrise, sunset) +"\n\n"+\
       pollutionReport() +"\n\n"+\
       bye()
    recipient = addressBook[name]
    sendMail(desc.encode('utf-8'), recipient)
示例#11
0
def issueWarningAndScheduleDeletion():

    # This query finds all users who haven't logged in within the last 365 days and don't already have
    # a DELETE_USER_DATE record. 
    query = """
        select 
        users.user_id,
        users.first_name,
        users.last_name,
        users.email,
        users.username
        from users
        where (datediff(now(), users.last_login) > %s ) AND
        not exists
            (select 1 from user_preferences where
            users.user_id = user_preferences.user_id AND
            user_preferences.preference = '%s')"""  % (limit, preferenceDeleteUserDate)
    # print "find users to warn query is '%s'" % query
    cur = conn.cursor()
    cur.execute(query)

    deleteDate = getDeleteDate()
    """
        It's important to only issue warnings for users who actually have data.  This is to avoid
        sending a warning email to user's who have just had their data deleted the last time this
        ran.  
    """
    for row in cur:
        userid = row[0]
        email = row[3]
        username = row[4]
        if not hasData(userid, username):
            # print "Not warning user_id %d, email %s, because he has no data or tasks." % (userid, email)
            continue
        try:
            # Guest accounts have a bogus email address, don't send to them.
            if username.startswith("Guest-") and not "@" in email:
                pass
            else:
                print "Sending email to user_id %d, email %s.  He/she must log in by %s." % (userid, email, deleteDate)
                mailer.sendMail(email, fromaddr, ccaddr, emailSubject, emailContentsFile)
        except Exception, e:
            # I'm not sure if mail exceptions should be fatal because they indicate a problem that will cause failures
            # on all emails, or if they may specific to an email address.  I suspect the former.  If you find otherwise, 
            # comment out the "raise" line and uncomment the "traceback", "print" and "continue"  lines and the program 
            # will continue after mail exceptions instead of terminating.

            print "Error sending email to %s.  Will try again next time this runs.  Deletion has not been scheduled." % email 

            # traceback.print_exc()
            # print
            # continue
            raise

        # inserting DELETE_USER_DATE flag
        query2 = "insert into user_preferences (user_id, preference, value) values (%d, '%s', '%s')" % (userid, 
            preferenceDeleteUserDate, deleteDate)
        # print "insert deletion date flag statement is " + query2

        cur2 = conn.cursor()
        try:
            cur2.execute(query2)
            conn.commit()
        except Error, e:
            conn.rollback()
            print str(e)
            print "insert statement $s failed." % query2 
            print """