Untitled

From anonymous, 1 Month ago, written in Python, viewed 13 times.
URL https://paste.codexterous.com/view/31f21148 Embed
Download Paste or View Raw
  1. import re
  2. from decimal import Decimal
  3. from slugify import slugify
  4.  
  5. # Credit union name
  6. c=CreditUnion.objects.get(home_url='epbecu')
  7.  
  8. # Credit union tiers. ORDER IN BEST TO WORST because they get sorted by id,
  9. # not alphabetically.
  10. tiers = ['Tier 1 (720+)', 'Tier 2 (680+)', 'Tier 3 (650+)', 'Tier 4 (620+)', 'Tier 5 (619+)', 'Tier 6 (599 or less)']
  11. created_tiers = []
  12.  
  13. CreditHistoryTier.objects.filter(credit_union=c).delete()
  14. VehicleYearRange.objects.filter(credit_union=c).delete()
  15. EnhancedAutoLoanRate.objects.filter(credit_union=c).delete()
  16.  
  17. for i, t in enumerate(tiers):
  18.   created_tiers.append(CreditHistoryTier.objects.create(credit_union=c,
  19.                                                         tier_name=t,
  20.                                                         slug_tier_name=slugify(t),
  21.                                                         index=i))
  22.  
  23.  
  24. model_year_ranges = [
  25.   VehicleYearRange.objects.create(credit_union=c,
  26.                                   current_model_year_minus_start=2,
  27.                                   current_model_year_minus_end=None),
  28.   VehicleYearRange.objects.create(credit_union=c,
  29.                                   current_model_year_minus_start=5,
  30.                                   current_model_year_minus_end=3),
  31.   VehicleYearRange.objects.create(credit_union=c,
  32.                                   current_model_year_minus_start=None,
  33.                                   current_model_year_minus_end=6),
  34. ]
  35.  
  36.  
  37. rates = [
  38. """12 Months\t3.5\t4\t4\t9\t9\t14
  39. 24 Months\t3.5\t4\t4\t9\t9\t14
  40. 36 Months\t3.5\t4\t4\t9\t9\t14
  41. 48 Months\t3.5\t4\t4\t9\t9\t14
  42. 60 Months\t3.5\t4\t4\t9\t9\t14
  43. 72 Months\t4\t4.5\t4.5\t9.5\t9.5\t14.5""",
  44.  
  45. """12 Months\t4\t4.5\t4.5\t9.5\t9.5\t14.5
  46. 24 Months\t4\t4.5\t4.5\t9.5\t9.5\t14.5
  47. 36 Months\t4\t4.5\t4.5\t9.5\t9.5\t14.5
  48. 48 Months\t4\t4.5\t4.5\t9.5\t9.5\t14.5
  49. 60 Months\t4\t4.5\t4.5\t9.5\t9.5\t14.5
  50. 72 Months\t4.5\t5\t5\t10\t10\t15""",
  51.  
  52. """12 Months\t4.5\t5\t5\t10\t10\t15
  53. 24 Months\t4.5\t5\t5\t10\t10\t15
  54. 36 Months\t4.5\t5\t5\t10\t10\t15
  55. 48 Months\t4.5\t5\t5\t10\t10\t15
  56. 60 Months\t4.5\t5\t5\t10\t10\t15""",
  57. ]
  58.  
  59. for j, table in enumerate(rates):
  60.   for rt in table.split("\n"):
  61.     r = rt.split("\t")
  62.     print
  63.     mos = int(re.search("(\d+)\s+.*$", r[0]).group(1))
  64.     for i, apr in enumerate(r[1:]):
  65.       apr = apr.rstrip("%")
  66.       if apr:
  67.         apr = Decimal(apr)
  68.         # for yr in model_year_ranges:
  69.         yr=model_year_ranges[j]
  70.         print "Creating", apr, "% tier for", yr, "and", created_tiers[i]
  71.         EnhancedAutoLoanRate.objects.create(credit_union=c,
  72.                                             vehicle_year_range=yr,
  73.                                             credit_history_tier=created_tiers[i],
  74.                                             loan_term=mos,
  75.                                             apr=apr)
  76.  
  77.  

Reply to "Untitled"

Here you can reply to the paste above