/
script.py
47 lines (34 loc) · 1.1 KB
/
script.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
import requests
import threading
from bs4 import BeautifulSoup
class XKCD(threading.Thread):
def run(self):
r = requests.get('https://c.xkcd.com/random/comic')
if r.status_code != 200:
return None
soup = BeautifulSoup(r.text, 'html.parser')
url = soup.find(id='comic').find('img')['src']
print(f'https:{url}')
class CommitStrip(threading.Thread):
def run(self):
r = requests.get('http://www.commitstrip.com/?random=1')
if r.status_code != 200:
return None
soup = BeautifulSoup(r.text, 'html.parser')
print(soup.find_all(class_='entry-content')[0].find('img')['src'])
class Node(threading.Thread):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.xkcd = XKCD()
self.commitstrip = CommitStrip()
self.daemon = False
def run(self):
self.xkcd.start()
self.commitstrip.start()
self.xkcd.join()
self.commitstrip.join()
if __name__ == '__main__':
# Get xkcd
# Get commitstrip
node = Node()
node.start()