module-popularity 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. # Copyright (C) 2014-2015 Alex-Daniel Jakimenko <alex.jakimenko@gmail.com>
  3. #
  4. # This program is free software: you can redistribute it and/or modify it under
  5. # the terms of the GNU General Public License as published by the Free Software
  6. # Foundation, either version 3 of the License, or (at your option) any later
  7. # version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License along with
  14. # this program. If not, see <http://www.gnu.org/licenses/>.
  15. # This script parses every link and gets the total number of modules
  16. # Use this script like this: ./module-popularity < list | tee popularity
  17. # Where 'list' is a file with a list of links to action=version (one link on each line)
  18. MODULES_PATH='../modules/'
  19. S='||' # table separator
  20. declare -A modules
  21. declare -A moduleLinks
  22. while read -r link; do
  23. echo "$link"
  24. while read -r module; do
  25. [[ $module == 'wiki.pl' ]] && continue
  26. ((modules["$module"] += 1))
  27. moduleLinks["$module"]+=" $link";
  28. done < <(curl -s "$link" | grep -Po 'tree/modules/\K.*?\.pl|\$Id:\s*\K.*?\.pl')
  29. done
  30. for curModule in "${!modules[@]}"; do
  31. if [[ -f "$MODULES_PATH/$curModule" ]]; then
  32. usefulLinks="Module:$curModule $S"
  33. wikiPage=$(grep -Po "AddModuleDescription\('[^']+',\s*'\K[^']+" "$MODULES_PATH/$curModule")
  34. if [[ $wikiPage ]]; then
  35. usefulLinks+="[[$wikiPage]]"
  36. else
  37. usefulLinks+='No wiki page'
  38. fi
  39. else
  40. usefulLinks="${S} Custom module"
  41. fi
  42. echo "$S ${modules[$curModule]} $S$curModule $S$usefulLinks $S ${moduleLinks[$curModule]} $S"
  43. done | sort -k 3 | sort -nrsk 2