Example #1
0
def mail_report(supplier):
    path = "/mnt/c/Users/91894/Desktop/SHOP-PY/supplier-data/descriptions/"
    path_to_report = reports.generate_report(path)

    reciever = supplier
    message = emails.generate_mail(reciever, path_to_report)
    emails.send_mail(message)
Example #2
0
def inv_address():
    udp_message = bytes([0x5a, 0x5a, 0x5a, 0x5a, 0x00, 0x41, 0x3a, 0x04])

    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
    sock.connect(("8.8.8.8", 80))
    ip = sock.getsockname()[0]
    ip = socket.inet_aton(ip)
    sock.close()

    for i in ip:
        udp_message += bytes([i])
    if config.debug:
        print(ip)
        print("\n")
        print(udp_message)
        print("\n")

    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    sock.settimeout(3.0)
    sock.bind(("", 6600))
    time.sleep(5)
    sock.sendto(udp_message, ('<broadcast>', 6600))
    i = 0
    while True:
        try:
            time.sleep(1)
            data, addr = sock.recvfrom(1024)
#        except socket.timeout:
        except Exception as e:
            print("huaweil inv_address error: %s" % str(e))
            if config.debug:
                print('--> resend')
            sock.sendto(udp_message, ('<broadcast>', 6600))
            time.sleep(2)
            i = i + 1
            if i < 5:
                time.sleep(5)
                continue
            else:
                if config.debug:
                    print("can't find inverter")
                if (config.inverter_ip != ""):
                    return config.inverter_ip
                emails.send_mail("can't find inverter" + str(e))

        if len(data) == 30:
            addr = str(addr[0])
            if config.debug:
                print("inverter address: " + addr)
            return (addr)
Example #3
0
def run(me, password):
    get_ETF_fr_YH('ETF.csv')
    send_mail(
        send_from = '*****@*****.**', 
        send_to = SUBSCRIBE_LIST, 
        subject = 'Suggested ETF', 
        text = """Hello,
Attachment includes the ETFs.
Sincerely,
""", 
        files = ['ETF.csv'], 
        server = 'smtp.gmail.com',
        username = me,
        password = password
    )
Example #4
0
def run(me, password):
    find_validETF('ETF.csv')
    send_mail(send_from='*****@*****.**',
              send_to=SUBSCRIBE_LIST,
              subject='Suggested ETF',
              text="""Hello,

Attachment includes the ETFs with today's close lower than Bollinger Bottom and Relative Strength Index lower than 30.

Sincerely,
-Weiyi
""",
              files=['ETF.csv'],
              server='smtp.gmail.com',
              username=me,
              password=password)
Example #5
0
def run(me, password):
    find_validETF('ETF.csv')
    send_mail(
        send_from = '*****@*****.**', 
        send_to = SUBSCRIBE_LIST, 
        subject = 'Suggested ETF', 
        text = """Hello,

Attachment includes the ETFs with today's close lower than Bollinger Bottom and Relative Strength Index lower than 30.

Sincerely,
-Weiyi
""", 
        files = ['ETF.csv'], 
        server = 'smtp.gmail.com',
        username = me,
        password = password
    )
Example #6
0
async def add_user(request):
    # todo informacja zwrotna (mail w użyciu, użytkownik zajerestrowany, takie bzdety)
    data = await request.post()
    try:
        password = hashlib.sha3_256(data["password"].encode()).hexdigest()
        token = db.add_user_unauthorized(login=data['login'],
                                         password=password,
                                         email=data['email'])
        if token:
            try:
                emails.send_mail(address_to=data['email'],
                                 token=token,
                                 nick=data['login'])
            except Exception:
                pass
            return web.Response(text="ok")
        else:
            return web.Response(text="not ok")
    except KeyError:
        return web.Response(text="not ok")
    pass
Example #7
0
File: app.py Project: lilvedaes/sso
def show_page():
    if request.method == 'POST':
        emails.send_mail(request.values)
        return "", 204

    return render_template("index.html")
Example #8
0
def main():
    global register
    global measurement
    global info
    global status
    global y_exp
    global c_exp
    global y_gen
    global c_gen
    global y_tot
    global c_tot
    global c_peak
    global tmax
    global min_ins
    global c_stop
    global c_start
    global client
    global flux_client
    global ok
    global forecast_array
    global loads
    global loops

    config.loads = {}
    inverter_file = config.model
    inverter = __import__(inverter_file)
    if config.debug:
        print("got it")

    inverter_ip = inverter.inv_address()
    print(inverter_ip)
    if inverter_ip != "":
        config.inverter_ip = inverter_ip

    print(config.inverter_ip)
    if config.debug:
        print("statring setup")
        print("opening modbus")

    client = connect_bus(ip=config.inverter_ip,
                         PortN=config.inverter_port,
                         timeout=config.timeout)

    if config.debug:
        print("opening db")

    try:
        flux_client = InfluxDBClient(host=config.influxdb_ip,
                                     port=config.influxdb_port,
                                     username=config.influxdb_user,
                                     password=config.influxdb_password)

    except Exception as e:
        print("main error: %s" % str(e))
        flux_client = None
        print("problem openning db")

    if config.debug:
        print("setting db")

    flux_client.create_database(config.influxdb_database)
    flux_client.create_database(config.influxdb_longterm)
    if config.debug:
        print("setting params")

    last_loop = 0
    info_time = 0
    last_status = {}
    y_exp = 0
    c_exp = 0
    y_tot = 0
    c_tot = 0
    y_gen = 0
    c_gen = 0
    c_peak = 0
    c_start = ""
    c_stop = ""
    tmax = 0
    min_ins = 1000
    thread_time = [1]
    thread_mean = 1
    sleep = 0
    midnight = (int(
        time.mktime(
            time.strptime(
                time.strftime("%m/%d/%Y ") + " 00:00:00",
                "%m/%d/%Y %H:%M:%S"))))
    s = (
        'SELECT %s FROM "%s" WHERE time >= %s and time <= %s and P_daily > 0'
    ) % (
        'max("M_PExp") as "M_PExp", max("M_PTot") as "M_PTot", max("P_accum") as "P_accum", max("P_daily") as "P_daily", max("Temp") as "Temp"',
        config.model, str(
            (midnight - 24 * 3600) * 1000000000), str(midnight * 1000000000))
    zeros = flux_client.query(s, database=config.influxdb_database)
    m = list(zeros.get_points(measurement=config.model))
    try:
        y_exp = m[0]['M_PExp']
        y_tot = m[0]['M_PTot']
        y_gen = m[0]['P_daily']
        tmax = m[0]['Temp']

    except Exception as e:
        print("main 1 error: %s" % str(e))
        y_exp = 0
        y_tot = 0
        y_gen = 0
        tmax = 0

    s = (
        'SELECT %s FROM "%s_info" WHERE time >= %s and time <= %s and Insulation > 0'
    ) % ('min("Insulation") as "Insulation"', config.model,
         str((midnight - 3600 * 24) * 1000000000), str(midnight * 1000000000))
    zeros = flux_client.query(s, database=config.influxdb_database)
    m = list(zeros.get_points(measurement=config.model + "_info"))
    try:
        if config.debug:
            print(m[0])

        min_ins = m[0]['Insulation']

    except Exception as e:
        print("main 2 error: %s" % str(e))
        if config.debug:
            print(s)

        min_ins = 1000

    midnight = int(
        time.mktime(
            time.strptime(
                time.strftime("%m/%d/%Y ") + " 23:59:59",
                "%m/%d/%Y %H:%M:%S"))) + 1
    if ((float(time.strftime("%S")) % 60) > 1):
        time.sleep(59 - float(time.strftime("%S")))

    utils.fill_blanks(flux_client, midnight)
    forecast_time = forecast(midnight)
    if config.debug:
        print("loop")

    ok = True
    low_prod = time.time() + 300
    while ok:
        current_time = time.time()
        if (current_time - last_loop + thread_mean >= int(
                config.scan_interval)):
            last_loop = current_time
            measurement = {}
            info = {}
            status = {}
            j = 0
            while do_map(client, config, inverter):
                j += 1
                if config.debug:
                    print(time.ctime(), register)
                    print("map looping")

                time.sleep(10)
                if j > 10:
                    if config.debug:
                        print("map infinite loop")

                    ok = False

                if not ok:
                    return -1

            if not ok:
                return -1

            current_time = time.time()
            if (current_time - info_time > config.info_interval):
                utils.write_influx(flux_client, info, config.model + "_info",
                                   config.influxdb_database)
                info_time = current_time
                if config.debug:
                    print(info)
                    print(y_exp)
                    print(c_exp)
                    print(y_tot)
                    print(c_tot)
                    print(y_gen)
                    print(c_gen)
                    print(c_peak)
                    print(c_start)
                    print(c_stop)
                    print(tmax)
                    print(min_ins)
                if info["Insulation"] > 0 and info["Insulation"] < 1.5:
                    emails.send_mail("Insulation low: " +
                                     str(info["Insulation"]))

            if (status != last_status):
                utils.write_influx(flux_client, status, config.model + "_stat",
                                   config.influxdb_database)
                last_status = status
                if config.debug:
                    print(status)
                if ((status["Alarm1"] != "") or (status["Alarm2"] != "")
                        or (status["Alarm3"] != "")
                        or (status["Fault"] != '0')):
                    emails.send_mail("Help\r\n" + str(status))

            if config.debug:
                print("looking at low production")
                print(measurement)
                print(low_prod)

            i = 0
            j = 0

            try:
                for j in forecast_array:
                    if j > current_time:
                        break
                    i = j
                if float(time.strftime("%H")) > 12:
                    i = j
                if i == 0:
                    i = j
                if config.debug:
                    print(i)
                    print(j)
                    print(forecast_array[i])

                if (measurement["P_active"] * 2 < forecast_array[i]):
                    if (current_time > low_prod + 300):
                        emails.send_mail("low production: " +
                                         measurement["P_active"])
                else:
                    low_prod = current_time
            except:
                if config.debug:
                    print("no forcast in low production")
                    print(measurement["P_active"])
                    print(time.strftime("%H"))
                if measurement["P_active"] == 0:
                    if float(time.strftime("%H")) > 11 and float(
                            time.strftime("%H")) < 15:
                        if (current_time > low_prod + 300):
                            emails.send_mail("low production: " +
                                             measurement["P_active"])
                else:
                    low_prod = current_time

            x = config.scan_interval - (float(time.strftime("%S")) %
                                        config.scan_interval)
            if x == 30:
                x = 0

            if (0.5 < x < 6):
                time.sleep(x - 0.05)

            if (config.diverters):
                changes = divert.check(measurement['M_P'])
                for x in changes:
                    measurement["load_" + str(x)] = changes[x]


#                print(changes)
#                print(measurement)

            utils.write_influx(flux_client, measurement, config.model,
                               config.influxdb_database)

            if (measurement["Temp"] > 60):
                emails.send_mail("Temperatur high: " +
                                 str(measurement["Temp"]))

            if (config.supla_api != ""):
                #read from supla
                supla()

            thread_time.insert(0, time.time() - last_loop)
            if len(thread_time) > 5:
                thread_time.pop()

            loops = 0

            thread_mean = sum(thread_time) / len(thread_time)
            if (int(time.time()) > midnight):
                daily = {}
                daily['Insulation'] = float(min_ins)
                min_ins = 1000
                daily['Temp'] = float(tmax)
                tmax = 0
                s = 'SELECT cumulative_sum(integral("power90")) /3600  as power90, cumulative_sum(integral("power10")) /3600  as power10, cumulative_sum(integral("power")) /3600  as power FROM "forcast" WHERE time > now() -22h group by time(1d)'
                zeros = flux_client.query(s, database=config.influxdb_database)
                m = list(zeros.get_points(measurement="forcast"))
                daily['f_power'] = float(m[0]['power'])
                try:
                    daily['f_power90'] = float(m[0]['power90'])
                    daily['f_power10'] = float(m[0]['power10'])

                except Exception as e:
                    if config.debug:
                        print("main 3 error: %s" % str(e))
                    daily['f_power90'] = float(m[0]['power'])
                    daily['f_power10'] = float(m[0]['power'])

                if config.debug:
                    print(midnight)
                    print(c_gen)
                    print(y_gen)
                    print(c_peak)

                if y_exp != 0 and y_tot != 0:
                    daily['P_Load'] = float(c_gen - (c_exp - y_exp) +
                                            (c_tot - y_tot))

                daily['P_daily'] = float(c_gen)
                c_gen = 0
                if (y_exp != 0):
                    daily['P_Exp'] = float(c_exp - y_exp)

                y_exp = c_exp
                if (y_tot != 0):
                    daily['P_Grid'] = float(c_tot - y_tot +
                                            config.extra_load * 24 / 1000)

                y_tot = c_tot
                daily['P_peak'] = float(c_peak)
                daily['Start'] = c_start
                daily['Shutdown'] = c_stop
                utils.write_influx(flux_client, daily, config.model + "_daily",
                                   config.influxdb_longterm,
                                   (midnight - 24 * 3600) * 1000000000)
                if config.debug:
                    print(time.ctime(midnight - 24 * 3600))
                    print(daily)

                utils.send_measurements(midnight - 24 * 3600, midnight,
                                        flux_client)
                midnight = int(
                    time.mktime(
                        time.strptime(
                            time.strftime("%m/%d/%Y ") + " 23:59:59",
                            "%m/%d/%Y %H:%M:%S"))) + 1

            if (int(time.time()) > forecast_time):
                forecast_time = forecast(midnight)

        else:
            sleep = config.scan_interval - (
                float(time.strftime("%S")) %
                config.scan_interval) - thread_mean * 1.1
            if sleep == config.scan_interval:
                sleep = 0.0

    #       sleep = 0.95 * (config.scan_interval - (time.time() - last_loop)) + 0.05
            if ((int(time.time() + sleep)) > midnight):
                sleep = midnight - int(time.time())

            if sleep < 0.16:
                sleep = 0.1

    #       if sleep < 0:
    #           sleep = 1
            time.sleep(sleep)

        try:
            pass

        except Exception as e:
            print("main 4 error: %s" % str(e))
            ok = False
            return -1
