I'm trying to use Selenium to mass post tennis events to a website using a .CSV file. I've almost got it finished, but for some reason I cannot make it so that the player with the higher ranking (higher being closer to number 1) comes first in the event name.
Here I want to produce a title of Wimbledon Federer vs Tsonga, but it keeps coming out as Wimbledon Tsonga vs Federer.
Here is an example of the data being used:
| Winner [9] | Loser [10] | WRank [11] | LRank [12] |
|---|---|---|---|
| Tsonga J.W. | Federer R. | 19 | 3 |
Here is the code:
player_1_rank = line[11]
player_2_rank = line[12]
if player_1_rank < player_2_rank:
player_1 = line[9]
player_2 = line[10]
player_1_rank = line[11]
player_2_rank = line[12]
else:
player_2 = line[9]
player_1 = line[10]
player_2_rank = line[11]
player_1_rank = line[12]
# Deletes player initials.
if player_1.count(".") == 1:
player_1 = ''.join(player_1.split())[:-2]
elif player_1.count(".") == 2:
player_1 = ''.join(player_1.split())[:-4]
if player_2.count(".") == 1:
player_2 = ''.join(player_2.split())[:-2]
elif player_2.count(".") == 2:
player_2 = ''.join(player_2.split())[:-4]
tournament_name = line[2]
driver.find_element_by_name("eventname").send_keys(tournament_name+" "+player_1+" vs "+player_2)
Full script can be found here.
Full .CSV data file can be found here.
I'm sure its bound to be something minor I'm missing, but I really need another set of eyes to look at this for me. Thanks for any help you can provide.
Aucun commentaire:
Enregistrer un commentaire