a = """
Bishop Guertin DI	Demers/Iuliano	9	Ghill, NT, StMarks, ND, Blake, MBA, BF, GD, Harvard

Niles West NP	Noparstak/Patel	9	StMarks, Mich, Gbx, OV, Blake, MBA, BF, Cal, Hoflo

Brophy MS	McCoy/Singer	8	Gtown, Meadows, ND, Gbx, MBA, ASU, GD, Harvard

Glenbrook North DK	Donovan/Knez	8	Ghill, Gtown, StMarks, Mich, *Blake, MBA, BF, Cal

Glenbrook South CM	Callahan/Mitchell	7	Niles, NT, StMarks, Dowling, Blake, BF, Harvard

St. Mark's School Of Texas JM	Jain/Marshall	7	Grapevine, Ghill, Gbx, Alta, MBA, Stanford, Cal

Stratford OS	Ogle/Sanjeev	7	Ghill, StMarks, Gbx, Blake, MBA, BF, Harvard

Westminster BG	Basco/Gupta	7	Wake, Ghill, StMarks, Mich, Gbx, MBA, Harvard

Whitney Young DS	Dastrup/Sears	7	Valley, Mich, Gbx, Alta, MBA, BF, Cal

Carrollton GR	Gonzalez/Ryshawy	6	Ghill, ND, Gbx, MBA, BF, Harvard

Centennial KK	Koo/Koo	6	Ghill, Gtown, Bronx, Gbx, Blake, MBA

Highland Park HS	Hampton/Sundaresan	6	Wake, Grapevine, Ghill, StMarks, Colleyville, Cal

Notre Dame AB	Aaronson/Berger	6	LB, Meadows, Alta, MBA, BF, Cal

Pine Crest GJ	Gruber/Jain	6	NT, Bronx, Mich, BF, Stanford, Cal

Wayzata HL	Haas/Larsen	6	Caucus, Mich, Gbx, Dowling, Blake, Cal

Acorn AJ	Anderson/Jeffers	5	Bronx, Scranton, Lex, Harvard, Lakeland

Bronx Law AL	Athanasopoulos/Liriano	5	Wake, Ghill, Lex, BF, Harvard

C.E. Byrd GN	Gustavson/Nabors	5	Ghill, Memorial, UT, HH, Colleyville

Glenbrook South CK	Coleman/Kenner	5	Niles, StMarks, Mich, Dowling, Blake

Greenhill DJ	Daftary/Jaramillo	5	Grapevine, StMarks, Meadows, Gbx, Harvard

Iowa City West MY	Moser/Yan	5	NT, Caucus, Mich, Blake, MBA

Lexington FK	Fraser/Krishnan	5	Ghill, StMarks, MBA, BF, Harvard

Niles West CK	Chan/Kang	5	NT, *Gbx, Blake, BF, Hoflo

Pace LS	Lewis/Shepherd	5	Hooch, *Mich, Gbx, Lex, BF

Pine Crest LM	Levy/McCue	5	Wake, Ghill, StMarks, MBA, Cal

Polytechnic AA	Alison/Asimow	5	Wake, StMarks, Alta, GD, Cal

Bronx Science DM	Drecker-Waxman/Mayar	4	UT, Lex, BF, Harvard

Capitol Debate HP	Hirsch/Park	4	Wake, Gtown, Capitol, Scranton

Cedar Ridge PR	Pabst/Robinson	4	Ghill, Memorial, Colleyville, Cal

College Prep AG	Attiyeh/Givan	4	ND, Gbx, Alta, MBA

Glenbrook North CH	Choi/Hill	4	Ghill, StMarks, BF, Harvard

Glenbrook North MT	Matlin/Tashma	4	StMarks, Mich, Blake, BF

St Vincent de Paul MY	Martin/Young	4	Wake, ND, Gonzaga, Lex

University Prep DK	Dean/Kimbrough	4	NT, Gbx, Blake, Cal

Wayzata GN	Gehling/Narayan	4	Valley, Caucus, Mich, Gbx

College Prep FP	Fiero/Ping	3	Ghill, Meadows, Gbx

Dexter MS	Maxey/Sadler	3	NT, OV, MBA

Kinkaid BR	Bleiweiss/Rosenthal	3	Meadows, Memorial, UT

Pace HP	Howard/Parikh	3	Hooch, StMarks, Mich

Rowland Hall St Marks GK	Goldman/Kovnick	3	Meadows, Bingham, Cal

St Paul Central BN	Bellamy/Natala	3	Scranton, Blake, Cal

Westminster HH	Hall/Hall	3	OV, Samford, GD

Westminster HL	Hall/Li	3	Ghill, Gtown, *Gbx

Austin SFA EE	Estrada/Estrada	2	Grapevine, Colleyville

Baltimore City College GM	Gaylin/Motevalli	2	Capitol, Pennsbury

Barstow DN	Dunn/Nanji	2	NT, Westside

Bishop Guertin SZ	Stekl/Zoda	2	PC, Harvard

Brooklyn Tech CN	Chui/Noel	2	Bronx, Harvard

Caddo Magnet CM	Conner/Martin	2	UT, Samford

College Prep BY	Bishop/Yamasaki	2	*Alta, Stanford

Homewood Flossmoor FR	Fontana/Runberg	2	Mich, Dowling

Interlake LM	Lim/Menninga	2	Gonzaga, Cal

Jenks DR	D'Onofrio/Reinking	2	Grapevine, UT

Juan Diego AC	Andrews/Carlson	2	Alta, Bingham

Juan Diego FW	Frederick/Walrath	2	ND, GD

Loyola AC	Aguilar/Chung	2	Meadows, ASU

Minneapolis South OT	Ouellette-Howitz/Thompson	2	Caucus, Dowling

New Trier PW	Piekos/Watkins	2	OV, Blake

Polytechnic HM	Hathaway/Medrano	2	La Costa, ASU

Reservoir SS	Smith/Smith	2	Gtown, Lex

River Hill DD	Datta/Datta	2	Lex, Lakeland

Sioux Falls Roosevelt KM	Munsinger/Kroger	2	Dowling, UGA

Thomas Jefferson Hs For Science And Techn KW	Kaplun/Wang	2	Pennsbury, Harvard

Westminster FM	Forman/Madhusudan	2	StMarks, Mich

Westminster MO	Madhusudan/Odermatt	2	*Wake, *Gtown

Alpharetta HM	Hesu/Moxley	1	OV

Alpine HW	Hayes/Weakley	1	CSUF

Baltimore City College BrGa	Brown/Gaylin	1	Lakeland

Baltimore City College BrGi	Brown/Gilliam-Price	1	Gtown

Blake SW	Shaikh/Wang	1	GD

Blue Valley North WY	Womack/Yang	1	KCKCC

Blue Valley Southwest HS	Hegna/Super	1	KCKCC

Bronx Science GL	Gopaul/Li	1	Lex

C.E. Byrd DN	Desobry/Nabors	1	Grapevine

Caddo Magnet JM	Jain/Martin	1	Memorial

Chattahoochee AS	Adam/Shelton	1	Wake

Chattahoochee IP	Ilango/Peramanu	1	OV

College Prep AF	Attiyeh/Fiero	1	Stanford

College Prep HJ	Hubinger/Jiang	1	CSUF

Coppell BJ	Ballard/Javeri	1	Grapevine

Dallas Jesuit FP	Ferrara/Pyke	1	UT

Damien CS	Canjanding/Stroud	1	*ND

Damien LL	Lansang/Luevano	1	LB

Damien LR	Luevano/Reyes	1	ASU

Damien MR	Munoz/Reyes	1	ND

Denver School of the Arts FF	Finley/Friesen-Johnson	1	Blake

Dowling WZ	Weinhardt/Zaun	1	Gonzaga

Eastside BR	Bhatti/Ross	1	Scranton

Edgemont KX	Kohli/Xu	1	Lakeland

Glenbrook North HK	Hensel/Kahn	1	Mich

Glenbrook North MS	Merchant/Spector	1	Blake

Glenbrook South CR	Callahan/Roche	1	*Niles

Glenbrook South DL	Dravid/Lin	1	*Niles

Green Valley BH	Bhatti/Horn	1	GD

Groves CP	Couger/Pasquinelli	1	Mich

Gulliver Prep AS	Asilis/Soria	1	UGA

Harker KM	Kaul/Midha	1	GD

Head Royce FM	Fong/Manley	1	ND

Homewood Flossmoor LS	Levinson/Swetz	1	Dowling

Iowa City West ST	Siddig/Trepka	1	Dowling

Katy Taylor AL	Alattar/Li	1	Cal

Kinkaid BY	Bajwa/Yerramsetti	1	UT

Leucadia Independent GY	Goldschlag/Yamout	1	Meadows

Lexington AX	Atia/Xie	1	Harvard

Liberal Arts & Science BC	Barrish/Cui	1	HH

Liberal Arts & Science SY	Shah/Yoon	1	UT

McDonogh ER	Eckhaus/Resar	1	Gtown

Nevada Union CH	Colen/Hill-Weld	1	La Costa

Niles North OW	Oberto-Besso Pa/Walkington	1	PC

Niles West CH	Charles/Harbeck	1	Hoflo

Northside ER	Esman/Roth	1	Blake

Notre Dame LP	Lubell/Pismarov	1	Alta

Pace MP	Movsovitz/Parikh	1	UGA

Pace PQ	Parikh/Queller	1	OV

Pine Crest MM	Marcus/Marcus	1	UGA

River Hill SS	Srivastava/Srivastava	1	Lakeland

Rowland Hall St Marks RW	Reed-Guevara/Wang	1	Alta

Shawnee Mission East RT	Ramaswami/Throckmorton	1	Valley

St Francis RS	Rout/Sharma	1	Gonzaga

St Ignatius BP	Beddow/Pucci	1	Mich

St Ignatius LP	Lavelle/Pendekanti	1	Hoflo

St Paul Central BF	Bartashevich/Foster	1	Valley

Wayzata DK	DePass/Krishnan	1	Westside

Westminster CD	Carithers/Dayal	1	*Harvard

Westminster FS	Forman/Seitz	1	Gbx

Westminster LS	Li/Shen	1	OV

Westwood JR	Jaladi/Reddy	1	Grapevine
"""

tourns = {"Ghill": "Greenhill", "NT": "New Trier", "StMarks": "St. Marks",
          "Blake": "Blake", "MBA": "MBA", "ND": "Notre Dame", "GD": "Golden Desert",
          "Harvard": "Harvard", "ASU": "ASU", "OV": "Ohio Valley", "Mich": "UMich",
          "BF": "Emory", "Grapevine": "Grapevine", "Dowling": "Downling", "Cal": "Berkeley",
          "Gbx": "Glenbrooks", "Gtown": "Georgetown"}

from api.models import Tournament, Team

def process_tourns(t_list):
  final_list = []
  for item in t_list:
  	t_name = ""
  	for char in item:
  	  if char != "*" and char != " ":
  	  	t_name += char
  	if t_name in tourns.keys():
  	  t_name = tourns[t_name]
  	final_list.append(t_name)
  return final_list

def get_bid_list(a):
  b = a.split("\n")
  d = []
  for c in b:
    if c:
  	  e = c.split("\t")
  	  d.append(e)
  data_list = []
  for f in d:
    data = {}
    data["team_code"] = f[0]
    data["team_name"] = f[1]
    data["num_bids"] = f[2]
    data["bid_tourns"] = process_tourns(f[3].split(","))
    data_list.append(data)
  return data_list

def enter_team_bids(a):
  bid_list = get_bid_list(a)
  for team in bid_list:
    try:
      team_obj = Team.objects.get(team_code = team["team_code"])
      for t_name in team["bid_tourns"]:
        try:
          tourn = Tournament.objects.get(tournament_name = t_name)
          team_obj.bids.add(tourn)
          print team["team_code"], t_name
        except:
          continue
      team_obj.save()
    except:
      continue

enter_team_bids(a)



