-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchrome_tabs.py
executable file
·53 lines (39 loc) · 1.37 KB
/
chrome_tabs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# fuck you python; why make it so hard to cleanly import from parent dir?
from os.path import dirname, abspath
import sys ; sys.path.insert(1, dirname(dirname(abspath(__file__))))
import math
import subprocess
import time
import fuckometer
def main(args):
fuckometer.init()
tabs = ChromeTabs(period=60)
tabs.loop() # run forever
class ChromeTabs(fuckometer.Factor):
"""How many tabs are open in Chrome?
Uses this extension, and one of the extension's scripts:
https://github.com/ToyKeeper/tab-counteroo
"""
path = 'chrome_tabs'
def fucks(self):
#return (self.raw - 10) * 2 / 3.0
return math.pow(max(1, self.raw - 10), 1/1.1)
def on_update(self):
if fuckometer.cfg.verbose:
print(self.text)
def update(self):
# getting the data is messy, so put it in another script
basedir = sys.path[1]
cmd = ('%s/%s' % (basedir, 'factors/chrome_tabs/tabsOpen.py'),)
try:
text = subprocess.check_output(cmd)
value = int(text)
self.raw = value
self.text = 'Chrome Tabs: %i' % (self.raw)
except subprocess.CalledProcessError:
now = time.strftime('%Y-%m-%d %H:%M:%S')
print('%s chrome_tabs.py: Error calling tabsOpen.py' % (now))
if __name__ == "__main__":
import sys
main(sys.argv[1:])