示例#1
0
def msgc(message: str, title: str = '', icon: str = ''):  ## {{{
    ## https://notify2.readthedocs.io/en/latest/#notify2.Notification.set_urgency
    ## also have a look at https://www.devdungeon.com/content/desktop-notifications-linux-python
    import notify2
    notify2.init('app name')
    n = notify2.Notification(str(message), str(title), icon)
    n.set_urgency(notify2.URGENCY_CRITICAL
                  )  ## URGENCY_CRITICAL, URGENCY_LOW & URGENCY_NORMAL
    n.show()
    notify2.uninit()
示例#2
0
 def __init__(self):
     notify2.uninit()
     notify2.init("sun")
     self.pkg_count = fetch()[0]
     self.message_added = ""
     self.summary = "{0}Software Updates".format(" " * 14)
     self.message = ("{0}{1} Software updates are available\n".format(
         " " * 3, self.pkg_count))
     self.icon = "{0}{1}.png".format(icon_path, __all__)
     self.n = notify2.Notification(self.summary, self.message, self.icon)
     self.n.set_timeout(60000 * int(config()["STANDBY"]))
示例#3
0
    def notify(self, message: str, msecs: int = 5000) -> None:
        """ Send a notification using a D-Bus connection.

        Args:
            message (str): The notice message to display
            msecs (int, optional): Delay to hide the notification, in milliseconds (default 5000)

        """
        notify2.init(self.APP_TITLE)
        notice = notify2.Notification(self.APP_TITLE, message, self.APP_ICON)
        notice.set_timeout(int(msecs))
        notice.show()
        notify2.uninit()
示例#4
0
    def screenshotVulnerability(self) -> None:
        """ Take a screenshot and save it in the vulnerability's directory.

        """
        if not os.path.isfile('/usr/bin/scrot'):
            self.statusBar().showMessage('Scrot is not installed!', msecs=5000)
            return

        self.statusBar().showMessage(
            f'A screenshot will be taken in {self.settings.value("global/delay")} seconds.',
            msecs=5000)

        time.sleep(int(self.settings.value('global/delay')))
        picture = self.currentVuln.takeScreenshot()

        if picture is None:
            self.statusBar().showMessage('Unable to take a screenshot',
                                         msecs=5000)
            return notify2.uninit()

        self.statusBar().showMessage(f'Screenshot saved in {picture}',
                                     msecs=5000)
        self.notify(f'Screenshot saved in {picture}')

        time.sleep(0.5)
        self.saveVulnerability()
        self.updateVulnerability()
示例#5
0
def initSystem():
    url = "https://api.covid19api.com/live/country/indonesia"
    response_data = requests.get(url).json()
    todayTime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

    for element in response_data:
        country = element['Country']
        confirm = element['Confirmed']
        death = element['Deaths']
        recovered = element['Recovered']
        #lastUpdate = element['Date']
    
    stringList = ['Country : ',country, '\n', 
                  'Confirmed : ',confirm, '\n',
                  'Death : ',death, '\n',
                  'Recovered : ',recovered, '\n',
                  'Time : ', todayTime, '\n',
                  'Visit this site for more information : ', infoURL
                 ]
    stringOutput = ''.join(str(i) for i in stringList )

    notify2.init("Covid19 Notification")
    notification = notify2.Notification("Covid19 Notification", stringOutput, "emblem-information")
    notification.set_urgency(2)
    notification.show()
    
while True:
    notify2.uninit()
    initSystem()
    time.sleep(timeInterval*60)
示例#6
0
def poll (users, send_notif = False):
    """
    Waits for updates of any of the users on the list

    Args:
        -> users: A list with all the usernames to get tweets from

        -> send_notif (optional): If True, also sends a notification on every new tweet
    """
    # Waits 60 seconds between every update
    sleep_time = 60
    logger = logging.getLogger ("Polling")

    info = {}
    notif_err = False

    if send_notif:
        if not notify2.init (notif_name):
            logger.error ("Error accessing DBus")
            notif_err = True

    del_items = []
    # Stores the current html and max_position
    for u in users:
        logger.info ("Getting initial data from '" + u + "'")
        info [u] = scraper.get_update_info (u)

        # If there has been some error fetching content, no updates can be done
        if not info [u]:
            logger.error ("No tweet from '" + u + "' couldn't be obtained")
            # Marks the item to be removed
            del_items.append (u)

    # Deletes all the marked items
    users = [ x for x in users if x not in del_items ]

    if len (info) <= 0:
        logger.error ("No available info to get updates")
        return

    while True:
        try:
            time.sleep (sleep_time)
            logger.info ("Polling, looking for updates at " + str (datetime.now ()))

            for u in users:
                update = scraper.get_new_tweets (u
                                                , info [u]["max_pos"]
                                                , info [u]["html"]
                    )

                if update:
                    # Prints the new tweet. The data is wrapped in a dictionary with the
                    # username as the key, because that's how 'print_tweets' expects it
                    print_tweets ( {u: update} )
                    # Updates also the stored info
                    info [u] = scraper.get_update_info (u)

                    if send_notif and not notif_err:
                        title = "New tweet from @" + u
                        msg =  format_tweet (update.values ()[0] ["text"]
                                            , add_tabs = False
                                            , strip = True
                                )

                        notif = notify2.Notification (title, msg, notif_icon)
                        notif.set_category (notif_type)
                        notif.set_urgency (notif_urgency)

                        notif.show ()
                        # Deletes the notification to avoid conflicts with the next ones
                        del notif

            logger.info ("Poll done\n")

        except KeyboardInterrupt:
            logger.info ("Interrupt caught while polling. Cleaning data...")
            # Cleans everything
            notify2.uninit ()

            logger.info ("All done")
            break
示例#7
0
pick = [ x.decode() for x in menu.communicate(input=labels)[0].splitlines() ]

if len(pick) > 0 and args.umount:
    for x in pick:
        status = devs[x].umount()

        if status:
            safe.append(devs[x].label)
        else:
            fail.append(devs[x].label)

    if safe:
        notify2.init("Media")
        message = " - ".join(safe)
        safe_pop = notify2.Notification("Safe to remove", message, "")
        safe_pop.show()
        notify2.uninit()

    if fail:
        notify2.init("Media")
        message = " - ".join(fail)
        fail_pop = notify2.Notification("Failed", message, "")
        fail_pop.set_urgency(notify2.URGENCY_CRITICAL)
        fail_pop.show()
        notify2.uninit()

elif len(pick) == 1:
    devs[pick[0]].explore()

sys.exit(0)
示例#8
0
 def terminate(self):
     notify2.uninit()
示例#9
0
 def test_init_uninit(self):
     assert notify2.is_initted()
     self.assertEqual(notify2.get_app_name(), "notify2 test suite")
     
     notify2.uninit()
     assert not notify2.is_initted()
示例#10
0
    def test_init_uninit(self):
        assert notify2.is_initted()
        self.assertEqual(notify2.get_app_name(), "notify2 test suite")

        notify2.uninit()
        assert not notify2.is_initted()
示例#11
0
def notifier_close():
    if sys.platform == 'linux':
        import notify2
        notify2.uninit()