Skip to content

Commit

Permalink
rstrip->re
Browse files Browse the repository at this point in the history
  • Loading branch information
CMIP-IPO GitHub Action committed Nov 13, 2023
1 parent 10e9071 commit d6d7cc5
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 21 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/create_cv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
print('Create CV ')
import json
import os
import os,re
from glob import glob
from urllib import request
from datetime import datetime, timedelta
Expand All @@ -16,8 +16,16 @@
'''
Github action test script:
export PATH="${HOME}/Applications/Docker.app/Contents/Resources/bin:$PATH"
act -s GITHUB_TOKEN="$(gh auth token)" --container-architecture linux/amd64 --verbose -b & sleep 4 &&
docker exec -it act-Generate-CV-file-create-branch-and-update-files-cabe81e196626eaf2f1a205b6f6f95341b0aa587d4d7127baba6ccfa7bef525apacman -S /usr/bin/bash -c "cd .github/workflows/;python create_cv.py;cd ../../CVs;more CV.json;exit"
docker exec -it act-Generate-CV-file-create-branch-and-update-files-cabe81e196626eaf2f1a205b6f6f95341b0aa587d4d7127baba6ccfa7bef525a /bin/bash
docker exec -it act-Generate-CV-file-create-branch-and-update-files-cabe81e196626eaf2f1a205b6f6f95341b0aa587d4d7127baba6ccfa7bef525a /bin/bash -c "fq '.CV.table_id' CVs/CV.json";
-S /usr/bin/bash -c "cd .github/workflows/;python create_cv.py;cd ../../CVs;more CV.json;exit"
sudo apt-update
sudo apt install snapd
Expand All @@ -39,6 +47,7 @@
mip_tables = 'mip-cmor-tables'
table_prefix = 'MIP_'

pattern = re.compile(f'^{re.escape(table_prefix)}_*|\.json$')

###################################
# define functions
Expand Down Expand Up @@ -142,7 +151,7 @@ def notnull(dictionary, keys,replace='none'):

if entry == 'table_id':
# extract tables using github api
CV['table_id'] = [t.get('name').rstrip('.json').lstrip(table_prefix) for t in read_contents_from_github('PCMDI',mip_tables,'Tables')]
CV['table_id'] = [ pattern.sub('', t.get('name')) for t in read_contents_from_github('PCMDI',mip_tables,'Tables') ]


elif os.path.exists(os.path.abspath(file)):
Expand Down
120 changes: 120 additions & 0 deletions .github/workflows/jqp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/bin/bash



organize_output() {
declare -a headings
current_heading=""

while read -r line; do
if [[ -z "$current_heading" ]]; then
current_heading="$line"
headings["$current_heading"]=1
else
if [[ "$line" == *"/"* ]]; then
headings["$current_heading"]+="\n - $line"
else
current_heading="$line"
headings["$current_heading"]=1
fi
fi
done <<< "$1"

for heading in "${!headings[@]}"; do
echo "$heading"
echo -e "${headings[$heading]}"
done
}



# if [ "$#" -ne 1 ]; then
# echo "Usage: $0 <filename>"
# exit 1
# fi

# filename=$1



# overwrite!
filename='../../CVs/CV.json'

if [ ! -f "$filename" ]; then
echo "File '$filename' not found."
exit 1
fi

while true; do
echo "Enter JSON command (press Ctrl+C to exit):"
read -r -e -p "> " user_input
history -s "$user_input"

if [ -z "$user_input" ]; then
continue
fi

# Check if user_input matches the 'k\d' regex
if echo "$user_input" | grep -Eq 'k[0-9]+'; then
# Custom command replacements only if it matches the regex
user_input=$(echo "$user_input" | perl -pe 's/k(\d+)/".".("[]" x ${$1-1}) . " | keys"/eg')
fi

echo "$user_input"

jq "${user_input}" "${filename}"
# result=$(jq "${user_input}" "${filename}")

# if [ $? -eq 0 ]; then
# echo "Result:"
# echo "$result"
# else
# echo "Error executing jq:"
# echo "$result"
# fi

# # organize_output "$result"

done


# path(..) | map(select(type == "string")) | select(length <= 2) | join("/")



# #!/bin/bash

# if [ "$#" -ne 1 ]; then
# echo "Usage: $0 <filename>"
# exit 1
# fi

# filename=$1

# if [ ! -f "$filename" ]; then
# echo "File '$filename' not found."
# exit 1
# fi

# while true; do

# echo "Enter JSON data (press Ctrl+C to exit):"
# # read -r user_input
# read -r -e -p "Enter JSON command (press Ctrl+C to exit): " user_input

# history -s "$user_input"

# result= jq ${user_input} ${filename}

# if [ $? -eq 0 ]; then
# echo "Result:"
# echo "$result"
# else
# echo "Error executing jq:"
# echo "$result"
# fi

# # read -e -p "Enter JSON command (press Ctrl+C to exit): " user_input

# done

36 changes: 18 additions & 18 deletions CVs/CV.json
Original file line number Diff line number Diff line change
Expand Up @@ -792,23 +792,23 @@
}
},
"source_type": [
"CHEM",
"AOGCM",
"AER",
"OGCM",
"SLAB",
"ISM",
"AOGCM",
"RAD",
"CHEM",
"BGC",
"OGCM",
"LAND",
"AER",
"AGCM"
"RAD",
"AGCM",
"LAND"
],
"sub_experiment_id": {
"f2023": "Forcings 2023",
"none": "none"
},
"table_id": [
"ACm",
"ACmon",
"ACmonZ",
"AE1hr",
"AE3hrPt",
Expand All @@ -817,7 +817,7 @@
"AE6hrPt",
"AE6hrPtLev",
"AEday",
"AEm",
"AEmon",
"AEmonLev",
"AEmonZ",
"AEsubhrPt",
Expand All @@ -835,7 +835,7 @@
"APdayLev",
"APdayZ",
"APfx",
"APm",
"APmon",
"APmonClim",
"APmonClimLev",
"APmonDiurnal",
Expand All @@ -845,27 +845,27 @@
"APsubhrPtLev",
"APsubhrPtSite",
"GIAfx",
"GIAm",
"GIAmon",
"GIAyr",
"GIGfx",
"GIGm",
"GIGmon",
"GIGyr",
"LI3hrPt",
"LI6hrPt",
"LIday",
"LIfx",
"LIm",
"LImon",
"LIsubhrPtSite",
"LP3hr",
"LP3hrPt",
"LP6hrPt",
"LPday",
"LPfx",
"LPm",
"LPmon",
"LPyr",
"LPyrPt",
"OBday",
"OBm",
"OBmon",
"OBmonLev",
"OByr",
"OByrLev",
Expand All @@ -875,23 +875,23 @@
"OPdecLev",
"OPdecZ",
"OPfx",
"OPm",
"OPmon",
"OPmonClim",
"OPmonClimLev",
"OPmonLev",
"OPmonZ",
"OPyr",
"OPyrLev",
"SIday",
"SIm",
"SImon",
"SImonPt"
],
"tracking_id": [
"hdl:21.14100/.*"
]
},
"version_metadata": {
"file_updated": "Monday November 13 14:59 UTC",
"file_updated": "Monday November 13 20:13 UTC",
"CVs": {
"updated": "",
"tag": "",
Expand Down

0 comments on commit d6d7cc5

Please sign in to comment.