-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.py
executable file
·54 lines (41 loc) · 1.22 KB
/
start.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
53
54
#!/usr/bin/env python3
"""
Runs two multi-processes to fetch emails and generate RSS feeds,
and serve the feeds as an HTTP server.
"""
import multiprocessing
import time
import email_fetcher
import feed_generator
import feed_server
from common import logging, config
def fetch_and_generate():
"""
Fetches and generates RSS feed from emails periodically.
This function continuously calls the `feed_converter.main()` function to
fetch and generate an RSS feed from emails. It then sleeps for 120 seconds
before repeating the process.
Returns:
None
"""
refresh_seconds = config.get("refresh_seconds", 300)
while True:
email_fetcher.main()
feed_generator.main()
logging.info(f"waiting for {refresh_seconds} seconds")
time.sleep(refresh_seconds)
def serve():
"""
Starts the server and serves the static files.
"""
feed_server.main()
if __name__ == "__main__":
# Create processes
process1 = multiprocessing.Process(target=fetch_and_generate)
process2 = multiprocessing.Process(target=serve)
# Start processes
process1.start()
process2.start()
# Wait for both processes to finish
process1.join()
process2.join()