-
Notifications
You must be signed in to change notification settings - Fork 7
/
galaxy.py
67 lines (53 loc) · 1.54 KB
/
galaxy.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
from util import our_db
from planet import Planet
import logging
log = logging.getLogger('planeteria')
class Galaxy(list):
"A collection of planets"
selected = None
def __init__(self, selected=None):
self.planets = []
if selected: self.selected = selected
def append(self, planet):
"""planet is a Planet object"""
self.planets.append(planet)
def load(self):
with our_db('planets') as db:
for k in db.keys():
if not self.selected or k in self.selected:
self.append(Planet(db[k]))
def dump(self):
for p in self.planets:
p.dump()
def save(self):
for p in self.planets:
p.save()
def update(self):
for p in self.planets:
p.update()
def generate(self):
for p in self.planets:
p.generate()
def delete_unused_feeds(self):
planets = []
with our_db('planets') as db:
for k in db.keys():
planets.append(Planet(db[k]))
feed_urls = {}
for p in planets:
for f in p.feeds:
feed_urls[f] = f
feed_urls = feed_urls.keys()
with our_db('cache') as db:
for k in db.keys():
if not k in feed_urls:
del db[k]
log.debug("Removed %s from cache." % k)
def delete_missing_planets(self):
for p in self.planets:
p.delete_if_missing()
def get_planet_by_subdir(self, subdir):
for p in self.planets:
if p.direc == subdir:
return p
return None