コード例 #1
0
ファイル: notification.py プロジェクト: dymnz/ShitHappened
class Notification:
    def _email_config(self, sender, password, stmp_url, stmp_port):
        self._email_sender = EmailSender(sender, password, stmp_url, stmp_port)

    def email_config(self, email_sender_json):
        self._email_sender = EmailSender(email_sender_json['email'],
                                         email_sender_json['password'],
                                         email_sender_json['stmp']['url'],
                                         email_sender_json['stmp']['port'])

    def send_email(self, sender_name, recipient, subject, changed_sites):
        logging.info('Mailing: {}:{}'.format(sender_name, recipient))
        logging.debug(changed_sites)

        message = self._construct_message(changed_sites)

        message['From'] = sender_name
        message['To'] = recipient
        message['Subject'] = subject

        self._email_sender.send_email(recipient, message)

    # https://stackoverflow.com/questions/882712/sending-html-email-using-python
    def _construct_message(self, changed_sites):
        msg = MIMEMultipart('alternative')

        stringSites = []
        for info in changed_sites:
            stringSites.append('{}: {}'.format(info[0], info[1]))

        text = '\n'.join(stringSites)

        stringSites = []
        for info in changed_sites:
            stringSites.append("""\
				<tr>
					<td style="width:20%; font-size: 16px; text-align: center; padding-top:20px">{}</td>
					<td style="white-space: nowrap; overflow: hidden; text-overflow:ellipsis; width:80%; padding-top:20px">{}</td>
				</tr>""".format(info[0], info[1]))

        bodyString = '\n'.join(stringSites)

        html = ("<html><head></head><body><table>" + bodyString +
                "</table></body></html>")

        part1 = MIMEText(text, 'plain')
        part2 = MIMEText(html, 'html')

        msg.attach(part1)
        msg.attach(part2)

        return msg
コード例 #2
0
    def validate_speed(cls, trackable_object, time_stamp, frame):
        # Initialize log file.
        if not cls.log_file:
            cls.initialize_log_file()

        # check if the object has not been logged
        if not trackable_object.logged:
            # check if the object's speed has been estimated and it
            # is higher than the speed limit
            if trackable_object.estimated and trackable_object.speedMPH > MAX_THRESHOLD_SPEED:
                # set the current year, month, day, and time
                year = time_stamp.strftime("%Y")
                month = time_stamp.strftime("%m")
                day = time_stamp.strftime("%d")
                time = time_stamp.strftime("%H:%M:%S")

                if SEND_EMAIL:
                    # initialize the image id, and the temporary file
                    imageID = time_stamp.strftime("%H%M%S%f")
                    tempFile = TempFile()
                    cv2.imwrite(tempFile.path, frame)

                    # create a thread to upload the file to dropbox
                    # and start it
                    t = Thread(target=EmailSender.send_email(),
                               args=(tempFile, imageID))
                    t.start()

                    # log the event in the log file
                    info = "{},{},{},{},{},{}\n".format(
                        year, month, day, time, trackable_object.speedMPH,
                        imageID)
                else:
                    # log the event in the log file
                    info = "{},{},{},{},{}\n".format(year, month, day, time,
                                                     trackable_object.speedMPH)
                cls.logFile.write(info)

                # set the object has logged
                trackable_object.logged = True
コード例 #3
0
    ''' Function to be executed as thread to check for new emails and act accordingly.'''
    global email
    while True:
        check_email_and_act()
        sleep(15)

#####   MAIN    #####

if __name__ == "__main__":
    # begin email thread
    email_thread = threading.Thread(target=check_email_periodically, daemon=True)
    email_thread.start()
    # system startup
    date_time = get_time()
    print(date_time+" - starting system...")
    emailSender.send_email(commanders[1], "Starting system", "{} {} - {}".format("System is now up.", body, date_time), None)
    camera = picamera.PiCamera()
    stream = picamera.array.PiRGBArray(camera)
    camera.resolution = (1280,720)
    camera.framerate = 20
    camera.iso = 800
    sleep(1)
    # main loop
    while True:
        if system_is_armed:
            mse = 0
            camera.capture(stream, 'bgr')
            # stream.array now contains the image data in BGR order
            actual_frame = stream.array
            if not firstrun:
                image1 = cv2.cvtColor(actual_frame, cv2.COLOR_BGR2GRAY)
