Пример #1
0
def notifyusers(title, msgtext, msgpriority):
  idx = 0;
  app = Application(get_appapikey())
  print ('Application authenticated OK: ',(app.is_authenticated))
  if(app.is_authenticated):
    usertokens, devices, friendname = listusers()
    for usertoken in usertokens:
      user = app.get_user(usertoken)
      if(user.is_authenticated):
        print(user, 'authenticated OK')
        message = user.create_message(msgtext,
          # sound = 'incoming', # uncomment for alternate sound, leave for default
          title = title,
          device = devices[idx],
          priority = msgpriority,
          html = False
        );
        message.send()
        print('Sent: ', message.is_sent, ' ID: ',message.id, ' User: '******'fail: ', user, '/', friendname[idx])
      idx += 1
    print('Users notified: ', idx)
    print('Quota: ', app.remaining, '/', app.limit)
  else:
    print('App could not authenticate')
Пример #2
0
    def send(self, type, text, raw):
        self.msg_to_send = text

        if check_time_restriction(self.starttime, self.endtime):
            if not have_chump:
                raise Exception('Missing Pushover library: chump - install using pip')

            app = Application(self.token)
            if app.is_authenticated:
                user = app.get_user(self.user_key)

                if user_is_authenticated(user):
                    message = user.create_message(
                        title=self.title,
                        message=self.msg_to_send,
                        html=True,
                        priority=self.priority,
                        timestamp=int(time.time())
                    )

                    is_sent = message.send()

                    if is_sent != True:
                        current_app.logger.info("Pushover Notification Failed")
                        raise Exception('Pushover Notification Failed')
                else:
                    current_app.logger.info("Pushover Notification Failed - bad user key: " + self.user_key)
                    raise Exception("Pushover Notification Failed - bad user key: " + self.user_key)

            else:
                current_app.logger.info("Pushover Notification Failed - bad application token: " + self.token)
                raise Exception("Pushover Notification Failed - bad application token: " + self.token)
Пример #3
0
def hunt(check_interval):
    pushover_app = Application(PUSHOVER_APP_SECRET)
    pushover_user = pushover_app.get_user(PUSHOVER_USER_SECRET)

    reddit = praw.Reddit(client_id=REDDIT_CLIENT_ID,
                         client_secret=REDDIT_CLIENT_SECRET,
                         user_agent=REDDIT_USER_AGENT)

    subreddit = reddit.subreddit('buildapcsales')
    min_delta = datetime.utcnow() - timedelta(minutes=check_interval)

    filtered_subs = [
        x for x in subreddit.new(limit=25)
        if datetime.utcfromtimestamp(x.created_utc) >= min_delta
        and "GPU" in x.title
    ]

    if filtered_subs:
        response_msg = ""
        for sub in filtered_subs:
            response_msg += "\n<a href=\"" + sub.shortlink + "\">" + sub.title + "</a>"

        if response_msg:
            push_notification = pushover_user.send_message(
                title="New GPU for sale",
                message=response_msg,
                html=True,
                sound='gamelan')
Пример #4
0
def SendNotice(Message):

    try:
        app = Application(appid)

        if not app.is_authenticated:
            log.error("Unable to authenticate app ID")
            return False

        user = app.get_user(userid)

        if not user.is_authenticated:
            log.error("Unable to authenticate user ID")
            return False

        message = user.create_message(message=Message, sound=pushsound)

        message.send()

        console.info(message.id)
        return True
    except Exception as e1:
        log.error("Send Notice Error: " + GetErrorLine() + ": " + str(e1))
        console.error("Send Notice Error: " + str(e1))
        return False
Пример #5
0
    def send(self, type, text, raw):
        self.msg_to_send = text

        if check_time_restriction(self.starttime, self.endtime):
            if not have_chump:
                raise Exception('Missing Pushover library: chump - install using pip')

            app = Application(self.token)
            if app.is_authenticated:
                user = app.get_user(self.user_key)

                if user_is_authenticated(user):
                    message = user.create_message(
                        title=self.title,
                        message=self.msg_to_send,
                        html=True,
                        priority=self.priority,
                        timestamp=int(time.time())
                    )

                    is_sent = message.send()

                    if is_sent != True:
                        current_app.logger.info("Pushover Notification Failed")
                        raise Exception('Pushover Notification Failed')
                else:
                    current_app.logger.info("Pushover Notification Failed - bad user key: " + self.user_key)
                    raise Exception("Pushover Notification Failed - bad user key: " + self.user_key)

            else:
                current_app.logger.info("Pushover Notification Failed - bad application token: " + self.token)
                raise Exception("Pushover Notification Failed - bad application token: " + self.token)
