|
|
@@ -0,0 +1,47 @@
|
|
|
+"""Calculate donations"""
|
|
|
+
|
|
|
+import re
|
|
|
+
|
|
|
+RESOURCES = {
|
|
|
+ 'bbl': {},
|
|
|
+ 'kg': {},
|
|
|
+ 'pcs': {},
|
|
|
+ 'G': {},
|
|
|
+ 'g': {},
|
|
|
+ '$': {},
|
|
|
+}
|
|
|
+
|
|
|
+def sum_donations():
|
|
|
+ """Count total donations"""
|
|
|
+ with open('donation.txt', 'r') as file:
|
|
|
+ for line in file:
|
|
|
+ try:
|
|
|
+ donation = re.search(r'\d.*?(bbl|kg|pcs|G|g|\$)', line).group(0)
|
|
|
+ player = re.search(r'.*?\s\t', line).group(0).strip()
|
|
|
+ print(donation)
|
|
|
+ amount, resource = donation.split(' ')
|
|
|
+ amount = int(amount.replace('.', ''))
|
|
|
+
|
|
|
+ if player not in RESOURCES[resource]:
|
|
|
+ RESOURCES[resource][player] = 0
|
|
|
+ RESOURCES[resource][player] += amount
|
|
|
+
|
|
|
+ except Exception as exception:
|
|
|
+ print('exception')
|
|
|
+ print('%s %s' % (line, exception))
|
|
|
+
|
|
|
+
|
|
|
+ for resource, players in RESOURCES.items():
|
|
|
+ print(resource)
|
|
|
+ count = 1
|
|
|
+ for player in sorted(players, key=players.get, reverse=True):
|
|
|
+ print('%12d %s' % (players[player], player))
|
|
|
+ if count >= 10:
|
|
|
+ break;
|
|
|
+ count += 1
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ sum_donations()
|