Bladeren bron

Add file parameter

JoostSijm 5 jaren geleden
bovenliggende
commit
58c3defaab
1 gewijzigde bestanden met toevoegingen van 15 en 10 verwijderingen
  1. 15 10
      donations/donations.py

+ 15 - 10
donations/donations.py

@@ -1,10 +1,11 @@
 """Calculate donations"""
 
+import sys
 import re
 import math
 
 
-def sum_donations():
+def sum_donations(filename='donations.txt'):
     """Count total donations"""
     resources = {
         'bbl': {},
@@ -14,7 +15,7 @@ def sum_donations():
         'g': {},
         '$': {},
     }
-    with open('donations.txt', 'r') as file:
+    with open(filename, 'r') as file:
         for line in file:
             try:
                 donation = re.search(r'\d.*?(bbl|kg|pcs|G|g|\$)', line).group(0)
@@ -52,16 +53,16 @@ def print_resources(resources):
 def calc_reward(resources):
     """Calculate reward"""
     reward = {
-        'bbl': 130,
-        'kg': 120,
-        'pcs': 850000,
-        'g': 1250,
+        'bbl':    130,
+        'kg':     120,
+        'g':     1120,
+        'pcs': 840000,
     }
     resource_koef = {
         'bbl': 1000000000,
-        'kg': 1105000000,
-        'pcs': 104000000,
-        'g': 160000,
+        'kg':  1105000000,
+        'g':    100000000,
+        'pcs':     150000,
     }
     player_reward = {}
     for resource, players in resources.items():
@@ -95,7 +96,11 @@ def bucks(integer):
 
 
 if __name__ == '__main__':
-    RESOURCES = sum_donations()
+    RESOURCES = None
+    if len(sys.argv) < 2:
+        RESOURCES = sum_donations()
+    else:
+        RESOURCES = sum_donations(sys.argv[1])
     PLAYERS = calc_reward(RESOURCES)
     print_reward(PLAYERS)
     print_resources(RESOURCES)