Example #1
0
    def __init__(self, api_key, channel_name):

        from pushetta import Pushetta

        self._api_key = api_key
        self._channel_name = channel_name
        self.pushetta = Pushetta(self._api_key)
Example #2
0
    def __init__(self, api_key, channel_name, send_test_msg):
        """Initialize the service."""
        from pushetta import Pushetta
        self._api_key = api_key
        self._channel_name = channel_name
        self.is_valid = True
        self.pushetta = Pushetta(api_key)

        if send_test_msg:
            self.send_message("Home Assistant started")
Example #3
0
def send_notification(working_dir, msg):
    if len(msg) == 0:
        return

    f_name = working_dir + "/SettingFiles/pushetta"
    if not os.path.isfile(f_name):  # if such a file doesnt exist
        print("Are you sure you dont want to use pushetta? It is pretty neat.")
        return

    with open(f_name, "r") as myfile:
        raw_input = myfile.read().split('\n')
        API_KEY = raw_input[0]
        CHANNEL_NAME = raw_input[1]

    p = Pushetta(API_KEY)
    p.pushMessage(CHANNEL_NAME, msg)
Example #4
0
    def __init__(self, **kwargs):
        """
        Send a push message to an android phone via Pushetta API
        :param message: Message to send
        :param api_key: The Pushetta service secret token
        :param channel_name: Pushetta channel name
        """
        super(Push_message, self).__init__(**kwargs)

        self.message = kwargs.get('message', None)
        self.api_key = kwargs.get('api_key', None)
        self.channel_name = kwargs.get('channel_name', None)

        # check if parameters have been provided
        if self._is_parameters_ok():
            p = Pushetta(self.api_key)
            p.pushMessage(self.channel_name, self.message)
Example #5
0
def get_service(hass, config):
    """Get the Pushetta notification service."""
    from pushetta import Pushetta, exceptions

    if not validate_config({DOMAIN: config},
                           {DOMAIN: [CONF_API_KEY, 'channel_name']}, _LOGGER):
        return None

    try:
        pushetta = Pushetta(config[CONF_API_KEY])
        pushetta.pushMessage(config['channel_name'], "Home Assistant started")
    except exceptions.TokenValidationError:
        _LOGGER.error("Please check your access token")
        return None
    except exceptions.ChannelNotFoundError:
        _LOGGER.error("Channel '%s' not found", config['channel_name'])
        return None

    return PushettaNotificationService(config[CONF_API_KEY],
                                       config['channel_name'])
Example #6
0
    def __init__(self,
                 message=None,
                 api_key=None,
                 channel_name=None,
                 **kwargs):
        """
        Send a push message to an android phone via Pushetta API
        :param message: Message to send
        :param api_key: The Pushetta service secret token
        :param channel_name: Pushetta channel name
        :return:
        """
        super(Push_message, self).__init__(**kwargs)
        if message is None:
            raise NotImplementedError("Pushetta neuron needs message to send")

        if api_key is None:
            raise NotImplementedError("Pushetta neuron needs api_key")
        if channel_name is None:
            raise NotImplementedError("Pushetta neuron needs channel_name")

        p = Pushetta(api_key)
        p.pushMessage(channel_name, message)
Example #7
0
def main():
    global start_value
    global data_max

    # Initialize sensor with external library class.
    sensor = mpu9250()

    # Key taken from account.
    API_KEY = "fb2dc4530995b2fe3d3f823a0fa35a5e8d635716"

    # Name of channel.
    CHANNEL_NAME = "JuicySeniorDesign"

    # Create pushetta object.
    p = Pushetta(API_KEY)

    print('entering main loop...')
    sys.stdout.flush()
    while True:

        # Get sensor data.
        data = sensor.accel[2]

        # Look at new max value.
        if data > data_max:
            print('New Maximum... {}'.format(data_max))
            data_max = data

        # Thresholding for alarm detection. Adjust magnitude for each axis.
        if (data_max >= (start_value + Z_THRESHOLD)):
            print('Sending out alert... {} {} {}'.format(
                data_max, start_value, Z_THRESHOLD))
            sys.stdout.flush()
            alert(p, CHANNEL_NAME, sensor)
            print('Done... {} {} {}'.format(data_max, start_value,
                                            Z_THRESHOLD))
            sys.stdout.flush()
