yesterday=$(date -d "yesterday" +"%Y%m%d")

# Construct the file name with the date
output_file="soccers_$yesterday.tmp.csv"
output_file2="pp2_soccers_$yesterday.csv"

# Execute the MySQL query with the condition on updated_at and redirect the output to the file
export HEADER="updated_at { title { subject { description { medium_location { ms_image_id { category { width_hd { height_hd"
mysql -e "SELECT CONCAT_WS('{',IFNULL(updated_at, ''),IFNULL(title, ''),IFNULL(subject, ''),IFNULL(description, ''),IFNULL(medium_location, ''),IFNULL(ms_image_id, ''),IFNULL(supplemental_category, ''),IFNULL(max_avail_width, ''),IFNULL(max_avail_height, ''))
           FROM images
           WHERE provider_id = 17 AND source LIKE 'PRESSE SPORTS'  and updated_at >= CURDATE() - INTERVAL 1 DAY;" | sed "1s/CONCAT_WS('{',IFNULL(updated_at, ''),IFNULL(title, ''),IFNULL(subject, ''),IFNULL(description, ''),IFNULL(medium_location, ''),IFNULL(ms_image_id, ''),IFNULL(supplemental_category, ''),IFNULL(max_avail_width, ''),IFNULL(max_avail_height, ''))/$HEADER/g" > /var/www/pix/current/export/"$output_file"
unset HEADER
tr -d '\r' < /var/www/pix/current/export/"$output_file" > /var/www/pix/current/export/"$output_file2"
sed -i ':a;N;$!ba;s/\\n/ | /g' /var/www/pix/current/export/"$output_file2"
rm  /var/www/pix/current/export/"$output_file"
echo "export soccer fait" $yesterday