Example #9
0
            if sleep < 0.16:
                sleep = 0.1

    #       if sleep < 0:
    #           sleep = 1
            time.sleep(sleep)

        try:
            pass

        except Exception as e:
            print("main 4 error: %s" % str(e))
            ok = False
            return -1

emails.send_mail("Starting solar logger")
loops = 0
while True:
    print("starting")
    print(time.strftime("%c"))
    try:
        main()
        close_bus(client)
        flux_client.close()
        del flux_client

    except Exception as e:
        print("top error: %s" % str(e))
        print("something went wrong")
        loops = loops + 1
        if loops > 9:
Example #10
0
webs = [line.strip() for line in webFile]

need = [True] * len(products)
count = 1

while True in need:
  for i in range(len(products)):
    if need[i]:
      product = products[i].lower()
      
      for address in webs:
        page = urllib2.urlopen(address).read()
        page = page.lower()
        if product in page:
          title = address + ' has ' + product
          send_mail(title)
          need[i] = False

  LB = 5
  UB = 15
  minute = random.randint(LB, UB)
  time.sleep(SECOND_PER_MINUTE * minute)
    
    
# ----------------------------------------------------------------------------------------------------------------------
# Source: https://github.com/muthash/flight-booking-flask/blob/develop/app/helpers/send_email.py

import os
import atexit
import logging