<commit_before>#!/bin/bash
set -e
#set -x

TRANSIFEX_USER="<TRANSIFEX_USERNAME>"
TRANSIFEX_PASSWD="<<PASSWORD>>"
TRANSIFEX_API_URL="https://www.transifex.com/api/2/project/cataclysm-dda"


FTP_HOST="<WEB SITE FTP SERVER>"
FTP_USER="<FTP USERNAME>"
FTP_PASSWD="<<PASSWORD>>"

# Put all credentials info in this file if you want hide them.
# FTP_USER FTP_PASSWD TRANSIFEX_USER TRANSIFEX_PASSWD
#source cred.sh

# Where script will be store all files.
WORKING_DIR="<WORKING DIR>"

# This is constant values. Don't change it.
MASTER_RESOURCE="master-cataclysm-dda"
STABLE_RESOURCE="stable-cataclysm-dda"
OLD_RESOURCE="old-cataclysm-dda"

# Change it to your language.
LANG="ru"

OLD_PWD=$PWD

if [ -d "$WORKING_DIR" ]
then
    cd "$WORKING_DIR"
else
    mkdir "$WORKING_DIR"
    cd "$WORKING_DIR"
fi

# Main loop
for BRANCH in "MASTER" "STABLE" "OLD"
do
    # Magic with vars
    # Need update flag
    TO_UPDATE=false
    # Branch name in lowercase
    BR_LNAME=$(echo $BRANCH | tr '[:upper:]' '[:lower:]')
    # Transifex resource slug(internal name).
    TMP="${BRANCH}_RESOURCE"
    BR_RESOURCE=${!TMP}
    # Remote last update timestamp for branch.
    BR_REMOTE_TS=$(wget --quiet --output-document=- --user=$TRANSIFEX_USER \
    --password=$TRANSIFEX_PASSWD \
    $TRANSIFEX_API_URL/resource/$BR_RESOURCE/stats/$LANG/ | \
    grep '"last_update"' | \
    grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}')
    if [ -z "$BR_REMOTE_TS" ]
    then
        echo "'$BR_LNAME': Unable to get last update timestamp from API."
        exit 1
    else
        BR_REMOTE_TS=$(date --date="$BR_REMOTE_TS" +"%s")
    fi

    # Compare local/remote timestamps.
    BR_WORKDIR=$BR_LNAME
    if [ ! -d "$BR_WORKDIR" ]
    then
        mkdir "$BR_WORKDIR"
    fi
    if [ -f "$BR_WORKDIR/timestamp.txt" ]
    then
        BR_LOCAL_TS=$(cat "$BR_WORKDIR/timestamp.txt")
        if [ $BR_LOCAL_TS -lt $BR_REMOTE_TS ]
        then
          TO_UPDATE=true
        fi
    else
        echo "$BR_REMOTE_TS" > $BR_WORKDIR/timestamp.txt
        TO_UPDATE=true
    fi
    if $TO_UPDATE
    then
      cd $BR_WORKDIR
      # 1. Get updated translation
      wget --quiet --output-document=${BR_LNAME}.po \
      --user=$TRANSIFEX_USER --password=$TRANSIFEX_PASSWD \
      $TRANSIFEX_API_URL/resource/$BR_RESOURCE/translation/$LANG/?file
<commit_msg>fix timestamp file updates<commit_after>#!/bin/bash
set -e
#set -x

TRANSIFEX_USER="<TRANSIFEX_USERNAME>"
TRANSIFEX_PASSWD="<<PASSWORD>>"
TRANSIFEX_API_URL="https://www.transifex.com/api/2/project/cataclysm-dda"


FTP_HOST="<WEB SITE FTP SERVER>"
FTP_USER="<FTP USERNAME>"
FTP_PASSWD="<FTP_PASSWORD>"

# Put all credentials info in this file if you want hide them.
# FTP_USER FTP_PASSWD TRANSIFEX_USER TRANSIFEX_PASSWD
#source cred.sh

# Where script will be store all files.
WORKING_DIR="<WORKING DIR>"

# This is constant values. Don't change it.
MASTER_RESOURCE="master-cataclysm-dda"
STABLE_RESOURCE="stable-cataclysm-dda"
OLD_RESOURCE="old-cataclysm-dda"

# Change it to your language.
LANG="ru"

OLD_PWD=$PWD

if [ -d "$WORKING_DIR" ]
then
    cd "$WORKING_DIR"
else
    mkdir "$WORKING_DIR"
    cd "$WORKING_DIR"
fi

# Main loop
for BRANCH in "MASTER" "STABLE" "OLD"
do
    # Magic with vars
    # Need update flag
    TO_UPDATE=false
    # Branch name in lowercase
    BR_LNAME=$(echo $BRANCH | tr '[:upper:]' '[:lower:]')
    # Transifex resource slug(internal name).
    TMP="${BRANCH}_RESOURCE"
    BR_RESOURCE=${!TMP}
    # Remote last update timestamp for branch.
    BR_REMOTE_TS=$(wget --quiet --output-document=- --user=$TRANSIFEX_USER \
    --password=$TRANSIFEX_<PASSWORD>WD \
    $TRANSIFEX_API_URL/resource/$BR_RESOURCE/stats/$LANG/ | \
    grep '"last_update"' | \
    grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}')
    if [ -z "$BR_REMOTE_TS" ]
    then
        echo "'$BR_LNAME': Unable to get last update timestamp from API."
        exit 1
    else
        BR_REMOTE_TS=$(date --date="$BR_REMOTE_TS" +"%s")
    fi

    # Compare local/remote timestamps.
    BR_WORKDIR=$BR_LNAME
    if [ ! -d "$BR_WORKDIR" ]
    then
        mkdir "$BR_WORKDIR"
    fi
    if [ -f "$BR_WORKDIR/timestamp.txt" ]
    then
        BR_LOCAL_TS=$(cat "$BR_WORKDIR/timestamp.txt")
        if [ $BR_LOCAL_TS -lt $BR_REMOTE_TS ]
        then
          echo "$BR_REMOTE_TS" > $BR_WORKDIR/timestamp.txt
          TO_UPDATE=true
        fi
    else
        echo "$BR_REMOTE_TS" > $BR_WORKDIR/timestamp.txt
        TO_UPDATE=true
    fi
    if $TO_UPDATE
    then
      cd $BR_WORKDIR
      # 1. Get updated translation
      wget --quiet --output-document=${BR_LNAME}.po \
      --user=$TRANSIFEX_USER --password=$TRANSIFEX_PASSWD \
      $TRANSIFEX_API_URL/resource/$BR_RESOURCE/translation/$LANG/?file

{'fraction_non_alphanumeric': 0.14048719025619488, 'fraction_numerical': 0.00881982360352793, 'mean_word_length': 3.120242214532872, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 22, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3061557', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1825, 'n_words': 378}