Exemplo n.º 1
0
 def notify(self):
     self.hold = self.window_size
     offender = self.offender
     notify_send(
         "Memory warning",
         f"{offender.name()} [{offender.pid}] is taking too\
         much memory ({offender.memory_full_info().uss / 1024 / 1024} MBs)")
Exemplo n.º 2
0
def notify(d):
    title = "Github Notification"
    message, type_found = tostring(d)
    private = not d["public"]
    if not type_found:
        pprint(d)
    print(title + " - Private" if private else title)
    print(message + "\n")
    sh.notify_send(title, message, urgency="normal" if private else "low")
Exemplo n.º 3
0
def notify(d):
	title = "Github Notification"
	message, type_found = tostring(d)
	private = not d["public"]
	if not type_found:
		pprint(d)
	print(title + " - Private" if private else title)
	print(message + "\n")
	sh.notify_send(title, message, urgency="normal" if private else "low")
 def poll_status(self):
     for service in self.services:
         try:
             sudo.systemctl("is-active",
                            "openvpn@%s.service" % service).wait()
             service_status = "Connected to %s" % service
         except ErrorReturnCode:
             service_status = "Disconnected from %s" % service
         if self.status.get(service) != service_status:
             notify_send(service_status).wait()
         self.status[service] = service_status
     self.setToolTip("\n".join(self.status.values()))
Exemplo n.º 5
0
def core(coin: str, fiat: str, amount: float, reverse: bool, clipboard: bool, verbose: bool, timer: bool,
         wordform: bool, no_cache: bool):
    """
    Converts a cryptocurrency amount to a fiat equivalent or vice-versa

    Valid fiat currency values are: "AUD", "BRL", "CAD", "CHF", "CLP", "CNY", "CZK",
    "DKK", "EUR", "GBP", "HKD", "HUF", "IDR", "ILS", "INR", "JPY", "KRW", "MXN","MYR", "NOK",
    "NZD", "PHP", "PKR", "PLN", "RUB", "SEK", "SGD", "THB", "TRY","TWD", "ZAR"
    Valid cryptocurrency values are: "BTC", "ETH" "XRP", "LTC", and "BCH"

    `c2f btc usd 50`
    Translates to: What is 50 BTC worth in USD?

    `c2f btc usd 50 --reverse`
    Translates to: What is $50 USD worth in BTC?
    """
    util_setup(logger, timer, enabled_=True)
    with MeasureBlockTime("Main block"):
        if verbose:
            logzero.loglevel(logging.DEBUG)

        data_parser = DataParser(no_cache=no_cache)
        fiat = fiat.upper()
        coin = coin.upper()

        try:
            if reverse:
                if wordform:
                    click.echo(f"What is ${amount:.2f} {fiat} worth in {coin}?")
                quantity = data_parser.convert_to_crypto(fiat.upper(), coin.upper(), amount)
                formatted_quantity = "{:.8f}".format(quantity)

                print(formatted_quantity)
            else:
                if wordform:
                    click.echo(f"How much is {amount} {coin} in {fiat}?")
                quantity = data_parser.convert_to_fiat(fiat.upper(), coin.upper(), amount)
                formatted_quantity = "{:,.2f}".format(quantity)
                print(formatted_quantity)

            if clipboard:
                pyperclip.copy(formatted_quantity)
                sh.notify_send(APP_NAME, f"{formatted_quantity} copied to clipboard")
        except Exception as e:
            logger.exception(e)
Exemplo n.º 6
0
def set_profile(profile):
    global _current_profile

    print 'Setting current profile to', profile
    if isinstance(profile, basestring):
        if profile in _profiles:
            _current_profile = profile
            _profiles[profile]()
        else:
            print 'WARNING: Profile not found:', profile
            return
    else:
        _current_profile = reverse_lookup_profile(profile)
        profile()

    with open(_profile_store, 'w') as f:
        f.write(_current_profile)

    if not SIMULATE:
        notify_send("Profile Changed",
                    "Profile set to '%s'." % _current_profile,
                    icon="input-tablet",
                    expire_time=2000)
Exemplo n.º 7
0
def set_profile(profile):
    global _current_profile

    print 'Setting current profile to', profile
    if isinstance(profile, basestring):
        if profile in _profiles:
            _current_profile = profile
            _profiles[profile]()
        else:
            print 'WARNING: Profile not found:', profile
            return
    else:
        _current_profile = reverse_lookup_profile(profile)
        profile()

    with open(_profile_store, 'w') as f:
        f.write(_current_profile)

    if not SIMULATE:
        notify_send("Profile Changed",
                    "Profile set to '%s'." % _current_profile,
                    icon="input-tablet",
                    expire_time=2000)
Exemplo n.º 8
0

print("Started ({})".format(time.strftime("%Y-%m-%d %H:%M:%S")))

