fetch_articles.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. # CURL käsk transport_context sisestamisega - LIHTSUSTATUD VERSIOON
  3. # Kasutab jq-d JSON-i formateerimiseks
  4. # Salvestatakse markdown faili ja eksporditud PDF-ks VS Code Markdown PDF laiendusega
  5. set -e
  6. GRAPHQL_URL="http://100.80.222.54:9020/v1/graphql"
  7. OUTPUT_FILE="$HOME/Downloads/articles_with_transport_context.md"
  8. echo "📡 Toon artikleid GraphQL API-st..."
  9. curl -s "$GRAPHQL_URL" \
  10. -X POST \
  11. -H "Content-Type: application/json" \
  12. -d '{
  13. "query": "{ Get { ScientificArticle { title source_file summary_et transport_context } } }"
  14. }' \
  15. | jq -r '
  16. "<style>\n@media print {\n h2 {\n page-break-before: always;\n }\n h2:first-of-type {\n page-break-before: avoid;\n }\n}\n</style>\n\n# Teadusartiklite analüüs\n\nEksporditud: " + (now | strftime("%d.%m.%Y %H:%M")) + "\n\n---\n\n",
  17. (.data.Get.ScientificArticle[] |
  18. "\n## " + .title + "\n\n" +
  19. "**Allikfail:** `" + (.source_file | split("/") | .[-1]) + "`\n\n" +
  20. "### Kokkuvõte (eesti keeles)\n\n" +
  21. .summary_et + "\n\n" +
  22. "### Transpordiplaneerimise kontekst\n\n" +
  23. (
  24. if .transport_context then
  25. (
  26. .transport_context |
  27. if type == "string" then
  28. (
  29. gsub("```json\\s*"; "") |
  30. gsub("\\s*```"; "") |
  31. .
  32. )
  33. else
  34. @json
  35. end
  36. )
  37. else
  38. "Andmeid pole saadaval"
  39. end
  40. ) + "\n\n---\n"
  41. )' \
  42. > "$OUTPUT_FILE"
  43. if [ -f "$OUTPUT_FILE" ]; then
  44. echo "✅ Markdown fail salvestatud: $OUTPUT_FILE"
  45. echo ""
  46. echo "🚀 Järgmised sammud:"
  47. echo " 1. Avage fail VS Code'is: code $OUTPUT_FILE"
  48. echo " 2. Paremklõps failil → 'Markdown PDF: Export (pdf)'"
  49. echo " 3. PDF fail luuakse samasse kausta"
  50. echo ""
  51. echo "💡 Juhised: Vaata README_CURL_TRANSPORT_CONTEXT.md"
  52. else
  53. echo "❌ Viga: markdown faili ei õnnestunud luua"
  54. exit 1
  55. fi