Beispiel #1
0
    def __init__(self):
        print("Initializing Garage Door Monitor")
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.BEAM_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        #GPIO.add_event_detect(self.BEAM_PIN, GPIO.BOTH, callback=self.break_beam_callback)
        
        atexit.register(self.exitHandler)

        config = configparser.ConfigParser()
        config.read('settings.conf')


        # While there is no internet... run a continously loop.
        # THIS IS BLOCKING THE ENTIRE STATUS CHECK SCRIPT!
        noInternetCount = 0
        while not self.internet():
            print("No internet %s!!!" % noInternetCount)

            noInternetCount += 1
            time.sleep(5)

        # Configure HTTP basic authorization: BasicAuth
        username = config['Notifications']['clicksendAPI_username']
        password = config['Notifications']['clicksendAPI_password']
        notificationNumber = config['Notifications']['phonenumber']
        notificationNumber2 = config['Notifications']['benjaminWork']
        notificationNumber3 = config['Notifications']['annaCell']
        configuration = clicksend_client.Configuration()
        configuration.username = username
        configuration.password = password

        # create an instance of the API class
        self.api_instance = clicksend_client.SMSApi(clicksend_client.ApiClient(configuration))

        # If you want to explictly set from, add the key _from to the message.
        sms_message = SmsMessage(source="python",
                        body="Hey, the garage door has been open for five minutes.",
                        to=notificationNumber)
        sms_message2 = SmsMessage(source="python",
                        body="Hey, the garage door has been open for several minutes.",
                        to=notificationNumber2)

        sms_message3 = SmsMessage(source="python",
                        body="Hey, the garage door has been open for several minutes.",
                        to=notificationNumber3)

        self.sms_messages = clicksend_client.SmsMessageCollection(messages=[sms_message,sms_message2,sms_message3])


        garageDoorStatusThread = threading.Thread(target=self.doorStatusLoop)
        sendSMSThread = threading.Thread(target=self.sendSMS)


        garageDoorStatusThread.start()
        sendSMSThread.start()
Beispiel #2
0
def textSender():

    configuration = clicksend_client.Configuration()
    configuration.username = ''
    configuration.password = ''


    # create an instance of the API class
    api_instance = clicksend_client.SMSApi(clicksend_client.ApiClient(configuration))

    # If you want to explictly set from, add the key _from to the message.
    sms_message = SmsMessage(source="sdk",
                        body="Delivery Driver needed for Cake's Bakery. Contact at 214-557-4834",
                        to=""
                       )

    sms_messages = clicksend_client.SmsMessageCollection(messages=[sms_message])

    try:
        # Send sms message(s)
        api_response = api_instance.sms_send_post(sms_messages)
        print(api_response)
        return(jsonify(api_response))
    except ApiException as e:
        print("Exception when calling SMSApi->sms_send_post: %s\n" % e)
        return("error")
Beispiel #3
0
def send_sms(request):
    if request.method == "POST":
        data = json.loads(request.body.decode("utf-8"))
        print("Sending SMS: {}".format(data))

        sms_message = SmsMessage(source="api",
                                 body=data["message_body"],
                                 to="+972{}".format(data["number"]),
                                 schedule=data["schedule"])
        sms_messages = clicksend_client.SmsMessageCollection(
            messages=[sms_message])

        try:
            api_response = ast.literal_eval(
                api_instance.sms_send_post(sms_messages))
            # save sms only if it is scheduled and we have project_id
            if data["project_id"] and data["schedule"]:
                # first cancel any scheduled messages for this project_id
                cancel_sms_by_project_id(data["project_id"])
                # now save new scheduled sms
                message_id = api_response["data"]["messages"][0]["message_id"]
                Sms(number=data["number"],
                    message_id=message_id,
                    project_id=data["project_id"]).save()
        except ApiException as e:
            print(
                "Exception when calling SMSApi->sms_send_post: {}\n".format(e))
        return HttpResponse("")
 def notify(self, to, msg):
     sms_message = SmsMessage(source="python", body=msg, to=f"+91{to}")
     sms_messages = clicksend_client.SmsMessageCollection(
         messages=[sms_message])
     try:
         # Send sms message(s)
         api_response = self.api_instance.sms_send_post(sms_messages)
         print(api_response)
     except ApiException as e:
         print("Exception when calling SMSApi->sms_send_post: %s\n" % e)
Beispiel #5
0
    def send_sms(self, phone, code):
        api_instance = clicksend_client.SMSApi(clicksend_client.ApiClient(configuration))

        sms_message = SmsMessage(source="php",
                                 body="Your security code for MEDD is {}".format(code),
                                 to=phone,
                                 schedule=1436874701)

        sms_messages = clicksend_client.SmsMessageCollection(messages=[sms_message])

        try:
            # Send sms message(s)
            api_response = api_instance.sms_send_post(sms_messages)
            print(api_response)
        except ApiException as e:
            print("Exception when calling SMSApi->sms_send_post: %s\n" % e)
