Advertisement
campos20

3 days comp with few events

Jul 12th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. from datetime import date
  2. import csv
  3.  
  4. limit = 100
  5.  
  6. def get_comp_with_n_days(days):
  7.     out = []
  8.     c = True
  9.     with open('WCA_export_Competitions.tsv','rb') as tsvin:
  10.         tsvin = csv.reader(tsvin, delimiter='\t')
  11.        
  12.         name = []
  13.         country = []
  14.         events_number = []
  15.        
  16.         for line in tsvin:
  17.             if c:
  18.                 c = False
  19.                 continue
  20.            
  21.             year = int(line[5])
  22.             month = int(line[6])
  23.             day = int(line[7])
  24.             end_month = int(line[8])
  25.             end_day = int(line[9])
  26.            
  27.             d0 = date(year, month, day)
  28.             d1 = date(year, end_month, end_day)
  29.            
  30.             delta = d1 - d0
  31.            
  32.             if abs(delta.days)+1 == days:
  33.                 name.append(line[1])
  34.                 country.append(line[3])
  35.                 events_number.append(len(line[10].split()))
  36.    
  37.     count = 0
  38.     previous = 0
  39.     for x, y, z in sorted(zip(events_number, name, country)):
  40.         count += 1
  41.         if (count >= limit and x != previous) or (x>17): break
  42.         previous = x
  43.         print x, "-", y, "-", z
  44.  
  45. get_comp_with_n_days(3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement