torrent: add a do_json_output subroutine

Signed-off-by: Gregory Bartholomew <gregory.lee.bartholomew@gmail.com>
This commit is contained in:
Gregory Bartholomew
2025-09-08 18:49:09 +00:00
committed by kevin
parent 21c6575fd4
commit de6a9a68bd
2 changed files with 10 additions and 3 deletions

View File

@@ -20,6 +20,7 @@ import sys
import glob
import time
import operator
import simplejson
timeformat = "%Y-%m-%d"
rssformat = "%a, %d %b %Y %H:%M:%S"
@@ -67,7 +68,6 @@ def do_html_output(config, groups):
myout.close()
def do_rss_output(config, groups):
myout = open(config.rssout, 'w')
with open(config.rssheader) as head:
myout.write(head.read())
@@ -83,8 +83,12 @@ def do_rss_output(config, groups):
with open(config.rssfooter) as foot:
myout.write(foot.read())
myout.close()
def do_json_output(config, groups):
myout = open(config.jsonout, 'w')
myout.write(simplejson.dumps(groups, default=vars))
myout.close()
class Group:
def __init__(self, name, date):
self.name = name
@@ -119,6 +123,7 @@ class Config:
self.rssfooter = cpobj.get('main', 'rssfooter')
self.htmlout = cpobj.get('main', 'htmlout')
self.rssout = cpobj.get('main', 'rssout')
self.jsonout = cpobj.get('main', 'jsonout')
except configparser.NoOptionError as e:
print("Config file missing required option:", e, file=sys.stderr)
sys.exit(1)
@@ -174,6 +179,7 @@ def main():
do_html_output(config, sortgroups)
do_rss_output(config, sortgroups)
do_json_output(config, sortgroups)
if __name__ == "__main__":

View File

@@ -7,4 +7,5 @@ rssheader=/srv/torrent/torrent-generator/head.rss
rssfooter=/srv/torrent/torrent-generator/foot.rss
htmlout=/srv/web/index.html
rssout=/srv/web/rss20.xml
jsonout=/srv/web/torrents.json