Beispiel #6
0
    def send_invite_sms(self, company, phone, link):
        api_instance = clicksend_client.SMSApi(clicksend_client.ApiClient(configuration))

        sms_message = SmsMessage(source="php",
                                 body="Hello! Your company {} "
                                      "invited you as a representative manager to the MEDD platform."
                                      " Please, follow this link and confirm your participation {}".format(company, link),
                                 to=phone,
                                 schedule=1436874701)

        sms_messages = clicksend_client.SmsMessageCollection(messages=[sms_message])

        try:
            # Send sms message(s)
            api_response = api_instance.sms_send_post(sms_messages)
            print(api_response)
        except ApiException as e:
            print("Exception when calling SMSApi->sms_send_post: %s\n" % e)
Beispiel #7
0
def main():
    # create an instance of the API class
    api_instance = clicksend_client.SMSApi(
        clicksend_client.ApiClient(configuration))
    sms_message = SmsMessage(source="sdk",
                             body="This is the body of the message.",
                             country='US',
                             to="+13129709819")
    sms_messages = clicksend_client.SmsMessageCollection(
        messages=[sms_message])
    try:
        # Send sms message(s)
        api_response = api_instance.sms_send_post(sms_messages)
        sent_list = api_response['data']['messages']
        print(sent_list)
        # then - https://developers.clicksend.com/docs/rest/v3/?python#view-sms-receipts
        # https://developers.clicksend.com/docs/rest/v3/#create-test-sms-receipt
        # inbound https://developers.clicksend.com/docs/rest/v3/#view-inbound-sms
    except ApiException as e:
        print("Exception when calling SMSApi->sms_send_post: %s\n" % e)
    return
Beispiel #8
0
                if url['LastNum'] > 0:
                    msg += f"{url['Company']}: Old:{url['LastNum']}, Current:{num}\n"
                s = f"update JodyEmployees set LastNum = {num} where intID = {url['intID']}"
                SQLExec(s, cursor, conn)

    if msg != "":
        configuration = clicksend_client.Configuration()
        configuration.username = smsUser
        configuration.password = smsPass

        api_instance = clicksend_client.SMSApi(
            clicksend_client.ApiClient(configuration))
        toSend = []
        for phone in phones:

            toSend.append(
                SmsMessage(source="python", _from=srcPhone, body=msg,
                           to=phone))
        sms_messages = clicksend_client.SmsMessageCollection(messages=toSend)

        try:
            api_response = api_instance.sms_send_post(sms_messages)
            print(api_response)
        except ApiException as e:
            print("Exception when calling SMSApi->sms_send_post: %s\n" % e)

    s = "update JodyConfig set LastChecked = getdate()"
    SQLExec(s, cursor, conn)

driver.close()
conn.close()
Beispiel #9
0
from __future__ import print_function
import clicksend_client
from clicksend_client import SmsMessage
from clicksend_client.rest import ApiException

# Configure HTTP basic authorization: BasicAuth
configuration = clicksend_client.Configuration()
configuration.username = '******'
configuration.password = '******'

# create an instance of the API class
api_instance = clicksend_client.SMSApi(
    clicksend_client.ApiClient(configuration))
sms_message = SmsMessage(source="php",
                         body="hi Vibhuti this is a message from ClassUp.",
                         to="+18049388789",
                         schedule=1436874701)
sms_messages = clicksend_client.SmsMessageCollection(messages=[sms_message])

try:
    # Send sms message(s)
    api_response = api_instance.sms_send_post(sms_messages)
    print(api_response)
except ApiException as e:
    print("Exception when calling SMSApi->sms_send_post: %s\n" % e)
configuration.password = os.environ.get('NOTIFY_PARAMETER_2')

# create an instance of the API class
api_instance = clicksend_client.SMSApi(clicksend_client.ApiClient(configuration))

# If you want to explictly set from, add the key _from to the message.

if os.environ.get('NOTIFY_CONTACTPAGER') != "":
    if os.environ.get('NOTIFY_WHAT') == "HOST":
        sms_message = SmsMessage(source="php",
                                 _from=os.environ.get('NOTIFY_PARAMETER_3'),
                                 body="""
                                    %s %s
                                    Message  : %s
                                    Address  : %s
                                    Date/Time: %s
                                    """ % (os.environ.get('NOTIFY_HOSTNAME'),
                                        os.environ.get('NOTIFY_HOSTSTATE'),
                                        os.environ.get('NOTIFY_HOSTOUTPUT'),
                                        os.environ.get('NOTIFY_HOSTADDRESS'),
                                        os.environ.get('NOTIFY_SHORTDATETIME')),
                              to=os.environ.get('NOTIFY_CONTACTPAGER'))
    else:
        sms_message = SmsMessage(source="php",
                                 _from=os.environ.get('NOTIFY_PARAMETER_3'),
                                 body="""
                                 %s %s
                                 Service  : %s
                                 Message  : %s
                                 Address  : %s
                                 Date/Time: %s