forked from m-wichmann/local_seriesly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
local_seriesly.py
executable file
·140 lines (118 loc) · 4.54 KB
/
local_seriesly.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
"""local seriesly fetches data from tvrage and generates html files"""
import os
import json
import sys
import src.fetchdata as fetchdata
import src.generatehtml as generatehtml
import src.parse_cfg as parse_cfg
from optparse import OptionParser
class LocalSeriesly(object):
"""main class for local_seriesly"""
parsecfg_obj = None
fetchdata_obj = None
generate_obj = None
def __init__(self):
self.parsecfg_obj = parse_cfg.ParseCFG()
self.fetchdata_obj = fetchdata.Fetchdata()
self.generate_obj = generatehtml.GenerateHTML()
# remove html files and fetched data
def remove(self):
"""remove working data"""
# remove the json database with fetched data
print "Removing show data..."
currentdirpath = os.path.dirname(os.path.realpath(sys.argv[0]))
try:
os.remove(currentdirpath + "/data/seriesdb.json")
except OSError:
pass
# remove the html for every profile
print "Removing profile data..."
profiles = self.parsecfg_obj.get_profile_names()
for profile in profiles:
try:
os.remove(currentdirpath + "/data/" + profile + ".html")
except OSError:
pass
# remove the compiled python scripts
# TODO: why are these scripts even compiled?
print "Removing compiled python scripts..."
try:
os.remove(currentdirpath + "/src/fetchdata.pyc")
except OSError:
pass
try:
os.remove(currentdirpath + "/src/generatehtml.pyc")
except OSError:
pass
try:
os.remove(currentdirpath + "/src/parse_cfg.pyc")
except OSError:
pass
try:
os.remove(currentdirpath + "/src/__init__.pyc")
except OSError:
pass
@classmethod
def list_all_shows(cls):
"""list all shows currently in one or more profiles"""
currentdirpath = os.path.dirname(os.path.realpath(sys.argv[0]))
try:
data = json.load(open(currentdirpath + '/data/seriesdb.json', 'r'))
except IOError:
print "Couldn't find show data. Please fetch the data first!"
return
temp = []
for show in data:
show_id = show.keys().pop()
show_name = show[show_id].pop()["name"]
temp.append(show_name + " (id: " + show_id + ")")
temp.sort()
for line in temp:
print line
def profiles(self):
"""list all profiles including their ids"""
profiles = self.parsecfg_obj.get_config_data()
for profile in profiles:
print "Profile: " + profile
show_ids = profiles[profile]
for show_id in show_ids:
# TODO: add show name to output
print "\t" + show_id
# fetch data
def fetch(self):
"""fetch data from tvrage.com"""
self.fetchdata_obj.fetchdata()
# generate html files
def generate(self):
"""generate html files for profiles"""
self.generate_obj.generatehtml()
def main(self):
"""main method that parses command line arguments"""
# use OptionParser to provide decent argument parsing
parser = OptionParser()
parser.add_option("-f", "--fetch", action="store_true", dest="fetch", help="fetch data")
parser.add_option("-g", "--generate", action="store_true", dest="generate", help="generate the html documents")
# TODO: be able to choose the config file
#parser.add_option("-c", "--configfile", dest="config_file",
# help="path to config file with the profiles and show ids",
# metavar="FILE")
parser.add_option("-r", "--remove", action="store_true", dest="clean", help="remove html files and fetched data")
parser.add_option("-l", "--list", action="store_true", dest="listshows", help="list all shows by name that are currently in a profile")
parser.add_option("-p", "--profiles", action="store_true", dest="profiles", help="list all profiles and their shows")
(options, args) = parser.parse_args()
# go through the options
if options.clean:
self.remove()
if options.fetch:
self.fetch()
if options.listshows:
self.list_all_shows()
if options.profiles:
self.profiles()
if options.generate:
self.generate()
if __name__ == '__main__':
OBJ = LocalSeriesly()
OBJ.main()