Exemplo n.º 1
0
def send_gas_newsletter(gas):

    week = datetime.timedelta(7)

    # What will be
    end_date = start_date + week
    start_date = datetime.datetime.now()
    closing_orders = gas.orders.filter(datetime_end__range=(start_date, end_date))

    # What has been
    start_date = datetime.datetime.now() - week
    end_date = datetime.datetime.now()
    open_orders = gas.orders.open().filter(datetime_start__range=(start_date, end_date))
    new_pacts = GASSupplierSolidalPact.history.filter(history_type="+", history_date__range=(start_date, end_date))
    new_gasmembers = GASMember.history.filter(history_type="+", history_date__range=(start_date, end_date))
    old_gasmembers = GASMember.history.filter(history_type="-", history_date__range=(start_date, end_date))

    if not settings.DEBUG:
        recipients = [FakeRecipient(gas.orders_email_contact)]
    else:
        recipients = User.objects.filter(is_superuser=True)

    notification.send(recipients, "gas_newsletter", {
        'gas' : gas,
        'closing_orders' : closing_orders,
        'open_orders' : open_orders,
        'new_pacts' : new_pacts,
        'new_gasmembers' : new_gasmembers,
        'old_gasmembers' : old_pacts,
    }, on_site=False)
Exemplo n.º 2
0
def bulk_gasmembers_notification(unseen_since):
    """Retrieve all unseen user notices and send them via mail."""

    if not settings.DEBUG:
        recipients = User.objects.filter(
            person__gasmember_set__isnull=True).distinct()
    else:
        recipients = User.objects.filter(is_superuser=True)

    for user in recipients:

        notices = Notice.objects.notices_for(user,
                                             on_site=True,
                                             unseen=True,
                                             added__gte=unseen_since)

        try:
            notification.send([user],
                              "gasmember_notification", {
                                  'notices': notices,
                              },
                              on_site=False)

        except Exception as e:
            log.error("Send msg gasmember_notification: %s (%s)" %
                      (e.message, type(e)))
            pass

        for n in notices:
            n.unseen = False
            n.save()
Exemplo n.º 3
0
def bulk_gasmembers_notification(unseen_since):
    """Retrieve all unseen user notices and send them via mail."""

    if not settings.DEBUG:
        recipients = User.objects.filter(person__gasmember_set__isnull=True).distinct()
    else:
        recipients = User.objects.filter(is_superuser=True)
    
    for user in recipients:

        notices = Notice.objects.notices_for(user, 
            on_site=True, unseen=True, added__gte=unseen_since
        )

        try:
            notification.send([user], "gasmember_notification", {
                'notices' : notices,
            }, on_site=False)

        except Exception as e:
            log.error("Send msg gasmember_notification: %s (%s)" % (e.message, type(e)))
            pass

        for n in notices:
            n.unseen = False
            n.save()
Exemplo n.º 4
0
def watering(channel: str, wateringtime: int):
    print("Start watering")
    switch_pump("ON")
    time.sleep(wateringtime)
    switch_pump("OFF")
    print("Stop watering")

    now = datetime.now()
    current_time = now.strftime("%D %H:%M:%S")
    Notification.send("Watering plant completed at " + current_time)
Exemplo n.º 5
0
def notify_member(member, notif):
    context = {
            'member': member,
            }
    for user in member.users.all():
        user = user.user
        notification.send([user], notif, context)
        pprint("User %s was notified with notification %s for agency %s" %
                (user.username, notif, member.agency))
    member.rec_expiry_notice=True
    member.save()
Exemplo n.º 6
0
def send_comment_notification(sender, instance, created, **kwargs):
    if created:
        if not instance.aportacio.autor == instance.autor:
            send([instance.aportacio.autor], "comment_to_app", {"debat": instance})

        # notification.send([instance], "comment_to_app")

        debats = Debat.objects.filter(aportacio=instance.aportacio)
        userz = set()
        for item in debats:
            if not item.autor == instance.autor and item.autor not in userz and not item.autor == instance.aportacio.autor:
                userz.add(item.autor)
        # notification.send_now(userz, 'comment_to_com' )
        for user in userz:
            notification.send([user], "comment_to_com", {"debat": instance})