Пример #6
0
    def notify(self, title, text, url=None):
        app = Application(self.application_id)
        user = app.get_user(self.user_id)

        message = user.send_message(message=text,
                                    title=title,
                                    url=url)
Пример #7
0
    def notify(self, title, text, url=None):
        app = Application(self.application_id)
        user = app.get_user(self.user_id)

        message = user.send_message(message=text,
                                    title=title,
                                    url=url,
                                    priority=self.priority)
Пример #8
0
    def send_notification(self, notification_message):
        app = Application(self.config["app_key"])
        user = app.get_user(self.config["user_key"])
        message = user.send_message(notification_message)

        if message.is_sent:
            self.log.info("Pushover message sent successfully")
        else:
            self.log.error("Pushover message not sent")
Пример #9
0
    def __init__(self, cfg: Configuration):
        super().__init__(cfg)

        pushover_cfg = cfg[PUSHOVER_CONFIG_KEY]
        apiToken = pushover_cfg["apiToken"]
        userKey = pushover_cfg["userKey"]

        application = Application(apiToken)
        self.__user = application.get_user(userKey)
Пример #10
0
def po(msg):
    app = Pushover(os.getenv('PUSHOVER_APP', False))
    if app.is_authenticated == True:
        user = app.get_user(os.getenv('PUSHOVER_USER', False))
        if user.is_authenticated == True:
            message = user.send_message(msg)
            return True

    return False
Пример #11
0
    def send_notification(self, notification_message):
        app = Application(self.config['app_key'])
        user = app.get_user(self.config['user_key'])
        message = user.send_message(notification_message)

        if message.is_sent:
            self.log.info("Pushover message sent successfully")
        else:
            self.log.error("Pushover message not sent")
Пример #12
0
    def check_requirements(self):
        app = Application(self.application_id)

        try:
            user = app.get_user(self.user_id)
            if not user.is_authenticated:
                raise ValueError("User could not be authenticated")
        except Exception as ex:
            _logger.error("Cannot connect to your Pushover account. "
                          "Correct your config and try again. Error details:")
            _logger.error(ex)
            raise
        _logger.info("Pushover server check passed")
Пример #13
0
def arp_display(pkt):
	if pkt[ARP].op == 1: #who-has (request)
	  if pkt[ARP].psrc == '0.0.0.0': #ARP Probe
	    if pkt[ARP].hwsrc == '74:75:48:__fill in unique MAC Add__': #ELEMENTS
	      app = Application('a    ---app id here---         b')
	      user = app.get_user('u   ---user id here    ---   W')
	      message = user.create_message("Ding-Dong The Mail Is Here!")
	      app.is_authenticated
	      user.is_authenticated, user.devices
	      message.is_sent, message.id
	      message.send()
	      message.is_sent, message.id, str(message.sent_at)
	      os.system('aplay bluesclues-mailtime.wav')
Пример #14
0
def arp_display(pkt):
    if pkt[ARP].op == 1:  #who-has (request)
        if pkt[ARP].psrc == '0.0.0.0':  #ARP Probe
            if pkt[ARP].hwsrc == '74:75:48:__fill in unique MAC Add__':  #ELEMENTS
                app = Application('a    ---app id here---         b')
                user = app.get_user('u   ---user id here    ---   W')
                message = user.create_message("Ding-Dong The Mail Is Here!")
                app.is_authenticated
                user.is_authenticated, user.devices
                message.is_sent, message.id
                message.send()
                message.is_sent, message.id, str(message.sent_at)
                os.system('aplay bluesclues-mailtime.wav')
Пример #15
0
    def check_requirements(self):
        app = Application(self.application_id)

        try:
            user = app.get_user(self.user_id)
            if not user.is_authenticated:
                raise ValueError("User could not be authenticated")
        except Exception as ex:
            _logger.error("Cannot connect to your Pushover account. "
                          "Correct your config and try again. Error details:")
            _logger.error(ex)
            raise
        _logger.info("Pushover server check passed")
