def handle(self, *args, **options): logger.info('Running Notifications...') debug = options['debug'] while debug is None: response = raw_input('Continue in production mode? (Y/N) ') if response == "Y": debug = False if response == "N": debug = True version = options['version'] test_notification = options['test_notification'] notification = LaunchLibrarySync(debug=debug, version=version) library = LaunchLibrarySDK(version=version) if test_notification: response = library.get_next_launches(launch_service_provider="spx") if response.status_code is 200: response_json = response.json() launch_data = response_json['launches'] for launch in launch_data: launch = launch_json_to_model(launch) notification_obj = Notification.objects.get(launch=launch) # TODO pass in parameter for setting the notification_type notification.send_notification(launch, 'oneHour', notification_obj) else: logger.error(response.status_code + ' ' + response) else: notification.check_next_launch()
def get_previous_launches(self): logger.info("Getting previous launches") launches = [] count = 0 total = None while total is None or count < total: response = self.launchLibrary.get_previous_launches(offset=count) if response.status_code is 200: response_json = response.json() count = response_json['count'] + response_json['offset'] total = response_json['total'] launch_data = response_json['launches'] logger.info("Saving next %i launches - %s out of %s" % (len(launch_data), count, total)) for launch in launch_data: launch = launch_json_to_model(launch) launch.save() launches.append(launch) else: logger.error('ERROR ' + str(response.status_code)) logger.error('RESPONSE: ' + response.text) logger.error('URL: ' + response.url) break return launches
def get_next_launches(self, next_count=5, all=False): logger.info("Daily Digest running...") launches = [] count = 0 total = None while total is None or count < total: response = self.launchLibrary.get_next_launches( next_count=next_count, offset=count) if response.status_code is 200: response_json = response.json() count = response_json['count'] + response_json['offset'] total = response_json['total'] launch_data = response_json['launches'] logger.info("Saving next %i launches - %s out of %s" % (len(launch_data), count, total)) for launch in launch_data: launch = launch_json_to_model(launch) logger.debug("Saving Launch: %s" % launch.name) launch.save() launches.append(launch) if not all: break else: logger.error('ERROR ' + str(response.status_code)) logger.error('RESPONSE: ' + response.text) logger.error('URL: ' + response.url) break return launches
def get_next_launch(self): response = self.launchLibrary.get_next_launches() if response.status_code is 200: response_json = response.json() launch_data = response_json['launches'] logger.debug("Found %i launches" % len(launch_data)) logger.debug("DATA: %s" % launch_data) for launch in launch_data: return launch_json_to_model(launch) else: logger.error(response.status_code + ' ' + response)
def is_launch_deleted(self, id): response = self.launchLibrary.get_launch_by_id(id) if response.status_code == 200: logger.debug("Launch is NOT Stale - %s" % id) response_json = response.json() launch_data = response_json['launches'] logger.debug("Found %i launches" % len(launch_data)) logger.debug("DATA: %s" % launch_data) for launch in launch_data: return launch_json_to_model(launch) return False elif response.status_code == 404: logger.debug("Launch is Stale - %s" % id) return True