def sendIPOEmail(ipoData, download_dir, docsSearchedFor):
    global error
    ipo_count = 0

    # Writing and sending the email
    if error is True:
        email_template = "error"
    else:
        # Count the number of IPO found based on the number of dictionary keys
        for r in ipoData:
            # if r is not empty
            if r:
                ipo_count = ipo_count + 1

        # logging.info("Number of IPO found: " + str(ipo_count))
        # print("[INFO] Number of IPO found: " + str(ipo_count))

        if ipo_count == 0:
            logging.warning("No New IPO Document(s) Found - No Data Retrieved")
            print('[WARNING] No New IPO Document(s) Found - No Data Retrieved')
            email_template = "no-ipo"
        else:
            email_template = "one-ipo"
            logging.info("Writing data into txt file...")
            print("[INFO] Writing data into txt file...")
            f = open("message.txt", "w+")
            f.write("Dear ${PERSON_NAME},\r\n")
            f.write(
                "Here are the details of the IPO Document(s) found on HKEXnews website:\r\n"
            )
            for key in ipoData:
                # print(key)
                for y in ipoData[key]:
                    f.write("%s : %s\n" % (y, ipoData[key][y]))
                if ipo_count > 1:
                    f.write("-----------------------------------\n")
            f.write("\n\nDocuments searched for: " + docsSearchedFor)
            # f.write("\n\nDocuments searched for: \n   Supplementary Listing Documents \n   Allotment Results \n   "
            #         "Supplemental Information Regarding IPOs \n   IPO Cancellations (Global Offering not to proceed)")
            f.close()

    # Sleep to ensure all data is written to file before sending
    time.sleep(5)

    send(template=email_template,
         number_ipo=ipo_count,
         working_dir=path,
         attachment_dir=download_dir)
Exemplo n.º 8
0
def send_gas_notification(gas):
    """GAS notification for closing orders."""

    t = datetime.timedelta(gas.config.notice_days_before_order_close)
    end_date = datetime.datetime.now() + t
    start_date = end_date - datetime.timedelta(1)

    closing_orders = gas.orders.filter(datetime_end__range=(start_date, end_date))

    if not settings.DEBUG:
        recipients = [FakeRecipient(gas.orders_email_contact)]
    else:
        recipients = User.objects.filter(is_superuser=True)
    
    notification.send(recipients, "gas_notification", {
        'gas' : gas,
        'closing_orders' : closing_orders,
    }, on_site=False)
Exemplo n.º 9
0
 def run(self):
     should_send, title, message = self.work()
     if should_send:
         status = send(title,message)
         print(title,status)
Exemplo n.º 10
0
if __name__ == "__main__":
    login_data = load_configuration()
    c = Crawler(login_data.get("login_d"), login_data.get("password_d"))
    local_path = pth.dirname(pth.abspath(__file__))
    old_marks_file_name = local_path + "/old_marks.html"

    tmp_marks = c.getMarksInHtmlTable()

    # TODO: utf-8 should be default
    marks = str(tmp_marks.encode('utf-8'))
    try:
        f = open(old_marks_file_name, 'r')
        old_marks = f.read()
        if old_marks != marks:
            send(login_data.get("login_m"),
                 login_data.get("notification_address"),
                 login_data.get("password_m"), marks)
            f.close()
            f = open(old_marks_file_name, 'w')
            f.write(marks)
        f.close()

    except IOError:
        print("Error: this is initial usage or another error occurred")
        with open(old_marks_file_name, 'w') as f:
            send(login_data.get("login_m"),
                 login_data.get("notification_address"),
                 login_data.get("password_m"), marks, "Pierwsza wiadomosc")
            f.write(marks)
Exemplo n.º 11
0
 def handle(self, *args, **options):
     admin = User.objects.get(id=1)
     user = User.objects.get(username="******")
     notification.send([user], "member_expired", {"from_user": admin})