-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgn_to_litchess.py
27 lines (19 loc) · 921 Bytes
/
pgn_to_litchess.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
import urllib.parse
def generate_lichess_analysis_link(pgn_moves):
# Split the input PGN moves into individual moves
moves_list = pgn_moves.split()
# Format the PGN moves with spaces between moves for readability
formatted_moves = " ".join(moves_list)
# Encode the formatted PGN moves
encoded_moves = urllib.parse.quote(formatted_moves)
# Construct the URL for the Lichess analysis board with the PGN data
lichess_analysis_url = f"https://lichess.org/analysis/pgn/{encoded_moves}"
return lichess_analysis_url
# Example usage:
# Assuming `pgn_moves` is a string containing the PGN moves generated by your Python program
pgn_moves = "1.e4 nan.e5 nan.Bf1c4 nan.Nb8c6 nan.Qd1f3 nan.d6 nan.Qf3xf7"
# Generate the Lichess analysis link
lichess_link = generate_lichess_analysis_link(pgn_moves)
# Print or use the generated link
print("Lichess Analysis Link:")
print(lichess_link)