Пример #16
0
def SendNotice(Message):

    try:
        app = Application(appid)
        user = app.get_user(userid)

        message = user.create_message(message=Message, sound=pushsound)

        message.send()

        print(message.id)

    except Exception as e1:
        log.error("Error: " + str(e1))
        print("Error: " + str(e1))
Пример #17
0
    def run(self):
        self.logger.info("Starting Pushover Interface")
        try:
            self.app = Application(cfg.PUSHOVER_APPLICATION_KEY)
            if not self.app.is_authenticated:
                raise Exception('Failed to authenticate with Pushover. Please check PUSHOVER_APPLICATION_KEY')

            while True:
                item = self.queue.get()
                if item[1] == 'notify':
                    self.handle_notify(item[2])
                elif item[1] == 'command':
                    if item[2] == 'stop':
                        break
        except Exception:
            self.logger.exception("Pushover")
Пример #18
0
class PushoverInterface(Interface):
    """Interface Class using Pushover"""
    name = 'pushover'

    def __init__(self):
        super().__init__()

        self.logger = logging.getLogger('PAI').getChild(__name__)
        self.app = None
        self.users = {}

    def run(self):
        self.logger.info("Starting Pushover Interface")
        try:
            self.app = Application(cfg.PUSHOVER_APPLICATION_KEY)
            if not self.app.is_authenticated:
                raise Exception('Failed to authenticate with Pushover. Please check PUSHOVER_APPLICATION_KEY')

            while True:
                item = self.queue.get()
                if item[1] == 'notify':
                    self.handle_notify(item[2])
                elif item[1] == 'command':
                    if item[2] == 'stop':
                        break
        except Exception:
            self.logger.exception("Pushover")

    def stop(self):
        """ Stops the Pushover interface"""
        self.queue.put_nowait(SortableTuple((2, 'command', 'stop')))

    def notify(self, source, message, level):
        self.queue.put_nowait(SortableTuple((2, 'notify', (source, message, level))))

    def handle_notify(self, raw):
        sender, message, level = raw
        if level < logging.INFO:
            return

        for user_key, devices_raw in cfg.PUSHOVER_BROADCAST_KEYS.items():
            user = self.users.get(user_key)

            if user is None:
                user = self.users[user_key] = self.app.get_user(user_key)

            if not user.is_authenticated:
                raise Exception(
                    'Failed to check user key with Pushover. Please check PUSHOVER_BROADCAST_KEYS[%s]' % user_key)

            if devices_raw == '*' or devices_raw is None:
                user.send_message(message, title='Alarm')
            else:
                devices = list(filter(bool, re.split('[\s]*,[\s]*', devices_raw)))

                for elem in (elem for elem in devices if elem not in user.devices):
                    self.logger.warning('%s is not in the Pushover device list for the user %s' % (elem, user_key))

                for device in devices:
                    user.send_message(message, title='Alarm', device=device)
Пример #19
0
def main():
    reddit = praw.Reddit('bot1')
    subreddit = reddit.subreddit('mechmarket')

    config = configparser.ConfigParser()
    config.read("pushover.ini")
    app = Application(config.get('Pushover', 'app_key'))  # app token
    user = app.get_user(config.get('Pushover', 'user_key'))  # user token

    item = 'HHKB'
    low = 0
    high = 250

    for submission in subreddit.stream.submissions():

        l = process_submission(submission, item, low, high)
        if l[0]:
            message = user.send_message(title=l[1],
                                        message=l[2],
                                        url=l[3],
                                        url_title='Open Reddit',
                                        html=True,
                                        sound='cosmic')
Пример #20
0
    GPIO.setup(PIR_PIN_3, GPIO.IN)
if PIR_PIN_4_PRIORITY != 9:
    GPIO.setup(PIR_PIN_4, GPIO.IN)

# log GPIO pins set up
TText = "PIR GPIO pins set up: 1 = " + str(PIR_PIN_1_PRIORITY) + " 2 = " + str(
    PIR_PIN_2_PRIORITY) + " 3 = " + str(PIR_PIN_3_PRIORITY) + " 4 = " + str(
        PIR_PIN_4_PRIORITY)
SENDTOLOG(TText)

# log starting to setup Pushover
SENDTOLOG("Setting up Pushover")

# Setup Pushover connection
# install APP API Key
app = Application(AppKey)
AppKeyStatus = "%s - APP is authenticated" % app.is_authenticated
SENDTOLOG(AppKeyStatus)