while True:
	try:
		res = requests.get("https://api.twitch.tv/kraken/streams/followed?limit=50", headers=headers).json()
		if 'streams' in res:
			online = res['streams']
		else:
			print(res)
			time.sleep(delay)
			continue
	except json.JSONDecodeError as e:
		print(e)
		sh.notify_send("Twitch", str(e), urgency="low")
		time.sleep(delay)
		continue
	except requests.exceptions.ConnectionError as e:
		print(e)
		time.sleep(delay)
		continue
	for channel in online:
		game = channel["game"]
		username = channel["channel"]["name"]
		display = channel["channel"]["display_name"]
		# print(game, username, display)
		if username in data["data"]:
			if data["data"][username]["notify"] and data["data"][username]["last_processed"] < time.time() - delay * 5:
				tobenotified.append(display)
			data["data"][username]["last_processed"] = time.time()
Exemplo n.º 9
0
#!/usr/bin/env python

# vim: set noet sw=4 ts=4:

import socket
import sys

from sh import notify_send

ip = socket.gethostbyname_ex('raylu.net')[2][0]
addr = (ip, 61221)
s = socket.create_connection(addr)
while True:
	data = s.recv(1024)
	print('sending', data)
	notify_send(data, t=5000)
Exemplo n.º 10
0
from os.path import splitext, abspath, basename, dirname, isfile
from sh import zenity, notify_send


new = ""
message = ""

i = 0
for f in argv[1:]:
    if "file://" in f:
        f = unquote(f)[7:]

    fdir = dirname(abspath(f))
    name,ext = splitext(f)

    if new == "":
       new = zenity("--text", "Rename", "--entry", "--entry-text", basename(name)).strip()

    try:
        while True:
            i = i + 1
            new_name = "%s/%s %s%s" % (fdir, new, i, ext)
            if not isfile(new_name):
                break

        rename(f, new_name)
        message = "%s%s → %s\n" % (message, f, new_name)
    except Exception as e:
        notify_send("Error", "-u", "critical", e)

notify_send("Renamed", message)
 def disconnect_vpn(self, service):
     try:
         sudo.systemctl.stop("openvpn@%s.service" % service).wait()
     except ErrorReturnCode:
         notify_send("Failed to disconnect %s" % service).wait()
         traceback.print_exc()
 def connect_vpn(self, service):
     try:
         sudo.systemctl.restart("openvpn@%s.service" % service).wait()
     except ErrorReturnCode:
         notify_send("Failed to connect to %s" % service)
         traceback.print_exc()
Exemplo n.º 13
0
    return "'{}'".format(d["type"]), False


def notify(d):
    title = "Github Notification"
    message, type_found = tostring(d)
    private = not d["public"]
    if not type_found:
        pprint(d)
    print(title + " - Private" if private else title)
    print(message + "\n")
    sh.notify_send(title, message, urgency="normal" if private else "low")


print("Started ({})".format(time.strftime("%Y-%m-%d %H:%M:%S")))
sh.notify_send('github_notifier started', urgency="low")
while True:
    headers = {
        "Accept": "application/vnd.github.v3+json",
        "Authorization": auth
    }
    if etag:
        headers["If-None-Match"] = etag
    try:
        r = requests.get("https://api.github.com/users/" + cfg["username"] +
                         "/received_events",
                         headers=headers)
    except requests.exceptions.ConnectionError as e:
        print(e)
        time.sleep(60)
        continue
Exemplo n.º 14
0
from os.path import splitext, abspath, basename, dirname, isfile
from sh import zenity, notify_send

new = ""
message = ""

i = 0
for f in argv[1:]:
    if "file://" in f:
        f = unquote(f)[7:]

    fdir = dirname(abspath(f))
    name, ext = splitext(f)

    if new == "":
        new = zenity("--text", "Rename", "--entry", "--entry-text",
                     basename(name)).strip()

    try:
        while True:
            i = i + 1
            new_name = "%s/%s %s%s" % (fdir, new, i, ext)
            if not isfile(new_name):
                break

        rename(f, new_name)
        message = "%s%s → %s\n" % (message, f, new_name)
    except Exception as e:
        notify_send("Error", "-u", "critical", e)

notify_send("Renamed", message)
Exemplo n.º 15
0
	for pname in blocking:
		try:
			sh.pgrep(pname)
			blocked = True
			if len(tobenotified) > 0:
				print("{} notifications blocked by {}".format(len(tobenotified), pname))
			break
		except sh.ErrorReturnCode_1:
			pass
	for pname in required:
		try:
			sh.pgrep(pname)
		except sh.ErrorReturnCode_1:
			blocked = True
			print(pname, "required")
			break

	if not blocked and tobenotified:
		for elem in tobenotified:
			notify(elem)
		tobenotified = []
	if not blocked and not notified_start:
		sh.notify_send('github_notifier started', urgency="low")
		notified_start = True

	etag = r.headers["etag"]
	try:
		time.sleep(int(r.headers["x-poll-interval"]))
	except KeyboardInterrupt:
		exit()