-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathissue_monthly.py
executable file
·81 lines (63 loc) · 2.49 KB
/
issue_monthly.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import datetime as datetime
import os
def organize_monthly(path):
opened_per_month_path = path + 'opened-per-month/'
closed_per_month_path = path + 'closed-per-month/'
if not os.path.exists(closed_per_month_path):
os.makedirs(closed_per_month_path)
if not os.path.exists(opened_per_month_path):
os.makedirs(opened_per_month_path)
for file in os.listdir(path):
if file.endswith('.txt'):
this_file = open(os.path.join(path,file))
this_data = this_file.readlines()[1:]
opened,closed = collect_issues(this_data)
organize_and_write_file(opened,opened_per_month_path,str(file))
organize_and_write_file(closed,closed_per_month_path,str(file))
def collect_issues(this_data):
open_list = []
close_list = []
for line in this_data:
line = line.strip()
line = line.split(',')
open_raw = line[4]
close_raw = line[5]
open_value = open_raw.split('/')
open_date = datetime_it(open_value[2],open_value[1],open_value[0])
open_list.append(open_date)
if '-' in close_raw:
close_raw_dates = close_raw.split('-')
for date in close_raw_dates:
this_close_value = date.split('/')
this_close_date = datetime_it(this_close_value[2],this_close_value[1],this_close_value[0])
close_list.append(this_close_date)
else:
if not 'None' in close_raw:
close_value = close_raw.split('/')
close_date = datetime_it(close_value[2],close_value[1],close_value[0])
close_list.append(close_date)
return open_list,close_list
def datetime_it(day,month,year):
date = datetime.datetime(int(day),int(month),int(year))
return date
def organize_and_write_file(data,folder_path,file_name):
this_file = open(os.path.join(folder_path + file_name),'w')
years = []
for date in data:
if date.year not in years:
years.append(date.year)
months = [[list() for month in range(12)] for year in range(len(years))]
for current_year, current_month_list in zip(years, months):
for current_month_number, month in zip(range(1,13), current_month_list):
for date in data:
if date.year == current_year:
if date.month == current_month_number:
month.append(date.day)
for year,month in zip(years,months):
this_file.write(str(year))
this_file.write('\n')
for month_number, month_data in zip(range(1,13), month):
this_file.write(str(month_number) + '->' + str(len(month_data)))
this_file.write('\n')
issue_folder_path = raw_input('Please specify the folder where are the data generated by IssueSpider.py:')
organize_monthly(issue_folder_path)