# connect APP to user Key
user = app.get_user(UserKey)
UserKeyStatus = "User is authenticated - %s the device is a %s" % (
    user.is_authenticated, user.devices)
SENDTOLOG(UserKeyStatus)

#let everything (electronics) stabalise
time.sleep(2)

SENDTOLOG("Night Watchman is On Duty (CTRL+C to exit)")

#main loop
Пример #21
0
    def run(self):

        # Log a run
        logging.info("Executing Follow Garbage Collector.")

        # Setting for PushOver
        self.appPushover = Application(self.pushover_token_api)
        self.userPushover = self.appPushover.get_user(self.pushover_user_key)

        try:
            # This time we want to set our q to search for our keywords
            self.twitter = Twython(
                self.twitter_app_key,
                self.twitter_app_secret,
                self.twitter_oauth_token,
                self.twitter_oauth_token_secret,
            )

            friends = self.twitter.get_friends_ids()

            for friend in friends["ids"]:

                user_timeline = self.twitter.get_user_timeline(user_id=friend,
                                                               count=1)

                for tweet in user_timeline:

                    diffDate = datetime.now() - \
                        self.datetime_from_utc_to_local(
                            self.tweetdatetime_to_datetime_utc(
                                tweet["created_at"]))

                    if diffDate.days >= 365 * self.twitter_years_inactive:

                        tweetDate = datetime.strftime(
                            self.datetime_from_utc_to_local(
                                self.tweetdatetime_to_datetime_utc(
                                    tweet["created_at"])),
                            "%Y-%m-%d %H:%M:%S",
                        )

                        if (not tweet["user"]["screen_name"]
                                in self.twitter_excluded_tweeps):

                            if self.twitter_unfollow:
                                self.twitter.destroy_friendship(user_id=friend)

                            self.message = self.userPushover.send_message(
                                message=f'Flushed @'
                                f'{tweet["user"]["screen_name"]} '
                                f'- {tweet["user"]["name"]}\n{tweetDate}\n'
                                f'{tweet["text"]}',
                                sound=self.pushover_sound)

                            # Log a flush
                            logging.info(
                                f'Flushed @'
                                f'{tweet["user"]["screen_name"]} '
                                f'- {tweet["user"]["name"]} - {tweetDate}')

                    # trying not to upset the Twitter Gods
                    sleep(2)

        except TwythonError as e:
            print(e)
        f.close()
    else:
        f = open(currentIpFile, "w")
        f.write(ip)
        f.close()
    return old_ip

def storeCurrentIP(ip):
    f = open(currentIpFile, "w")
    f.write(public_ip)
    f.close()

try:
    #try and parse result, is it an IP address?
    IP(request_ip)
    public_ip = request_ip
except:
    print("no IP address retrieved") 
    public_ip = "127.0.0.1"

old_ip = getOldIP(public_ip)

if old_ip != public_ip:
    app = Application(AppToken)
    user = app.get_user(UserKey)
    message = user.create_message(title="IP Change", message="new IP address {}".format(public_ip), priority=1)
    message.send()
    storeCurrentIP(public_ip)


Пример #23
0
class Follow_Garbage_Collector():
    def __init__(self):

        logging.basicConfig(
            format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
            level=logging.INFO)

        self.config_file = "/config/Follow_Garbage_Collector.ini"

        try:
            with open(self.config_file, "r") as f:
                f.close()
            try:
                self.config = configparser.ConfigParser()
                self.config.read(self.config_file)

                self.twitter_app_key = self.config['TWITTER']['APP_KEY']
                self.twitter_app_secret = self.config['TWITTER']['APP_SECRET']
                self.twitter_oauth_token = \
                    self.config['TWITTER']['OAUTH_TOKEN']
                self.twitter_oauth_token_secret = \
                    self.config['TWITTER']['OAUTH_TOKEN_SECRET']
                self.twitter_unfollow = True if (
                    self.config['TWITTER']['UNFOLLOW'] == "ON") else False
                self.twitter_years_inactive = \
                    int(self.config['TWITTER']['YEARS_INACTIVE'])
                self.twitter_excluded_tweeps = list(
                    self.config['TWITTER']['EXCLUDED_TWEEPS'].split(","))

                self.pushover_user_key = self.config['PUSHOVER']['USER_KEY']
                self.pushover_token_api = self.config['PUSHOVER']['TOKEN_API']
                self.pushover_sound = self.config['PUSHOVER']['SOUND']

            except KeyError:
                logging.error("Can't get keys from INI file. "
                              "Please check for mistakes.")

                sys.exit()

        except IOError or FileNotFoundError:
            logging.error(f"Can't open file {self.config_file}, "
                          f"creating example INI file.")

            shutil.copyfile('/app/Follow_Garbage_Collector.ini.example',
                            '/config/Follow_Garbage_Collector.ini.example')
            sys.exit()

    # Convert UTC times to local times
    def datetime_from_utc_to_local(self, utc_datetime):
        now_timestamp = time()
        offset = datetime.fromtimestamp(
            now_timestamp) - datetime.utcfromtimestamp(now_timestamp)
        return utc_datetime + offset

    # convert a tweetdatetime to datetime_utc
    def tweetdatetime_to_datetime_utc(self, tweetDate):

        return self.datetime_from_utc_to_local(
            datetime.strptime(tweetDate, "%a %b %d %H:%M:%S +0000 %Y"))

    def run(self):

        # Log a run
        logging.info("Executing Follow Garbage Collector.")

        # Setting for PushOver
        self.appPushover = Application(self.pushover_token_api)
        self.userPushover = self.appPushover.get_user(self.pushover_user_key)

        try:
            # This time we want to set our q to search for our keywords
            self.twitter = Twython(
                self.twitter_app_key,
                self.twitter_app_secret,
                self.twitter_oauth_token,
                self.twitter_oauth_token_secret,
            )

            friends = self.twitter.get_friends_ids()

            for friend in friends["ids"]:

                user_timeline = self.twitter.get_user_timeline(user_id=friend,
                                                               count=1)

                for tweet in user_timeline:

                    diffDate = datetime.now() - \
                        self.datetime_from_utc_to_local(
                            self.tweetdatetime_to_datetime_utc(
                                tweet["created_at"]))

                    if diffDate.days >= 365 * self.twitter_years_inactive:

                        tweetDate = datetime.strftime(
                            self.datetime_from_utc_to_local(
                                self.tweetdatetime_to_datetime_utc(
                                    tweet["created_at"])),
                            "%Y-%m-%d %H:%M:%S",
                        )

                        if (not tweet["user"]["screen_name"]
                                in self.twitter_excluded_tweeps):

                            if self.twitter_unfollow:
                                self.twitter.destroy_friendship(user_id=friend)

                            self.message = self.userPushover.send_message(
                                message=f'Flushed @'
                                f'{tweet["user"]["screen_name"]} '
                                f'- {tweet["user"]["name"]}\n{tweetDate}\n'
                                f'{tweet["text"]}',
                                sound=self.pushover_sound)

                            # Log a flush
                            logging.info(
                                f'Flushed @'
                                f'{tweet["user"]["screen_name"]} '
                                f'- {tweet["user"]["name"]} - {tweetDate}')

                    # trying not to upset the Twitter Gods
                    sleep(2)

        except TwythonError as e:
            print(e)
Пример #24
0
def _send_pushover_summary(message, title):
    app = Application(get_env_variable("WORDSPEAK_PUSHOVER_API_TOKEN"))
    user = app.get_user(get_env_variable("WORDSPEAK_PUSHOVER_USER"))
    return user.send_message(message=message, title=title)
Пример #25
0
# Obtain our Pushover credentials from SSM
# We ask SSM to automatically handle decryption for us, as well.
ssm = boto3.client('ssm')
ssm_params = ssm.get_parameters_by_path(Path=SSM_PATH, WithDecryption=True)

# Convert the response from SSM into a dictionary for easy reference later on
pushover_params = {}
if 'Parameters' in ssm_params and len(ssm_params.get('Parameters')) > 0:
    # We actually have some parameters back from SSM
    for param in ssm_params.get('Parameters'):
        pushover_params[param.get('Name').split('/')[-1]] = param.get('Value')

# Create our Pushover API client, and test we're actually authenticated
# successfully (the API key is valid) and we're trying to route our request to
# a valid user/group key.
pushover = Application(pushover_params['AppKey'])
assert pushover.is_authenticated

user = pushover.get_user(pushover_params['UserKey'])
assert user.is_authenticated