コード例 #4
0
from email_sender import EmailSender
from crawler import LinkedInCrawler
from data_cleaning import clean_data

if __name__ == '__main__':
    """
    This is how the workflow is supposed to run. However, if the user wants to run the program to test it, 
    I recommend running the scripts separately as one collection of one company in one city alone is ranging 
    between 40-45m. The user can also set a small number of pages to be searched by including the desired number(int)
    to be searched by inserting it as a param in the get_data function below. 
    If the scripts are to be run separately this would be the order to run the files run the files:
    crawler_linkedin.py > data_cleaning.py > email_sender.py

    If the user doesn't want to pester the Uber's employees again just make a list with a few names(first and last)
    and substitute the param in send_email function.
    """
    start = time()

    cities = ['São Paulo', 'San Francisco']
    company = ['Uber']
    # TODO: You must install ChromeDrive in your computer from https://chromedriver.chromium.org/ for selenium to work

    # Collects the results from the all cities and companies combinations
    raw_data = LinkedInCrawler.get_data(cities, company)
    # Clean the data
    cleaned_data = clean_data(raw_data)
    # Send the emails
    EmailSender.send_email(cleaned_data)

    total = time() - start
コード例 #5
0
 def test_send_email(self):
     self.assertEqual(EmailSender.send_email(), True)
コード例 #6
0
        raise

    if bestbuy_tracking_retriever.failed_email_ids:
        print(
            "Found %d BB emails without buying group labels and marked them as unread. Continuing..."
            % len(bestbuy_tracking_retriever.failed_email_ids))

    try:
        total_trackings = sum(
            [len(trackings) for trackings in groups_dict.values()])
        print("Found %d total tracking numbers" % total_trackings)

        # We only need to process and upload new tracking numbers if there are any;
        # otherwise skip straight to processing existing locally stored data.
        if total_trackings > 0:
            email_sender.send_email(groups_dict)

            print("Uploading tracking numbers...")
            group_site_manager = GroupSiteManager(config, driver_creator)
            try:
                group_site_manager.upload(groups_dict)
            except:
                send_error_email(email_sender,
                                 "Error uploading tracking numbers")
                raise

            print("Adding results to Google Sheets")
            tracking_uploader = TrackingUploader(config)
            try:
                tracking_uploader.upload(groups_dict)
            except:
コード例 #7
0
                    fail_count += 1
                if fail_count > 5:
                    break

            # zip
            #TODO: copy to onedrive file or send to file server
            result = os.system('zip -r zips/%s.zip content/%s' %
                               (this_day, this_day))

            # Generate list
            with open("zips/list-%s.txt" % this_day, 'w+') as f:
                for area_articles in spider.articles:
                    for article in spider.articles[area_articles]:
                        f.write(article.__str__() + '\n')

            # send
            sender = EmailSender(file_path='zips/list-%s.txt' % this_day)
            sender.send_email()
        else:
            print("no")
            break
    else:
        print("no_new_article_today")
    print(this_day)
    last_day = this_day
    time.sleep(432)


def GetArticles():
    return
