Skip to content

Commit 04b9db6

Browse files
Merge pull request #2 from tammojan/master
Moving around code, add setup.py
2 parents d9fa944 + a6a4e8d commit 04b9db6

9 files changed

+325
-278
lines changed

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,15 @@ venv.bak/
102102

103103
# mypy
104104
.mypy_cache/
105+
106+
# PyCharm
107+
.idea/
108+
109+
# cache
110+
skycache/
111+
112+
# Don't add fits files
113+
*.fits
114+
115+
# Temporary files
116+
results/
File renamed without changes.

modules/functions.py

-126
This file was deleted.

setup.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
name="SkyviewBot",
5+
description="Script to download image from SkyView and post it to Slack.",
6+
license="MIT License",
7+
author="V.A. Moss and T.J. Dijkema",
8+
author_email="vmoss.astro@gmail.com",
9+
version="1.0.0",
10+
packages=find_packages(),
11+
entry_points={
12+
'console_scripts': ['skyviewbot=skyviewbot.cli:main']
13+
}
14+
)

skyviewbot.py

-152
This file was deleted.

skyviewbot/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""skyviewbot: a bot for posting skyview images to Slack
2+
3+
The main usage of skyviewbot is through the command-line interface skyviewbot.
4+
The tool can be used with
5+
>>> from skyviewbot import skyviewbot
6+
"""
7+
8+
from .cli import main
9+
from .functions import skyviewbot, call_skyview, coords_from_name, send_to_slack, plot_fits

skyviewbot/cli.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python
2+
"""Command-line interface for skyviewbot"""
3+
4+
# ASTERICS-OBELICS Good Coding Practices (skyviewbot.py)
5+
# V.A. Moss (vmoss.astro@gmail.com), with suggestions from T.J. Dijkema
6+
7+
import sys
8+
from .functions import skyviewbot
9+
from argparse import ArgumentParser, RawTextHelpFormatter
10+
11+
12+
def main(*function_args):
13+
"""Command-line interface to skyviewbot
14+
15+
Args:
16+
List[str]: arguments (typically sys.argv[1:])
17+
18+
Returns:
19+
bool: True if succeeded, False if not
20+
"""
21+
22+
parser = ArgumentParser(formatter_class=RawTextHelpFormatter)
23+
parser.add_argument('field', help="Field, e.g. 'M101'")
24+
parser.add_argument('msg', help="Message to accompany the post on Slack")
25+
parser.add_argument('-f', '--fits-name',
26+
default=None,
27+
type=str,
28+
action="store",
29+
help='Specify name of a custom fits file to use as input instead of Skyview (default: %(default)s)')
30+
parser.add_argument('-i', '--slack-id',
31+
default=None,
32+
type=str,
33+
help='Your Slack ID (default: %(default)s)')
34+
parser.add_argument('-s', '--survey',
35+
default='DSS',
36+
type=str,
37+
help="Survey name, e.g. 'DSS' (default: %(default)s)")
38+
parser.add_argument('-r', '--radius',
39+
default=1.,
40+
type=float,
41+
help="Radius (default: %(default)s)")
42+
parser.add_argument('-c', '--colormap',
43+
default="viridis",
44+
type=str,
45+
help="Colormap (default: %(default)s)")
46+
parser.add_argument('-d', '--dry-run',
47+
default=False,
48+
action='store_true',
49+
help='Dry run: make image, do not post to google and slack (default: %(default)s')
50+
args = parser.parse_args(*function_args)
51+
52+
if not args.slack_id:
53+
print('You should use your Slack ID before posting!')
54+
return False
55+
56+
retval = skyviewbot(args.slack_id, args.field, args.fits_name, args.msg, args.survey,
57+
args.radius, args.colormap, dry_run=args.dry_run)
58+
59+
if retval:
60+
print("SkyViewBot posted to Slack successfully")
61+
else:
62+
print("Some error happened in SkyViewBot")
63+
64+
return retval
65+
66+
67+
if __name__ == '__main__':
68+
main(sys.argv[1:])
File renamed without changes.

0 commit comments

Comments
 (0)