### The real excitement starts here...
# In case anyone hits our API directly, give them a firm but friendly greeting.
@app.route('/')
def index():
    return Response(body='OK', status_code=200)


# We will be accepting SMS from Nexmo at this endpoint.
# The URL you need for your Nexmo dashboard will be output by Chalice deploy -
Пример #26
0
def scrape():

    push_app = Application("")
    push_User = push_app.get_user("")
    # message = push_User.send_message("Test MSG")

    sites = [
        "http://jungle-scs.co.jp/sale_en/?page_id=116&cat=313&vw=nk",
        "http://jungle-scs.co.jp/sale_en/?page_id=116&cat=383&vw=nk"
    ]

    siteURL = "http://jungle-scs.co.jp/sale_en/?page_id=116&cat=313&vw=nk"
    # localSite = "test.html"
    localURL = "Jungle.html"
    firstRun = True
    #

    # new_figures = []  # type: list[FigureData]
    old_figures = []  # type: list[FigureData]

    count = 1

    run = True
    while run:

        sys.stdout.write('\x1b[K')  # Clear the line
        print("Scraping Jungle... Scrape# " + str(count))
        count += 1

        siteHTML = requests.get(siteURL).text
        # soup = BeautifulSoup(siteHTML, 'html.parser')

        figures = Figures(Decoder.jungle, siteHTML).figures

        # localHTML = open(localURL, 'r', encoding='UTF8').read()
        # soup = BeautifulSoup(localHTML, 'html.parser')

        # product_soup = soup.find(id='products')

        if firstRun is False:
            # print("Number of figures: " + str(len(figures)))
            for figure in figures:
                figNew = True
                for oldFigure in old_figures:
                    if oldFigure.name == figure.name:
                        figNew = False

                if figNew:
                    message = push_User.send_message(
                        title="New Figure Availible",
                        message='<a href="' + figure.link + '">' +
                        figure.name + '</a>' + " in stock. Price: " +
                        figure.price + " Condition: " + figure.condition,
                        html=True,
                        url=figure.pic_link,
                        url_title="Picture")
                    logging.warning("Figure " + figure.name + " is new!")

                # if old_figures.count(figure) < 1:
                #     #  figure not found!!
                #     print("Figure " + figure.name + " is new!")

        old_figures[:] = figures[:]
        firstRun = False

        # Display a progress bar during sleep.
        sys.stdout.write('\x1b[K')  # Clear the line
        iterable = range(3 * 60 * 1000)
        with click.progressbar(iterable) as bar:
            for i in bar:  # wait 5 seconds before next request to avoid hammering web servers.
                time.sleep(0.001)
        sys.stdout.write('\x1b[2A')  # Move cursor up 2 lines

    input("Press enter to exit")
Пример #27
0
class PushoverInterface(Interface):
    """Interface Class using Pushover"""
    name = 'pushover'

    def __init__(self):
        super().__init__()

        self.logger = logging.getLogger('PAI').getChild(__name__)
        self.app = None
        self.users = {}

    def run(self):
        self.logger.info("Starting Pushover Interface")
        try:
            self.app = Application(cfg.PUSHOVER_APPLICATION_KEY)
            if not self.app.is_authenticated:
                raise Exception(
                    'Failed to authenticate with Pushover. Please check PUSHOVER_APPLICATION_KEY'
                )

            ps.subscribe(self.handle_panel_event, "events")
            ps.subscribe(self.handle_notify, "notifications")

            while True:
                item = self.queue.get()
                if item[1] == 'command':
                    if item[2] == 'stop':
                        break
        except Exception:
            self.logger.exception("Pushover")

    def stop(self):
        """ Stops the Pushover interface"""
        self.queue.put_nowait(SortableTuple((2, 'command', 'stop')))

    def notify(self, source, message, level):
        self.queue.put_nowait(
            SortableTuple((2, 'notify', (source, message, level))))

    def handle_notify(self, message):
        sender, message, level = message
        if level < EventLevel.INFO.value:
            return

        self.send_message(message)

    def handle_panel_event(self, event):
        """Handle Live Event"""

        if event.level < EventLevel.INFO.value:
            return

        major_code = event.major
        minor_code = event.minor

        # Only let some elements pass
        allow = False
        for ev in cfg.PUSHOVER_ALLOW_EVENTS:
            if isinstance(ev, tuple):
                if major_code == ev[0] and (minor_code == ev[1]
                                            or ev[1] == -1):
                    allow = True
                    break
            elif isinstance(ev, str):
                if re.match(ev, event.key):
                    allow = True
                    break

        # Ignore some events
        for ev in cfg.PUSHOVER_IGNORE_EVENTS:
            if isinstance(ev, tuple):
                if major_code == ev[0] and (minor_code == ev[1]
                                            or ev[1] == -1):
                    allow = False
                    break
            elif isinstance(ev, str):
                if re.match(ev, event.key):
                    allow = False
                    break

        if allow:
            self.send_message(event.message)

    def send_message(self, message):

        for user_key, devices_raw in cfg.PUSHOVER_BROADCAST_KEYS.items():
            user = self.users.get(user_key)

            if user is None:
                user = self.users[user_key] = self.app.get_user(user_key)

            if not user.is_authenticated:
                raise Exception(
                    'Failed to check user key with Pushover. Please check PUSHOVER_BROADCAST_KEYS[%s]'
                    % user_key)

            if devices_raw == '*' or devices_raw is None:
                user.send_message(message, title='Alarm')
            else:
                devices = list(
                    filter(bool, re.split('[\s]*,[\s]*', devices_raw)))

                for elem in (elem for elem in devices
                             if elem not in user.devices):
                    self.logger.warning(
                        '%s is not in the Pushover device list for the user %s'
                        % (elem, user_key))

                for device in devices:
                    user.send_message(message, title='Alarm', device=device)
Пример #28
0
from chump import Application
app = Application('a9acbhw54uvnfxr7k7s91duexphdfs')
app.is_authenticated
user = app.get_user('ujm7395t6eg57jwrcyjycm4vzr1i1a')
user.is_authenticated, user.devices
message = user.create_message(title="What's up, dog?",
                              message="hello",
                              html=True,
                              sound='intermission',
                              priority=2)
message.is_sent, message.id
message.send()
message.is_sent, message.id, str(message.sent_at)
Пример #29
0
def scrape():

    push_app = Application("")
    push_User = push_app.get_user("")
    # message = push_User.send_message("Test MSG")

    sites = ["http://jungle-scs.co.jp/sale_en/?page_id=116&cat=313&vw=nk",
             "http://jungle-scs.co.jp/sale_en/?page_id=116&cat=383&vw=nk"]

    siteURL = "http://jungle-scs.co.jp/sale_en/?page_id=116&cat=313&vw=nk"
    # localSite = "test.html"
    localURL = "Jungle.html"
    firstRun = True
    #

    # new_figures = []  # type: list[FigureData]
    old_figures = []  # type: list[FigureData]

    count = 1

    run = True
    while run:

        sys.stdout.write('\x1b[K')  # Clear the line
        print("Scraping Jungle... Scrape# " + str(count))
        count += 1

        siteHTML = requests.get(siteURL).text
        # soup = BeautifulSoup(siteHTML, 'html.parser')

        figures = Figures(Decoder.jungle, siteHTML).figures

        # localHTML = open(localURL, 'r', encoding='UTF8').read()
        # soup = BeautifulSoup(localHTML, 'html.parser')

        # product_soup = soup.find(id='products')

        if firstRun is False:
            # print("Number of figures: " + str(len(figures)))
            for figure in figures:
                figNew = True
                for oldFigure in old_figures:
                    if oldFigure.name == figure.name:
                        figNew = False

                if figNew:
                    message = push_User.send_message(
                        title="New Figure Availible",
                        message='<a href="' + figure.link + '">' + figure.name + '</a>' + " in stock. Price: " + figure.price + " Condition: " + figure.condition,
                        html=True,
                        url=figure.pic_link,
                        url_title="Picture"
                        )
                    logging.warning("Figure " + figure.name + " is new!")

                # if old_figures.count(figure) < 1:
                #     #  figure not found!!
                #     print("Figure " + figure.name + " is new!")

        old_figures[:] = figures[:]
        firstRun = False

        # Display a progress bar during sleep.
        sys.stdout.write('\x1b[K')  # Clear the line
        iterable = range(3 * 60 * 1000)
        with click.progressbar(iterable) as bar:
            for i in bar:  # wait 5 seconds before next request to avoid hammering web servers.
                time.sleep(0.001)
        sys.stdout.write('\x1b[2A')  # Move cursor up 2 lines

    input("Press enter to exit")