示例#1
0
def run(name: str):
    logging.debug('Running ' + name)
    if osinfo.is_win():
        subprocess.Popen([os.path.dirname(sys.executable) + '/' + name + '.exe'])
    elif osinfo.is_linux():
        subprocess.Popen([os.path.dirname(sys.executable) + '/' + name ])
    else:
        raise OSError(platform.system() + 'is not supported!')
示例#2
0
    def __init__(self):
        # self.setAttribute(QtCore.Qt.WA_TintedBackground)
        self.sites = site.get_sites_dict()

        log.info('Initializing SiteMonitor window')
        super().__init__()
        self.setupUi(self)

        self.setWindowTitle('SiteMonster - SiteMonitor')
        set_wnd_icon(self, 'logo.ico')

        self.timer = QtCore.QTimer()
        self.timer.setInterval(1000)
        self.timer.timeout.connect(self.check_sites_file)
        self.timer.start()

        self.fav_btn_example.hide()
        self.description_.hide()
        self.fav_only_checkbox.hide()
        self.settings_btn.hide()
        self.site_settings.hide()
        self.delete_site.hide()

        log.debug('Building sites list')
        if site.get_sites_dict().keys().__len__() > 0:
            for key in self.sites:
                if True:
                    self.fav_sites = QtWidgets.QPushButton(self.fav_container_)
                    self.fav_sites.setText('')
                    self.fav_sites.setObjectName(key)

                    self.fav_sites.setToolTip(key)
                    self.fav_sites.setToolTipDuration(20 * 100)

                    icon = QtGui.QIcon()
                    icon.addPixmap(QtGui.QPixmap(self.sites[key]['favicon']),
                                   QtGui.QIcon.Normal, QtGui.QIcon.Off)

                    self.fav_sites.setIcon(icon)
                    self.fav_sites.setIconSize(QtCore.QSize(24, 24))
                    self.fav_sites.setMaximumSize(QtCore.QSize(256, 32))
                    self.fav_sites.setMinimumSize(QtCore.QSize(24, 24))
                    self.fav_sites.clicked.connect(
                        self.make_get_site_info(key))

                    self.fav_container.addWidget(self.fav_sites)
                    if not self.sites[key]['favourite']:
                        self.fav_sites.hide()
            self.add_site_btn.hide()
            self.message_label.setText("Select a site from the list.")

        self.add_site_btn.clicked.connect(self.add_site_onclick)
        self.plus_site.clicked.connect(self.add_site_onclick)
        self.menu_btn.clicked.connect(self.menu_onclick)
        self.fav_only_checkbox.stateChanged.connect(self.filter)
        self.site_settings.clicked.connect(self.site_settings_onclick)
        self.delete_site.clicked.connect(self.site_delete)
        self.actionAbout.triggered.connect(self.about_onclick)
示例#3
0
 def check_sites_file(self):
     log.debug('Checking siteList.json for changes')
     if self.sites == site.get_sites_dict():
         pass
     else:
         self.timer.stop()
         self.window = SiteMonitor()
         self.window.setGeometry(self.geometry())
         self.window.show()
         self.close()
示例#4
0
def build_fail_actions(send_notification=True, play_sound=True) -> dict:
    """Generate fail actions dictionary.

    send_notifications - bool, if True send push notifications to PC (`send_notification` method in `app/notifications.py`).
    play_sound - bool, if True plays alarm sound on your PC to PC (`play_sound` method in `app/notifications.py`).

    """

    logging.debug('Generating fail_actions dict')

    return {'send_notification': send_notification, 'play_sound': play_sound}
示例#5
0
 def filter(self):
     log.debug('Filtering list of sites')
     state = self.fav_only_checkbox.checkState()
     tmp: int = 2
     for siteobj in self.fav_container_.children():
         if tmp > 0:
             tmp -= 1
             continue
         if not self.sites[siteobj.objectName()]["favourite"]:
             if state:
                 siteobj.hide()
             else:
                 siteobj.show()
示例#6
0
 def get_site_info():
     log.debug('Getting info about \'' + name + '\'')
     self.site = name
     self.message_label.setText('[SITENAME] info'.replace(
         '[SITENAME]', name))
     self.description_.show()
     self.url.setText(self.sites[name]['url'])
     self.setCursor(QtGui.QCursor(QtCore.Qt.BusyCursor))
     self.status.setText(
         "OK" if sites.check(self.sites[name]) else "OOPS")
     self.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
     self.site_settings.show()
     self.delete_site.show()
示例#7
0
def send_mac_os_notification(message: str):
    """Send macOS push notification."""

    logging.debug('Sending macos push notification')

    if not osinfo.is_mac_os():
        logging.error('Trying to send macOS notification not from macOS!')
        raise OSError('MacOS notifications can be sent only from MacOS!')
    if appinfo.APP_ICON is not None:
        os.system(
            'terminal-notifier -title "{}" -subtitle "" -message "{}" -appIcon "{}"'
            .format(appinfo.APP_NAME, message, appinfo.APP_ICON))
    else:
        os.system(
            'terminal-notifier -title "{}" -subtitle "" -message "{}"'.format(
                appinfo.APP_NAME, message))
