def onPlayBackStopped(self): log_utils.log('Service: Playback Stopped', log_utils.LOGNOTICE, COMPONENT) if self.tracked: # clear the playlist if SALTS was playing and only one item in playlist to # use playlist to determine playback method in get_sources pl = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) plugin_url = 'plugin://%s/' % (kodi.get_id()) if pl.size() == 1 and pl[0].getfilename().lower().startswith(plugin_url): log_utils.log('Service: Clearing Single Item SALTS Playlist', log_utils.LOGDEBUG, COMPONENT) pl.clear() playedTime = float(self._lastPos) try: percent_played = int((playedTime / self._totalTime) * 100) except: percent_played = 0 # guard div by zero pTime = utils.format_time(playedTime) tTime = utils.format_time(self._totalTime) log_utils.log('Service: Played %s of %s total = %s%%' % (pTime, tTime, percent_played), log_utils.LOGDEBUG, COMPONENT) if playedTime == 0 and self._totalTime == 999999: log_utils.log('Kodi silently failed to start playback', log_utils.LOGWARNING, COMPONENT) elif playedTime >= 5: if percent_played <= 98: log_utils.log('Service: Setting bookmark on |%s|%s|%s| to %s seconds' % ( self.trakt_id, self.season, self.episode, playedTime), log_utils.LOGDEBUG, COMPONENT) db_connection.set_bookmark(self.trakt_id, playedTime, self.season, self.episode) if percent_played >= 75 and self._from_library: if kodi.has_addon('script.trakt'): run = 'RunScript(script.trakt, action=sync, silent=True)' xbmc.executebuiltin(run) self.reset()
def create_customer_pool(self, customers_start_id, customers_end_id, max_delay): for i in xrange(customers_start_id, customers_end_id): logging.debug('create order. customer_id:{}'.format(i)) customer_loc = TEST_POSITIONS[random.randint(0, len(TEST_POSITIONS) - 1)] order_time = None if bool(random.getrandbits(1)): order_time = datetime.utcnow() + timedelta(seconds=random.randint(0, max_delay)) order_time = format_time(order_time) self.create_order(user_id=i, time=order_time, **customer_loc)
def take_taxi(): payload = { 'user_id': random.randint(1, 1000), 'lat': '{0:.5f}'.format(round(random.uniform(-55, 55), 5)), 'lon': '{0:.5f}'.format(round(random.uniform(-55, 55), 5)), } if bool(random.getrandbits(1)): payload['time'] = format_time(datetime.now() + timedelta(minutes=random.randint(2, 5))) r = requests.post(ADD_ORDER_URL, data=payload) if r.status_code == requests.codes.ok: print 'taxi successful ordered: {}'.format(r.text) else: print 'taxi order fail. Payload {0} Exc {1}'.format(payload, r.text)
def test_order_cancel(self): self.create_taxi(user_id=self.NORTH_DRIVER, **TEST_NORTH) self.create_taxi(user_id=self.CENTER_DRIVER, **TEST_CENTER) self.create_taxi(user_id=self.SOUTH_DRIVER, **TEST_SOUTH) order_time = datetime.utcnow() + timedelta(days=1) order_time = format_time(order_time) o = self.create_order(user_id=12, time=order_time, **TEST_CENTER) time.sleep(5) self.cancel_order(o['id']) orders = self.get_orders() for order in orders: if order['id'] == o['id']: self.assertFalse(order['driver_id']) break