Procházet zdrojové kódy

Add option to print dense for easy copying

JoostSijm před 6 roky
rodič
revize
2cb1e2cf2a
1 změnil soubory, kde provedl 28 přidání a 14 odebrání
  1. 28 14
      index.py

+ 28 - 14
index.py

@@ -4,13 +4,15 @@ Calculate percentage level of index for regions
 inside the Verenigde Nederlanden.
 """
 
-REGIONS = [
-    'Amsterdam',
-    'Northern Netherlands',
-    'Eastern Netherlands',
-    'Western Netherlands',
-    'Southern Netherlands',
-]
+REGIONS = {
+    'Northern Netherlands': None,
+    'Eastern Netherlands': None,
+    'Southern Netherlands': None,
+    'Western Netherlands': None,
+    'Amsterdam': None,
+}
+
+PRINT_DENSE = True
 
 def region_in_string(string):
     """Look for region in string"""
@@ -22,7 +24,7 @@ def region_in_string(string):
 
 def calculate_index():
     """Calculate index bases on file"""
-    with open('regions.txt', 'r') as file:
+    with open('index.txt', 'r') as file:
         line_nr = 0
         last_percentage = 11
         for line in file:
@@ -32,12 +34,24 @@ def calculate_index():
                 diff_percentage = last_percentage - percentage
                 last_percentage = percentage
                 region = line.strip().split('\t')
-                print('%40s %2s %6.2f %% %6.2f %%' % (
-                    region[0],
-                    region[1],
-                    percentage,
-                    diff_percentage
-                ))
+                REGIONS[region[0].strip()] = percentage
+                if not PRINT_DENSE:
+                    print('%40s %2s %6.2f %% %6.2f %%' % (
+                        region[0],
+                        region[1],
+                        percentage,
+                        diff_percentage
+                    ))
+
+        if PRINT_DENSE:
+            index = 1
+            length = len(REGIONS)
+            for region in REGIONS:
+                if index == length:
+                    print('%.2f' % REGIONS[region])
+                else:
+                    print('%.2f,' % REGIONS[region], end='')
+                index += 1
 
 
 if __name__ == '__main__':