yemekhanebot.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. TOKEN="TOKEN"
  3. CHANNEL_NAME="CHANNEL_NAME"
  4. API_URL="https://api.telegram.org/bot$TOKEN/"
  5. bash yemekhanejson.sh > data.json
  6. current_month="$(date +%m)"
  7. while true
  8. do
  9. if [ "$(date +%m)" != $current_month ]
  10. then
  11. bash yemekhanejson.sh > data.json
  12. fi
  13. current_date=$(date +%Y-%m-%d)
  14. ogle=$(cat data.json | perl -ne '/'"$current_date"'","ogle":\{"corba":"(.*?)","ana":"(.*?)","vegan":"(.*?)","yardimci":"(.*?)","aperatif":"(.*?)"/ && print "$1\n$2\n$3\n$4\n$5";')
  15. aksam=$(cat data.json | perl -ne '/'"$current_date"'","ogle":\{"corba":".*?","ana":".*?","vegan":".*?","yardimci":".*?","aperatif":".*?"\},"aksam":\{"corba":"(.*?)","ana":"(.*?)","vegan":"(.*?)","yardimci":"(.*?)","aperatif":"(.*?)"/ && print "$1\n$2\n$3\n$4\n$5";')
  16. ogle_text="$(date +%d.+%m.+%Y)%0AÖğle Yemeği:%0A$ogle"
  17. curl -s -X POST $API_URL"sendMessage" -d chat_id=$CHANNEL_NAME -d text="$ogle_text" > /dev/null
  18. next_time=$(date -d 'today 16:00' +%s)
  19. current_time=$(date +%s)
  20. sleep $(($next_time - $current_time))
  21. aksam_text="$(date +%d.+%m.+%Y)%0AAkşam Yemeği:%0A$aksam"
  22. curl -s -X POST $API_URL"sendMessage" -d chat_id=$CHANNEL_NAME -d text="$aksam_text" > /dev/null
  23. next_time=$(date -d 'tomorrow 09:00' +%s)
  24. current_time=$(date +%s)
  25. sleep $(($next_time - $current_time))
  26. done