25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.6 KiB

  1. #! /bin/sh
  2. # Importuje artykuły z Micropedii i SclaviniaWiki z listy podanej na
  3. # standardowym wejściu.
  4. # Copyright © 2017 Paulina Laura Emilia <vilene@posteo.net>
  5. #
  6. # This program is free software. It comes without any warranty, to
  7. # the extent permitted by applicable law. You can redistribute it
  8. # and/or modify it under the terms of the Do What The Fuck You Want
  9. # To Public License, Version 2, as published by Sam Hocevar. See the
  10. # COPYING file for more details.
  11. set -C
  12. # Znajdź katalog w którym znajduje się ten skrypt.
  13. scriptdir=$(cd -P "$(dirname "$0")" && pwd)
  14. # Sprawdź czy skrypt mediawiki2ency.sh jest w ścieżce wyszukiwania lub
  15. # w katalogu w którym znajduje się ten skrypt.
  16. if ! mw2e=$(PATH=$PATH:$scriptdir command -v "mediawiki2ency.sh"); then
  17. printf "%s: Nie znaleziono skryptu \`mediawiki2ency.sh' w katalogu \`%s' bądź w ścieżce wyszukiwania.\n" \
  18. "$0" "$scriptdir" >&2
  19. exit 1
  20. fi
  21. # Wybierz prefiks URL-a stron w zależności od źródła.
  22. case $1 in
  23. --sclavinia)
  24. prefix=http://vonthorn.sarmacja.org/wiki/index.php/
  25. ;;
  26. *)
  27. prefix=https://micropedia.fandom.com/wiki/
  28. esac
  29. # Czytaj listę ze standardowego wejścia.
  30. while IFS= read -r name; do
  31. urlname=$(printf '%s\n' "$name" | sed -e 's/ /_/g')
  32. filename=$urlname.markdown
  33. if [ -e "$filename" ]; then
  34. printf '%s: %s: %s\n' "$0" "$filename" 'Plik już istnieje.' >&2
  35. continue
  36. fi
  37. if ! curl -fso "$filename.tmp" "$prefix$urlname?action=raw"; then
  38. printf '%s: %s: %s\n' "$0" "$name" \
  39. 'Nie udało się pobrać artykułu.' >&2
  40. continue
  41. fi
  42. "$mw2e" "$@" "$filename.tmp" "$name" > "$filename"
  43. rm -f "$filename.tmp"
  44. done