def main():
 try:
  sensor = 4

  GPIO.setmode(GPIO.BCM)
  GPIO.setup(sensor, GPIO.IN, GPIO.PUD_DOWN)

  previous_state = False
  current_state = False
  cam = picamera.PiCamera()

  API_KEY="e224478433d166114af5e762433790fb5f5921a5"
  CHANNEL_NAME="CzechBery"
  p=Pushetta(API_KEY)
  print "...Camera trap is ready... "

  while True:
      time.sleep(0.1)
      previous_state = current_state
      current_state = GPIO.input(sensor)
      if current_state != previous_state:
          new_state = "HIGH" if current_state else "LOW"
          print("GPIO pin %s is %s" % (sensor, new_state))
          if current_state:
              fileName = get_file_name()
              cam.start_preview()
              p.pushMessage(CHANNEL_NAME, "Motion Detected... Look at mail!")
              time.sleep(2)
              cam.capture(fileName)
              time.sleep(1)
              SendMail(fileName)#zde volam na metodu SendMail a pridavam ji atribut filname coz je nazev souboru ktery se ma poslat mailem
          else:
              cam.stop_preview()
 except KeyboardInterrupt:
     print " System is terminated"
 except Exception:
     print "Nastal Error"
Example #9
0
    start_value = sensor.accel[2]
    
    
if __name__ == "__main__":

    # Initialize sensor with external library class.
    sensor = mpu9250()
    
    # Key taken from account.
    API_KEY = "fb2dc4530995b2fe3d3f823a0fa35a5e8d635716"
    
    # Name of channel.
    CHANNEL_NAME = "JuicySeniorDesign"
    
    # Create pushetta object.
    p = Pushetta(API_KEY)

    data_max = 0
    
    while True:
        
        # Get sensor data.
        data = sensor.accel[2]

        # Look at new max value.
        if data > data_max:
            data_max = data
            
        # Thresholding for alarm detection. Adjust magnitude for each axis.           
        if (data_max >= (start_value + Z_THRESHOLD)):
            alert(p, CHANNEL_NAME, sensor)
Example #10
0
###########################################
# CONFIGURATION
WIDTH = 640
HEIGHT = 480
FRAMERATE = 24
HTTP_PORT = 8082
WS_PORT = 8084
COLOR = u'#444'
BGCOLOR = u'#333'
JSMPEG_MAGIC = b'jsmp'
JSMPEG_HEADER = Struct('>4sHH')

config = configparser.ConfigParser()
PUSHETTA_KEY = "e591b03544179db61e747dddccceac0fa3714d26"
CHANNEL_NAME = "SensorRPI"
alarm = Pushetta(PUSHETTA_KEY)
pir = MotionSensor(4)
###########################################


class StreamingHttpHandler(BaseHTTPRequestHandler):
    def do_HEAD(self):
        self.do_GET()

    def do_GET(self):
        config.read('config.ini')
        ACTIVE = config.get('main','active')
        STREAMING = config.get('main', 'streaming')
        SAVE = config.get('main', 'save')
        ACTIVE_CHECK = ''
        SAVE_CHECK=''
Example #11
0
# Kütüphaneleri import ettik
from pushetta import Pushetta
from bs4 import BeautifulSoup
import requests
from os import getcwd

# Pushetta için ApiKey'imizi buraya yazıyoruz
API_KEY = "API-KEY-HERE"
kanal = "Anime Bildirim"
# bildirim göndermek için Pushetta nesnesi oluşturduk
bildirim = Pushetta(API_KEY)
# Örnek kullanım
# bildirim.pushMessage("KanalAdı", "Bildirim")

# dizimob anasayfası kaynak kodunu çektik
r = requests.get('https://www.dizimob1.com/')
# BeautifulSoup ile kaynak kodu, html.parser modunda inceleyeceğiz
source = BeautifulSoup(r.content, "html.parser")
# A değişkeni bize class'ında listfilm bulunan tüm div leri çekti,
# sitede bu div ler dizi ve animelerin listelendiği divlerdir.
# yani tüm dizi ve animeleri çektik.
A = source.findAll("div", attrs={"class", "listfilm"})

# hata almamak için çektiklerimizi kaynak koda atıyoruz
content = ""
for element in A:
    content += str(element)