コード例 #8
0
ファイル: ajax.py プロジェクト: freedomd/WhiteBayReporting
def getSummaryReport(request, account, symbol, datefrom, dateto, user_email):
    
    # start filter
    report_list = None
    filename = ""
    content = "" #email content
    
    if account is not u"" or None:
        filename += account + "_"
        content += "Account: " + account + "\n"
        if report_list is None:
            report_list = Report.objects.filter(Q(account__icontains=account))
        else:
            report_list = report_list.filter(Q(account__icontains=account))
    
    if symbol is not u"" or None:
        filename += symbol + "_"
        content += symbol + " "
        if report_list is None:
            report_list = Report.objects.filter(Q(symbol=symbol))
        else:
            report_list = report_list.filter(Q(symbol=symbol))
    
    content += "Summary Report:\n"

    if datefrom is not u"" or None:
        filename += "%s_" % datefrom.replace("-", "")
        content += "from %s\n" % datefrom
        if report_list is None:
            report_list = Report.objects.filter(Q(reportDate__gte=datefrom))
        else:
            report_list = report_list.filter(Q(reportDate__gte=datefrom))
    
    if dateto is not u"" or None:
        filename += "%s_" % dateto.replace("-", "")
        content += "to %s\n" % dateto
        if report_list is None:
            report_list = Report.objects.filter(Q(reportDate__lte=dateto))
        else:
            report_list = report_list.filter(Q(reportDate__lte=dateto))
    
    if report_list != None:
        filename += "SUMM.csv"
        filepath = "./temp/" + filename 
        with open(filepath, 'wb') as csvfile:
            writer = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
            writer.writerow(['Symbol', 'SOD', 'Buys', 'BuyAve', 'Sells', 'SellAve', 'EOD',
                             'RealizedPNL', 'UnrealizedPNL', 'Commission', 'SEC Fees', 'ECN Fees', 'Net PNL'])
            
            summary_list = getSummary(report_list.order_by("reportDate"))
            
            for summary in summary_list:
                report = summary_list[summary]
                writer.writerow([report.symbol, report.SOD,
                                 report.buys, round(report.buyAve, 2), 
                                 report.sells, round(report.sellAve, 2), report.EOD,
                                 round(report.realizedPNL, 2), round(report.unrealizedPNL, 2), 
                                 round(report.commission, 2), round(report.secFees, 2), round(report.ecnFees, 2), 
                                 round(report.netPNL, 2)])
        
        es = EmailSender()
        success, message = es.send_email(filename, content, user_email, filepath)
        if success:
            message = "Summary report will be sent to <i><strong>%s</strong></i>." % user_email 
        os.remove(filepath)
    else:
        message = "No match reports."
        
    data = { 'message': message }
    
    return simplejson.dumps(data)
コード例 #9
0
            logger.debug(
                "Caulculated limit price as %f: %f x (1 + (%f *2) + %f)" %
                (limit_price, ask, bitstamp_client.btc_usd_fee,
                 profit_percentage))
            logger.debug("Caulculated limit price as %f: %f x %f" %
                         (limit_price, ask, multiplier))

            log_string = "Going to place order for %f bitcoin at a price of %f, selling again at %f" % (
                amount, price, limit_price)
            logger.info(log_string)
            print log_string

            if email_alerts_to:
                email_sender.send_email(
                    "Placed buy order for bitcoins on Bitstamp",
                    email_alerts_to, log_string)
                logger.info("Sent email alert")

            orders_to_date.append({
                "qty_usd": per_order_quantity,
                "qty_btc": amount,
                "price_buy": price,
                "price_sell": limit_price,
                "time": now
            })

            bitstamp_client.place_buy_limit_order(amount=amount,
                                                  price=ask,
                                                  limit_price=limit_price)
コード例 #10
0
ファイル: start.py プロジェクト: ryan-dd/crypto-price-alerts
import time
import argparse
import sys

parser = argparse.ArgumentParser(description='Send notifications on crypto prices')
parser.add_argument('gmail_sender_address', type=str, help='Gmail address to send from')
parser.add_argument('email_receiver_address', type=str, help='Email Address to send to')
args = parser.parse_args()

email_sender = EmailSender(args.gmail_sender_address)

conditions = []
conditions.append(CryptoNotificationCondition('bitcoin', Threshold.ABOVE, 70000))
conditions.append(CryptoNotificationCondition('bitcoin', Threshold.BELOW, 10000))

print("Starting...")
while(True):
    try:
        for condition in conditions:
            if condition.should_notify():
                email_sender.send_email(condition.get_email_message(), args.email_receiver_address)
                print("Sent email: " + condition.name_of_coin)
    except:
        print("Error occurred")
        e1 = sys.exc_info()[0]
        e2 = sys.exc_info()[1]
        print(e1)
        print(e2)
    time.sleep(60)