-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcortex_reddits.py
executable file
·85 lines (72 loc) · 2.73 KB
/
cortex_reddits.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
# Copyright (c) 2015-2018, Gianluca Fiore
#
# This program 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.
#
###############################################################################
# Browse (sub)reddits, sequentially, with cortex
__author__ = "Gianluca Fiore"
__license__ = "GPL"
__date__ = "20150317"
__status__ = "beta"
import argparse
import sys
import subprocess
# Declare here the (sub)reddits
REDDITS_IMG = ['unixporn', 'wallpaperdump', 'EarthPorn']
REDDITS_PROGRAMMING = ['compsci', 'programming', 'golang', 'awesomewm', 'archlinux', 'linux', 'SEO']
REDDITS_VAR = ['linguistics', 'history', 'music', 'metal', 'learnpolish', 'baking', 'bakker', 'bladerunner', 'Blogging', 'books', 'Coffee', 'europe', 'Instagram', 'italy', 'Malazan', 'MilitaryHistory', 'mkxmobile', 'nespresso', 'NickCave', 'Pizza', 'sailing']
REDDITS_ALL = REDDITS_IMG + REDDITS_PROGRAMMING + REDDITS_VAR
def argument_parser():
"""CLI argument parser"""
p = argparse.ArgumentParser()
p.add_argument("-i", "--image",
action="store_true",
help="browse images-related (sub)reddits",
dest="r_img")
p.add_argument("-p", "--programming",
action="store_true",
help="browse programming-related (sub)reddits",
dest="r_prog")
p.add_argument("-v", "--various",
action="store_true",
help="browse various (sub)reddits",
dest="r_var")
p.add_argument("-a", "--all",
action="store_true",
help="browse all (sub)reddist",
dest="r_all")
options = p.parse_args()
return options, p
def launch_cortex(reddit):
"""Launch cortex for every reddit given"""
for r in reddit:
if type(r) == 'list':
launch_cortex(r)
else:
command = ['cortex', r]
p = subprocess.call(command)
if __name__ == '__main__':
try:
options, cli_parser = argument_parser()
except:
sys.exit(1)
# Check first if we want to browse all reddits
if options.r_all:
launch_cortex(REDDITS_ALL)
else:
if options.r_img:
launch_cortex(REDDITS_IMG)
elif options.r_prog:
launch_cortex(REDDITS_PROGRAMMING)
elif options.r_var:
launch_cortex(REDDITS_VAR)
else:
print("Choose a list of reddits to browse please")
cli_parser.print_help()
cli_parser.exit(status=1)