#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import json

data_input = []
data_output = []

file_input = sys.argv[1]
file_output = sys.argv[2]

input_field = ['users, ','spaces, ','milestones, ','ticket_statuses, ','tickets, ','estimate_histories, ','user_tasks, ','ticket_comments, ','ticket_associations, ']
input_dict = {}
multiple_input ={}

for s in input_field:
	input_dict[s] = ''
	multiple_input[s] = False


with open(file_input) as f:

	for line in f:

		for s in input_field:
			if line.startswith(s):
				if multiple_input[s]:
					input_dict[s] += ','+line[len(s):-1]
				else:
					input_dict[s] += line[len(s):-1]
					multiple_input[s] = True


for s in input_field:
	data_input.append(json.loads('{"'+s[:-2]+'": ['+input_dict[s]+']}'))


#data_input.append(json.loads('{"users": ['+input_dict['users, ']+']}'))
#data_input.append(json.loads('{"user_tasks": ['+input_dict['user_tasks, ']+']}'))
#data_input.append(json.loads('{"tickets": ['+input_dict['tickets, ']+']}'))

print len(data_input[0]["users"])

users_output = ''
for i, element in enumerate(data_input[0]["users"]):
	users_output += '{"name":"'+element["login"]+'","fullname": "'+element["fullname"]+'"}'
	if i < len(data_input[0]["users"])-1:
		users_output += ','


#for element in data_input[2]["tickets"]:
#	print element["summary"]


data_output.append(json.loads('{"users": ['+users_output+']}'))





with open(file_output, 'wb') as f:
	f.write(json.dumps(data_output))

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import json

data_input = []
data_output = []

file_input = sys.argv[1]
file_output = sys.argv[2]

input_field = ['users, ','spaces, ','milestones, ','ticket_statuses, ','tickets, ','estimate_histories, ','user_tasks, ','ticket_comments, ','ticket_associations, ']
input_dict = {}
multiple_input ={}

for s in input_field:
	input_dict[s] = ''
	multiple_input[s] = False


with open(file_input) as f:

	for line in f:

		for s in input_field:
			if line.startswith(s):
				if multiple_input[s]:
					input_dict[s] += ','+line[len(s):-1]
				else:
					input_dict[s] += line[len(s):-1]
					multiple_input[s] = True


for s in input_field:
	data_input.append(json.loads('{"'+s[:-2]+'": ['+input_dict[s]+']}'))

users_output = ''
for i, element in enumerate(data_input[0]["users"]):
	users_output += '{"name":"'+element["login"]+'","fullname": "'+element["fullname"]+'"}'
	if i < len(data_input[0]["users"])-1:
		users_output += ','

milestones_output = ''
for i, element in enumerate(data_input[2]["milestones"]):
	if element["is_completed"]==1:
		released='true'
	else:
		released='false'
	if element["due_date"] is None:
		releaseDate=''
	else:
		releaseDate=str(element["due_date"])+'T00:00:00+00:00'
	milestones_output +=  '{"name":"'+element["title"]+'","released":'+released+',"releaseDate":"'+releaseDate+'"}'
	if i < len(data_input[2]["milestones"])-1:
		milestones_output += ','	

project_output = ''
for i, element in enumerate(data_input[1]["spaces"]):
	project_output += '{"name":"'+element["name"]+'",'
	project_output += '"key":"'+element["name"][0:3]+'",'
	if element["description"] != "":
		project_output += '"description":"'+element["description"]+'",'
	project_output += '"versions":['+milestones_output+'],"components": ["Component","AnotherComponent"]}'
	#project_output += '"version":['+milestones_output+']}'
	if i < len(data_input[1]["spaces"])-1:
		project_output += ','

data_output.append(json.loads('{"users": ['+users_output+'],"projects": ['+project_output+']}'))


with open(file_output, 'wb') as f:
	f.write((json.dumps(data_output))[1:-1])



add projects and mileston support