mirror of
https://pagure.io/fedora-infra/ansible.git
synced 2026-05-11 18:36:53 +08:00
torrent: add a do_json_output subroutine
Signed-off-by: Gregory Bartholomew <gregory.lee.bartholomew@gmail.com>
This commit is contained in:
committed by
kevin
parent
21c6575fd4
commit
de6a9a68bd
@@ -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__":
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user