Commit ca636424 authored by PizZaKatZe's avatar PizZaKatZe

Start with a fairly stupid JSON IO module

parents
/build/
/dist/
/jht_flyergen.egg-info/
/.mypy_cache/
/venv/
#!/usr/bin/env python3
#
# This file is part of jht_flyergen.
#
# jht_flyergen is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# jht_flyergen is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with jht_flyergen. If not, see <http://www.gnu.org/licenses/>.
"""JHT flyer generator CLI
"""
from argparse import ArgumentParser
from json import dumps
from sys import argv
from jht_flyergen.engine import fetch_data, read_data
TEST_URL = 'https://events.ccc.de/congress/2018/wiki/index.php/Special:Ask/cl:YzpVT9tKxFAM_KKaouzLQl5ERH1QYb8gp03t2Z5LSVJK_XrTdRcUcplhhjAZqmQyPGstkGKOhofWQZmQUoKRqWdR1LGuoEzSjYkCJ3w7fbxDl0hdq2IUEjf37RqneMOa1wuEXUeo4oeQtIM6DMqGLTSHR69XdfNQxecUez0eTRZuDk9e0Dw87_1Cu6dn7STOFmvBP_hm-pTasSr3bg2bD8_GOaQNq3xRid9X5f9RXUINZ-7s7sqNxHxbzIynnUCmWH6fhlnYbJslFsM9JizFg9DMF_YD' # pylint: disable=line-too-long
def parse_arguments(args):
"""Parses command-line arguments.
"""
parser = ArgumentParser()
parser.add_argument('-v', dest='verbose', action='store_true',
help='enable verbose output (useful for debugging)')
sources = parser.add_argument_group('data sources').add_mutually_exclusive_group(required=True)
sources.add_argument('-u', '--url', nargs='?', const=TEST_URL,
help='URL to fetch JSON data from; ' +
'if URL is omitted, a hard-coded URL returning test data is used')
sources.add_argument('-f', '--file', dest='path',
help='path to file containing JSON data')
return parser.parse_args(args)
def pretty_print(stuff):
"""Pretty-prints stuff.
"""
print(dumps(stuff, indent=4))
def main():
"""Program entry point.
"""
args = parse_arguments(argv[1:])
sessions = None
if args.url:
sessions = fetch_data(args.url)
elif args.path:
sessions = read_data(args.path)
pretty_print(sessions[0])
#!/usr/bin/env python3
#
# This file is part of jht_flyergen.
#
# jht_flyergen is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# jht_flyergen is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with jht_flyergen. If not, see <http://www.gnu.org/licenses/>.
"""JHT flyer generator
"""
from json import load
from typing import Dict, List
from urllib.request import urlopen
def fetch_data(url: str) -> List[Dict]:
"""Fetches given URL and returns self-organized session data.
Args:
url: URL to request
Returns:
A list of dicts - one for each self-organized session.
"""
results: Dict = load(urlopen(url))['results']
return list(results.values())
def read_data(path: str) -> List[Dict]:
"""Reads self-organized session data from file.
Args:
path: path to a file containing JSON-encoded data
Returns:
A list of dicts - one for each self-organized session.
"""
with open(path) as data_file:
return load(data_file)
from distutils.core import setup
from setuptools import find_packages
setup(
name='jht_flyergen',
description='A small module that generates a flyer with JHT events.',
keywords=['JHT', 'Junghackertag', 'CCC'],
author='PizZaKatZe',
author_email='pizzakatze@chaos-siegen.de',
url='https://gitlab.hasi.it/herzi/project/jht_flyergen',
license='GPLv3+',
version='0.1.0',
packages=find_packages(exclude=['tests']),
entry_points={
'console_scripts':[
'jht_flyergen = jht_flyergen.cli:main',
]
},
)
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment