11#! /bin/bash
22
3- # Define array of exchanges
4- EXCHANGES=(" binance" " kucoin" " coinbase" " kraken" " bybit" )
3+ # my_array=("binance" "okx")
4+ my_array=()
5+ items=$( echo " $EXCHANGES_JSON " | sed ' s/^\[//;s/\]$//;s/"//g;s/ //g' )
6+ IFS=' ,' read -ra my_array <<< " $items"
57
6- # Create the section content in a variable
7- SECTION= $' \n ## Exchange Repositories \n\n '
8+ # Define the marker string
9+ marker= " ### See our other exchanges "
810
9- # Generate links for each exchange
10- for exchange in " ${EXCHANGES[@]} " ; do
11- SECTION+=" - [python-${exchange} ](https://github.com/ccxt/python-${exchange} .git)" $' \n '
12- done
11+ # Define the README file path
12+ readme_file=" $GITHUB_WORKSPACE /README.md"
1313
14- # Update README with perl (no temp files)
15- perl -i -0pe " s/## Exchange Repositories.*?(^##|\Z)/$SECTION \$ 1/ms" ./../README.md || {
16- # If section doesn't exist, append it
17- echo " $SECTION " >> ./../README.md
14+ # Function to generate the list items
15+ generate_list_items () {
16+ local repo_prefix=" https://github.com/my/"
17+ local list_string=" "
18+
19+ for item in " ${my_array[@]} " ; do
20+ list_string+=" - [**$item ** python](${repo_prefix}${item} )\n"
21+ done
22+
23+ printf " %s" " $list_string "
1824}
1925
20- # Display the changes
21- cat ./../README.md
26+ # Check if the README file exists
27+ if [ ! -f " $readme_file " ]; then
28+ echo " Error: README.md not found."
29+ exit 1
30+ fi
31+
32+ # Read the README file and remove everything after the marker
33+ content=$( sed " /$marker /q" " $readme_file " )
34+
35+ # Generate the list items
36+ list_items=$( generate_list_items)
37+
38+ # Append the marker and the new list items
39+ new_content=" $content \n$marker \n$list_items "
40+
41+ # Write the new content to the README file
42+ echo -e " $new_content " > " $readme_file " # -e to process escape sequences
43+
44+ echo " README.md updated successfully."
0 commit comments