def test_base(self): start = date.today() cities = list(self.backend.iter_city_search('paris')) assert cities for c in cities: assert c.id assert c.name c = cities[0] cur = self.backend.get_current(c.id) assert cur assert cur.temp assert cur.temp.unit assert not empty(cur.temp.value) assert cur.text forecast = list(self.backend.iter_forecast(c.id)) assert forecast for f in forecast: assert f.date assert new_datetime(f.date) >= new_datetime(start) assert f.text assert -20 < f.low.value <= f.high.value < 40 assert f.low.unit == 'C' assert f.high.unit == 'C'
def all_events(self, start, end): self.users.go() users = {u.id: u for u in self.page.iter_users()} last = None while True: if end: if end < start: break else: if last and last + timedelta(days=300) < start: self.logger.info('300 days without event, stopping') break window_end = start + timedelta(days=14) params = { 'date': 'between,%s,%s' % (start.strftime('%Y-%m-%d'), window_end.strftime('%Y-%m-%d')), 'paging': '0,10000', 'owner.id': ','.join(str(u.id) for u in users.values()), 'fields': 'u,a,o,ls,mc,r,c,rw', } self.calendar.go(params=params) events = self.page.iter_events(start, users=users) for event in sorted(events, key=lambda ev: new_datetime(ev.start_date)): if end and event.start_date >= end: continue yield event last = new_datetime(event.start_date) start = window_end
def all_events(self, start, end): self.users.go() users = {u.id: u for u in self.page.iter_users()} last = None while True: if end: if end < start: break else: if last and last + timedelta(days=300) < start: self.logger.info('300 days without event, stopping') break window_end = start + timedelta(days=14) params = { 'date': 'between,%s,%s' % (start.strftime('%Y-%m-%d'), window_end.strftime('%Y-%m-%d')), 'leavePeriod.ownerId': ','.join(str(u.id) for u in users.values()), 'fields': 'leavePeriod[id,ownerId,isConfirmed],isAm,date,color,isRemoteWork,leaveAccount[name,isRemoteWork]', } self.calendar.go(params=params) events = self.page.iter_events(start, users=users) for event in sorted(events, key=lambda ev: new_datetime(ev.start_date)): if end and event.start_date >= end: continue yield event last = new_datetime(event.start_date) start = window_end + timedelta(days=1)
def __setattr__(self, name, value): if name == 'value': # Force use of our date and datetime types, to fix bugs in python2 # with strftime on year<1900. if type(value) is datetime.datetime: value = new_datetime(value) if type(value) is datetime.date: value = new_date(value) return object.__setattr__(self, name, value)
def __setattr__(self, name, value): if name == 'value': # Force use of our date and datetime types, to fix bugs in python2 # with strftime on year<1900. if type(value) is datetime.datetime: value = new_datetime(value) if type(value) is datetime.date: value = new_date(value) return object.__setattr__(self, name, value)
def sorted_transactions(iterable): """Sort an iterable of transactions in reverse chronological order""" return sorted(iterable, reverse=True, key=lambda tr: (tr.date, new_datetime(tr.rdate) if tr.rdate else datetime.datetime.min))
def sorted_transactions(iterable): """Sort an iterable of transactions in reverse chronological order""" return sorted(iterable, reverse=True, key=lambda tr: (tr.date, new_datetime(tr.rdate) if tr.rdate else datetime.datetime.min))