示例#8
0
def send_linux_notification(message: str):
    """Send linux libnotify notification."""

    logging.debug('Sending linux libnotify notification')

    if not osinfo.is_linux():
        logging.error('Trying to send linux notification not from linux!')
        raise OSError(
            'Linux libnotify notifications can be sent only from linux-based OS!'
        )
    if appinfo.APP_ICON is not None:
        os.system(
            'notify-send "{}" "{}" --icon="{}" --expire-time=30000'.format(
                appinfo.APP_NAME, message, os.path.abspath(appinfo.APP_ICON)))
    else:
        os.system('notify-send "{}" "{}" --expire-time=30000'.format(
            appinfo.APP_NAME, message))
示例#9
0
def send_windows_notification(message: str):
    """Send windows 10 toast notification."""

    logging.debug('Sending windows 10 toast notification')

    if not osinfo.is_win():
        logging.error('Trying to send win10 notification not from win10!')
        raise OSError(
            'Windows toast notifications can be sent only from Windows 10!')

    import win10toast

    toaster = win10toast.ToastNotifier()
    toaster.show_toast(appinfo.APP_NAME,
                       message,
                       icon_path=appinfo.APP_ICON,
                       duration=5,
                       threaded=True)
示例#10
0
 def continue_f(self):
     if len(self.name.text()) > 3:
         if self.name.text() not in site.get_sites_dict().keys():
             if len(self.url.text()) > 2:
                 log.debug(
                     'Opening SiteSettings window for just created site \''
                     + self.name.text() + '\'')
                 site.add(self.name.text(), self.url.text(),
                          site.build_settings())
                 self.hide()
         else:
             QtWidgets.QMessageBox.information(self, 'Message',
                                               'Name must be unique',
                                               QtWidgets.QMessageBox.Ok,
                                               QtWidgets.QMessageBox.Ok)
     else:
         QtWidgets.QMessageBox.information(
             self, 'Message', 'Name must be at least 4 characters long',
             QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok)
示例#11
0
def build_settings(method='GET', headers=None, body='', proxy=None, expected_code=None, expected_answer=None,
                   fail_actions=None) -> dict:
    """Generate settings dictionary.

    method - string, HTTP method which with send request to check website availability.
    headers - dictionary or NoneType, HTTP request headers.
    body - string, HTTP request body.
    proxy - dictionary or NoneType, proxies which will be used to send HTTP request.
    expected_code - list of int or NoneType, expected HTTP status code (More info: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes), if None - accept any from 200 to 299.
    expected_answer - string or NoneType, expected response body, if None - accept any.
    fail_actions - dict or NoneType, what do if site is unavailable, generate with `build_fail_actions` method.

    """

    logging.debug('Generating settings dict')

    if fail_actions is None:
        fail_actions = build_fail_actions()

    return {'method': method, 'headers': headers, 'body': body, 'proxy': proxy, 'expected_code': expected_code,
            'expected_answer': expected_answer, 'fail_actions': fail_actions}
示例#12
0
 def start_btn_onclick(self):
     log.debug('Opening Monitor window')
     self.window = SiteMonitor()
     self.window.setGeometry(self.geometry())
     self.window.show()
     self.close()
示例#13
0
    def __init__(self, data=None):
        log.info('Initializing SiteSettings window')
        super().__init__()
        if data is None:
            data = {}
        self.setupUi(self)

        set_wnd_icon(self, 'settings.png')

        self.quit.clicked.connect(self.exit)
        self.save.clicked.connect(self.save_all)
        self.file_open.clicked.connect(self.open_icon)

        self.site_name = data['site_name']
        self.setWindowTitle('Settings: ' + self.site_name)
        self.header.setText(self.header.text().replace('[SITENAME]',
                                                       self.site_name))

        website = site.get_sites_dict()[self.site_name]

        log.debug('Getting site settings')

        text = website['settings']['method']
        self.http_method.setText(text)

        text = website['settings']['headers']
        if text is None:
            text = dict()
        self.http_headers.setText(json.dumps(text))

        text = website['settings']['body']
        self.http_body.setPlainText(text)

        text = website['settings']['proxy']
        if text is None:
            text = {'http': '', 'https': ''}
        self.http_proxy.setText(text['http'])
        self.https_proxy.setText(text['https'])

        text = website['settings']['expected_code']
        if text is None:
            text = [200, 201, 202, 203, 204, 205, 206, 207, 208, 226]
        self.http_codes.setText(','.join(str(i) for i in text))

        text = website['settings']['expected_answer']
        if text is None:
            text = ''
        self.expected.setText(text)

        text = website['favourite']
        if text is None:
            text = False
        self.favourite.setChecked(text)

        text = website['favicon']
        self.icon_path = text

        self.notification.setChecked(
            website['settings']['fail_actions']['send_notification'])
        self.sound.setChecked(
            website['settings']['fail_actions']['play_sound'])

        self.text_edits = [
            self.http_method, self.http_headers, self.http_body,
            self.http_proxy, self.https_proxy, self.http_codes, self.expected,
            self.notification, self.sound, self.favourite
        ]