Isoraqathedh

Currency To Time converter II

Jul 15th, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import easygui
  2. import csv
  3.  
  4. winTitle = "Dollar To Time Converter"
  5. convUnitsUp = (46, 5, 182/5, 1000, 1000, 65, 540/65, 4567/540, 3)
  6. unitNames = ("minute(s)", "day(s)", "week(s)", "year(s)", "millenium/a", "million year(s)", "Cretacean(s)", "Cambria(s)", "Earth(s)", "Universe(s)")
  7. oneK = "000"
  8. divisors = (("k", oneK), ("M", oneK * 2), ("G", oneK * 3), ("T", oneK * 4))
  9. finalString = ""
  10. displayFactoid = False
  11. millionYearsValue = 0
  12. #  $ 1          = 1 min
  13. #   46 mins     = 1 day
  14. #    5 days     = 1 week
  15. #  182 days     = 1 year
  16. # 1000 years    = 1 millenium
  17. # 1000 millenia = 1 ice age
  18. #   65 ice ages = 1 Cretaceous
  19. #  540 ice ages = 1 Cambrian
  20. # 4567 ice ages = 1 Earth
  21. #    3 Earths   = 1 Universe
  22. currencyUnit = [-1, -1]
  23. while currencyUnit[0] == -1 and currencyUnit[1] == -1:
  24.     inValue = easygui.enterbox("Enter a dollar amount, followed by USD or HKD", winTitle)
  25.     currencyUnit = [inValue.find("USD"), inValue.find("HKD")]
  26.     for i in divisors:
  27.         inValue = inValue.replace(i[0], i[1])
  28.         # to do: don't be lazy and actually multiply the dang thing.
  29.     # In any case, parse integer (or just crop off the USD/HKD!)
  30.     currencyValue = int(inValue[:-4])
  31.     if not currencyUnit[0] == -1:
  32.         # if USD, divide by 7.8
  33.         currencyValue = currencyValue * 7.8
  34.         break
  35.     elif not currencyUnit[1] == -1:
  36.         break
  37. j = 0
  38. print("  {0} {1}".format(round(currencyValue, 3), unitNames[0]))
  39. for i in convUnitsUp:
  40.     currencyValue = currencyValue / i
  41.     print("= {0} {1}".format(round(currencyValue, 3), unitNames[j+1]))
  42.     if currencyValue < 1:
  43.         currencyValue = currencyValue * i
  44.         break
  45.     j = j+1
  46.     if j == 5:
  47.         displayFactoid = True
  48.         millionYearsValue = currencyValue
  49. if displayFactoid:
  50.     with open('lunchValues.csv', 'r', newline='') as dataFile:
  51.         timeReader = csv.reader(dataFile)
  52.         provisionalProperties = ["", ""]
  53.         for row in timeReader:
  54.             if int(row[0]) > millionYearsValue:
  55.                 break
  56.             else:
  57.                 provisionalProperties = [row[1], row[2]]
  58.     descrString = "; it was the {0} then, and back then {1}".format(provisionalProperties[0], provisionalProperties[1])
  59. else:
  60.     descrString = "."
  61. finalString = "That amount of money will buy lunch for {0} {1}{2}".format(round(currencyValue, 3), unitNames[j], descrString)
  62. easygui.msgbox(finalString, winTitle)
Advertisement
Add Comment
Please, Sign In to add comment