-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeme_generator.py
executable file
·52 lines (43 loc) · 1.53 KB
/
meme_generator.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
import os
import time
import psutil
class MemeGenerator():
def __init__(self):
self.download0 = (
"curl -X GET 'https://meme-api.herokuapp.com/gimme' | "
"jq '.url' | xargs wget -O meme0 &")
self.download1 = (
"curl -X GET 'https://meme-api.herokuapp.com/gimme' | "
"jq '.url' | xargs wget -O meme1 &")
self.show0 = "sxiv -a -f -s f meme0 &"
self.show1 = "sxiv -a -f -s f meme1 &"
self.state = False
# Pre-download the meme
os.system(self.download0)
self.default_meme()
def kill(self, procname):
"""Kill all system processes that match the process name.
Args:
procname (str): The name of the processes to be killed
"""
for proc in psutil.process_iter():
# Check whether the process name matches
if proc.name() == procname:
proc.kill()
def show_meme(self, display_duration=5):
if self.state:
os.system(self.show1)
os.system(self.download0)
else:
os.system(self.show0)
os.system(self.download1)
self.state = not self.state
time.sleep(display_duration)
def default_meme(self):
default_dir = os.path.join("/home", "pi", "memeba", "assets",
"default.png")
os.system(f"feh -F -Z {default_dir} &")
def cleanup(self):
self.kill("sxiv")
self.kill("feh")
os.system("rm meme0; rm meme1")