# Çektiklerimiz üstünden devam edelim
source = BeautifulSoup(content, "html.parser")

# animeler.txt okuma modunda dosyasını açtık
Example #12
0
def main():

    parser = OptionParser(usage=__doc__)  #, version=__version__)
    parser.set_defaults(gui=True)
    parser.add_option("--ini",
                      action="store",
                      dest="inifile",
                      default="config/config.ini",
                      help="specify pyocto ini file (default: config.ini)")
    parser.add_option("-n",
                      "--notify",
                      action="store_true",
                      dest="push",
                      default=False,
                      help="send push notification when script terminates")
    parser.add_option("--setup",
                      action="store_true",
                      dest="setup",
                      default=False,
                      help="setup a vivado project")
    parser.add_option("--clear",
                      action="store_true",
                      dest="clear",
                      default=False,
                      help="clear a yocto build project")
    parser.add_option("--build",
                      action="store_true",
                      dest="build",
                      default=False,
                      help="build the yocto project")
    parser.add_option("--update",
                      action="store",
                      dest="update",
                      help="update the git repos.")

    # Parse command-line
    global options
    if len(sys.argv) < 2:
        if os.path.exists("pyocto.cmd"):
            argv = list(
                flatten([
                    a for a in (l.split('#')[0].split()
                                for l in open("pyocto.cmd")) if len(a)
                ]))
        else:
            argv = ["--help"]
    else:
        argv = sys.argv[1:]
    cmdline = ' '.join(argv)
    (options, args) = parser.parse_args(argv)

    inifile = options.inifile

    # Parse options form the configuration file
    v_pyocto = pyocto(inifile, options)

    #execute using the selected options
    if options.setup:
        print "-.- clone the yocto repos."
        v_pyocto.pyocto_git_clone("yocto")
        #if (os.path.exists("./poky")):
        #    print "-W- poky exists. Consider using the update switch - skip the clone"
        #else:
        #    g.clone(v_pyocto.yocto.repo_yocto)
        #    # git.Git().clone(v_pyocto.yocto.repo_yocto)

        os.chdir('poky')
        print "-.- path is now: " + os.getcwd()
        v_pyocto.pyocto_git_clone("meta-xilinx")
        v_pyocto.pyocto_git_clone("meta-xilinx-tools")
        # v_pyocto.pyocto_git_clone("meta-xilinx-petalinux")
        v_pyocto.pyocto_git_clone("meta-zynqberry")

        print "-I- Setup is DONE ----"

        notification = "PYOCTO (setup) is over"

    if options.clear:
        print "clear"
        notification = "PYOCTO (clear) is not supported"

        print "---- DONE ----"
        exit()

    if options.build:
        print "build"
        notification = "PYOCTO (build) is not supported"
        exit()

    if options.update:
        print "update"
        notification = "PYOCTO (update) is not supported"
        exit()

    if options.push and importpushetta:

        print "-.- Send notification"

        API_KEY = v_pyocto.notification.api_key
        CHANNEL_NAME = v_pyocto.notification.channel_name

        p = Pushetta(API_KEY)
        p.pushMessage(CHANNEL_NAME, notification)

    print "-.- done"
Example #13
0
 def __init__(self, api_key, channel_name):
     """Initialize the service."""
     from pushetta import Pushetta
     self._api_key = api_key
     self._channel_name = channel_name
     self.pushetta = Pushetta(self._api_key)
Example #14
0
# Save the file (locally) from post request in django views
destination = open('my_file.extension', 'wb+')
for chunk in request.FILES['file_key'].chunks():
    destination.write(chunk)
destination.close()

# ---------------------------------------------------------------------------- #

from django.core.files import File  # This is to save the raw file in models
my_file = open('file.extension', 'rb')
my_new_record = ModelName(field1='',
                          file_field=File(my_file),
                          field2=request.data['key'])
# File class helps to store file in django db
my_new_record.save()  # Save the new record in database
my_file.close()

# ---------------------------------------------------------------------------- #

# Send notifications on android mobile using third party app Pushetta
# pip install pushetta
from pushetta import Pushetta

api_key = ""
channel_name = ""
p = Pushetta(api_key)
msg = 'Hey there, Android! I am Python here.'
p.pushMessage(channel_name, msg)
# ---------------------------------------------------------------------------- #