power menu, redshift, polybar
This commit is contained in:
26
.config/polybar/scripts/notification-xkcd/README.md
Normal file
26
.config/polybar/scripts/notification-xkcd/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Script: notification-xkcd
|
||||
|
||||
Displays the current xkcd comic and whether there are any new ones in polybar, written in python.
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
## Dependencies
|
||||
|
||||
* [`Python: requests`](https://pypi.org/project/requests/)
|
||||
|
||||
|
||||
## Configuration
|
||||
|
||||
To set the icon or the location of the save file, edit `icon` or `latest_file` in `notification-xkcd.py`. Note that you cannot use `~` to indicate your home directory, as python needs a full path by default.
|
||||
|
||||
## Module
|
||||
|
||||
```ini
|
||||
[module/notification-xkcd]
|
||||
type = custom/script
|
||||
exec = ~/polybar-scripts/notification-xkcd.py
|
||||
click-left = xdg-open https://xkcd.com/ && ~/polybar-scripts/notification-xkcd.py read
|
||||
interval = 60
|
||||
```
|
||||
59
.config/polybar/scripts/notification-xkcd/notification-xkcd.py
Executable file
59
.config/polybar/scripts/notification-xkcd/notification-xkcd.py
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
from sys import argv
|
||||
|
||||
latest_file = "/home/user/polybar-scripts/notification-xkcd-latest"
|
||||
icon = "#"
|
||||
|
||||
|
||||
read = False
|
||||
if len(argv) > 1:
|
||||
if argv[1] == "read":
|
||||
read = True
|
||||
|
||||
|
||||
def useFile(doc, mode, write):
|
||||
f = open(doc, mode)
|
||||
if mode == 'r':
|
||||
doc = f.read()
|
||||
f.close()
|
||||
return doc
|
||||
else:
|
||||
f.write(write)
|
||||
f.close()
|
||||
|
||||
try:
|
||||
latest = int(useFile(latest_file, 'r', '')[0:4])
|
||||
except FileNotFoundError:
|
||||
useFile(latest_file, 'x', "2350")
|
||||
latest = 2350
|
||||
|
||||
newComic = False
|
||||
while True:
|
||||
try:
|
||||
status = requests.get('https://www.xkcd.com/' + str(latest + 1) + '/').status_code
|
||||
except requests.exceptions.ConnectionError:
|
||||
status = 404
|
||||
|
||||
if status == 200:
|
||||
latest += 1
|
||||
newComic = True
|
||||
|
||||
elif status == 404:
|
||||
toPrint = ""
|
||||
|
||||
if useFile(latest_file, 'r', '')[4:] == 'Unread':
|
||||
toPrint = "New: "
|
||||
|
||||
if read:
|
||||
toPrint = ""
|
||||
useFile(latest_file, 'w', str(latest) + 'Read')
|
||||
elif newComic:
|
||||
useFile(latest_file, 'w', str(latest) + 'Unread')
|
||||
toPrint = "New: "
|
||||
|
||||
toPrint += str(latest)
|
||||
print(icon + toPrint)
|
||||
break
|
||||
|
||||
BIN
.config/polybar/scripts/notification-xkcd/screenshots/1.png
Normal file
BIN
.config/polybar/scripts/notification-xkcd/screenshots/1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
BIN
.config/polybar/scripts/notification-xkcd/screenshots/2.png
Normal file
BIN
.config/polybar/scripts/notification-xkcd/screenshots/2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.4 KiB |
Reference in New Issue
Block a user