[boobcoming] improve collection management in boobcoming

This commit is contained in:
Bezleputh 2014-05-07 15:25:32 +02:00
commit b140b3fa09
2 changed files with 34 additions and 60 deletions

View file

@ -25,9 +25,6 @@ from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFor
from weboob.capabilities.base import empty
from weboob.capabilities.calendar import ICapCalendarEvent, Query, CATEGORIES
from weboob.tools.application.repl import ReplApplication, defaultcount
from weboob.capabilities.collection import Collection, CollectionNotFound
from weboob.core import CallErrors
__all__ = ['Boobcoming']
@ -346,58 +343,3 @@ class Boobcoming(ReplApplication):
l = self.retrieve_events(args[0])
for event in l:
self.do('attends_event', event, False)
def _fetch_objects(self, objs):
objects = []
collections = []
split_path = self.working_path.get()
try:
if len(split_path) == 0:
for category in CATEGORIES.values:
collection = Collection([category], category)
collection.backend = u'boobcoming'
collections.append(collection)
elif len(split_path) == 1 and split_path[0] in CATEGORIES.values:
query = Query()
query.categories = split_path
query.start_date = datetime.combine(parse_date('today'), time.min)
query.end_date = parse_date('')
query.city = ''
for backend, event in self.do('search_events', query):
if event:
objects.append(event)
except CallErrors as errors:
self.bcall_errors_handler(errors, CollectionNotFound)
return (objects, collections)
def do_cd(self, line):
"""
cd [PATH]
Follow a path.
".." is a special case and goes up one directory.
"" is a special case and goes home.
"""
if not len(line.strip()):
self.working_path.home()
elif line.strip() == '..':
self.working_path.up()
else:
self.working_path.cd1(line)
split_path = self.working_path.get()
collections = []
if len(split_path) == 0 or (len(split_path) == 1 and split_path[0] in CATEGORIES.values):
collection = Collection(self.working_path.get(), None)
collections.append(collection)
if len(collections):
if len(collections) == 1:
self.working_path.split_path = collections[0].split_path
self._change_prompt()
else:
print >>sys.stderr, u"Path: %s not found" % unicode(self.working_path)
self.working_path.restore()
return 1

View file

@ -17,7 +17,11 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .base import CapBaseObject, IBaseCap, StringField, DateField, IntField, FloatField, Field
from .base import CapBaseObject, StringField, DateField, IntField, FloatField, Field
from .collection import ICapCollection, CollectionNotFound, Collection
from datetime import time, datetime
from weboob.tools.date import parse_date
__all__ = ['BaseCalendarEvent', 'ICapCalendarEvent']
@ -98,7 +102,7 @@ class Query(CapBaseObject):
self.categories.append(value)
class ICapCalendarEvent(IBaseCap):
class ICapCalendarEvent(ICapCollection):
"""
Capability of calendar event type sites
"""
@ -155,3 +159,31 @@ class ICapCalendarEvent(IBaseCap):
:type is_attending : bool
"""
raise NotImplementedError()
def iter_resources(self, objs, split_path):
"""
Iter events by category
"""
if len(split_path) == 0 and self.ASSOCIATED_CATEGORIES != 'ALL':
for category in self.ASSOCIATED_CATEGORIES:
collection = Collection([category], category)
yield collection
elif len(split_path) == 1 and split_path[0] in self.ASSOCIATED_CATEGORIES:
query = Query()
query.categories = split_path
query.start_date = datetime.combine(parse_date('today'), time.min)
query.end_date = parse_date('')
query.city = ''
for event in self.search_events(query):
yield event
def validate_collection(self, objs, collection):
"""
Validate Collection
"""
if collection.path_level == 0:
return
if collection.path_level == 1 and collection.split_path[0] in CATEGORIES.values:
return
raise CollectionNotFound(collection.split_path)