This repository has been archived by the owner on Jul 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
rss.py
64 lines (53 loc) · 1.95 KB
/
rss.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
55
56
57
58
59
60
61
62
63
64
import config
import PyRSS2Gen
import http.server
import socketserver
import core
from datetime import datetime
from threading import Thread
# Our rss generator
rss = PyRSS2Gen.RSS2(
title="Satellite station images",
link="",
description="Images from the station",
lastBuildDate=datetime.now(),
items=[]
)
# Http server
httpd = 0
server_thread = 0
# We need to set out directory
class HTTPHandler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=config.output_dir, **kwargs)
# Function for adding passes
def addRSSPass(satellite, filename, date, passobj):
# Generate item content, here being images
image = ""
if satellite.downlink == "APT":
image = "Visible + Infrared : <\p>" + "<img src=\"" + filename + ".png\">"
elif satellite.downlink == "LRPT":
image = "Visible : <\p>" + "<img src=\"" + filename + " - Visible.png\">" + "<\p>" + "Infrared : <\p>" + "<img src=\"" + filename + " - Infrared.png\">"
# Add it to the feed
rss.items.append(PyRSS2Gen.RSSItem(
title = satellite.name + " on " + date.strftime('%H:%-M %d, %b %Y') + " (" + str(passobj.max_elevation_deg) + "°)",
link = "",
description = image,
guid = PyRSS2Gen.Guid(""),
pubDate = date)
)
# Write the file to push the update
rss.write_xml(open(config.output_dir + "/rss.xml", "w"))
# Used for the startup procedure
def startServer():
global rss, httpd, server_thread
if config.rss_webserver:
# Configure the http server
httpd = socketserver.TCPServer(("", config.rss_port), HTTPHandler)
print("Starting http server at " + str(config.rss_port))
print("\n")
# Start it in a thread
server_thread = Thread(target = httpd.serve_forever)
server_thread.start()
# Write the file to make the feed readable
rss.write_xml(open(config.output_dir + "/rss.xml", "w"))