-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
47 lines (39 loc) · 1 KB
/
example.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
# Future Imports
from __future__ import annotations
# Typing Imports
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import *
from ssec import Event
# Builtin Imports
import logging
import threading
import time
import sys
# Library Imports
# []
# Project Imports
from ssec import EventSource
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
# # # # # # # # # #
# Normal Example
event_source = EventSource('https://stream.wikimedia.org/v2/stream/recentchange')
event_source.on_open = print
event_source.on_message = print
event_source.on_error = print
event_source.open() # Interrupt with CTRL+C
# # # # # # # # # #
# Thread Example
event_source = EventSource('https://stream.wikimedia.org/v2/stream/recentchange', timeout=5)
event_source.on_open = print
event_source.on_message = print
event_source.on_error = print
t = threading.Thread(target=event_source.open)
t.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
event_source.close()
t.join()