old_contents: import requests
  import urllib2
  from pypnrstatus.pnr_utils import *
  import datetime
  
  def schedule_pnr_notification(pnr_notify):
      pnr_no = pnr_notify.pnr_no
      resp = requests.get('http://pnrapi.alagu.net/api/v1.0/pnr/%s'%pnr_no)
      resp = json.loads(resp.content)
  
      status = resp['status']
      data = resp['data']
  
      if data.has_key('message'):
          print data['message']
          return
  
      if data == {} and status == 'OK':
          print data
          # retry
          return
  
      pnr_notify.next_schedule_time = datetime.datetime.now() + caluclate_timedelta(pnr_notify.notification_frequency,
                      pnr_notify.notification_frequency_value)
      pnr_notify.save()
  
      print data
      passengers = data['passenger']
      notify_type = pnr_notify.notification_type
  
      if check_if_ticket_cancelled(passengers):
          if notify_type == 'email':
              send_ticket_cancelled_email(passengers, pnr_notify)
          elif notify_type == 'phone':
              send_ticket_cancelled_sms(passengers, pnr_notify)
          pnr_notify.delete()
          return
  
      if check_if_passengers_cnf(passengers):
          if notify_type == 'email':
              send_pnr_status_confirmed_email(passengers, pnr_notify)
          elif notify_type == 'phone':
              send_pnr_status_confirmed_sms(passengers, pnr_notify)
          pnr_notify.delete()
          return
  
      if data['chart_prepared']:
          if notify_type == 'email':
              send_pnr_status_chart_prepared_email(passengers, pnr_notify)
          elif notify_type == 'phone':
              send_pnr_status_chart_prepared_sms(passengers, pnr_notify)
          pnr_notify.delete()
          return
  
      if pnr_notify.notification_type == 'email':
          send_pnr_status_email(passengers, pnr_notify)
      elif pnr_notify.notification_type == 'phone':
          send_pnr_status_sms(passengers, pnr_notify)
  
  
new_contents: import requests
  import urllib2
  from pypnrstatus.pnr_utils import *
  import datetime
  
  def schedule_pnr_notification(pnr_notify):
      pnr_no = pnr_notify.pnr_no
      resp = requests.get('http://pnrapi.alagu.net/api/v1.0/pnr/%s'%pnr_no)
  
      try:
          resp = json.loads(resp.content)
      except ValueError:
          return
  
      status = resp['status']
      data = resp['data']
  
      if data.has_key('message'):
          print data['message']
          return
  
      if data == {} and status == 'OK':
          print data
          # retry
          return
  
      pnr_notify.next_schedule_time = datetime.datetime.now() + caluclate_timedelta(pnr_notify.notification_frequency,
                      pnr_notify.notification_frequency_value)
      pnr_notify.save()
  
      print data
      passengers = data['passenger']
      notify_type = pnr_notify.notification_type
  
      if check_if_ticket_cancelled(passengers):
          if notify_type == 'email':
              send_ticket_cancelled_email(passengers, pnr_notify)
          elif notify_type == 'phone':
              send_ticket_cancelled_sms(passengers, pnr_notify)
          pnr_notify.delete()
          return
  
      if check_if_passengers_cnf(passengers):
          if notify_type == 'email':
              send_pnr_status_confirmed_email(passengers, pnr_notify)
          elif notify_type == 'phone':
              send_pnr_status_confirmed_sms(passengers, pnr_notify)
          pnr_notify.delete()
          return
  
      if data['chart_prepared']:
          if notify_type == 'email':
              send_pnr_status_chart_prepared_email(passengers, pnr_notify)
          elif notify_type == 'phone':
              send_pnr_status_chart_prepared_sms(passengers, pnr_notify)
          pnr_notify.delete()
          return
  
      if pnr_notify.notification_type == 'email':
          send_pnr_status_email(passengers, pnr_notify)
      elif pnr_notify.notification_type == 'phone':
          send_pnr_status_sms(passengers, pnr_notify)
  
  
subject: Handle value error