Add script to capture html to orgmode
This commit is contained in:
		@@ -38,6 +38,8 @@ Then take a screenshot and process it.
 | 
			
		||||
#+begin_src bash
 | 
			
		||||
  temp_file="/tmp/screen.png"
 | 
			
		||||
 | 
			
		||||
  rm -f $temp_file
 | 
			
		||||
 | 
			
		||||
  scrot $temp_file
 | 
			
		||||
  convert $temp_file -scale 10% -scale 1000% $temp_file
 | 
			
		||||
#+end_src
 | 
			
		||||
@@ -92,7 +94,8 @@ The requirement is to have =pdftk= installed.
 | 
			
		||||
#+begin_src bash
 | 
			
		||||
  if [[ -f $1 && $1 == *.pdf ]]; then
 | 
			
		||||
      # Argument if a file
 | 
			
		||||
      pdftk "$1" cat 2-end output /tmp/pdftk_out.pdf && mv /tmp/pdftk_out.pdf "$1"
 | 
			
		||||
      # pdftk "$1" cat 2-end output /tmp/pdftk_out.pdf && mv /tmp/pdftk_out.pdf "$1"
 | 
			
		||||
      stapler del "$1" 1 /tmp/pdftk_out.pdf && mv /tmp/pdftk_out.pdf "$1"
 | 
			
		||||
  fi
 | 
			
		||||
#+end_src
 | 
			
		||||
 | 
			
		||||
@@ -137,7 +140,7 @@ Things to do:
 | 
			
		||||
- [ ] Display the not found figures
 | 
			
		||||
 | 
			
		||||
#+begin_src bash :results output
 | 
			
		||||
  latexpath="$HOME/MEGA/These/LaTeX/ressources/Figures";
 | 
			
		||||
  latexpath="$HOME/Cloud/thesis/latex/ressources/Figures";
 | 
			
		||||
 | 
			
		||||
  figures=`awk 'match($0, /(fig.*\.(png|svg|pdf))/, a) {print a[1];}' $1 \
 | 
			
		||||
        | awk '{ print gensub(/\s*\]\]\s*\|\s*\[\[\s*\.?\/?/, "\n", "g") }'`;
 | 
			
		||||
@@ -172,31 +175,7 @@ Things to do:
 | 
			
		||||
#+end_src
 | 
			
		||||
 | 
			
		||||
#+RESULTS:
 | 
			
		||||
#+begin_example
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/classical_feedback_alt.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/classical_feedback_2dof_alt.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/classical_feedback_sep.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/classical_feedback_bis.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/general_control_names.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/general_plant_weights.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/general_control_Mdelta.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/classical_feedback_stability.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/classical_feedback_meas.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/input_output_uncertainty.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/input_uncertainty_set.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/input_uncertainty_set_feedback.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/inverse_uncertainty_set.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/general_control_delta.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/general_control_Ndelta.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/general_control_Mdelta.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/additive_uncertainty.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/input_uncertainty.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/output_uncertainty.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/inv_additive_uncertainty.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/inv_input_uncertainty.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/inv_output_uncertainty.pdf
 | 
			
		||||
/home/tdehaeze/MEGA/These/LaTeX/ressources/Figures/input_uncertainty_set_feedback_weight.pdf
 | 
			
		||||
#+end_example
 | 
			
		||||
 | 
			
		||||
* NAS
 | 
			
		||||
** Mount
 | 
			
		||||
  :PROPERTIES:
 | 
			
		||||
@@ -315,3 +294,209 @@ else
 | 
			
		||||
    setsid nohup youtube-dl --add-metadata -ic $1 &> /dev/null &
 | 
			
		||||
fi
 | 
			
		||||
#+end_src
 | 
			
		||||
* Org-Protocol-Capture-HTML
 | 
			
		||||
:PROPERTIES:
 | 
			
		||||
:header-args:  :tangle ~/scripts/org-protocol-capture-html.sh
 | 
			
		||||
:header-args+: :comments both :mkdirp yes
 | 
			
		||||
:header-args+: :shebang "#!/usr/bin/env bash"
 | 
			
		||||
:END:
 | 
			
		||||
 | 
			
		||||
Defaults
 | 
			
		||||
#+begin_src bash
 | 
			
		||||
  heading="link"
 | 
			
		||||
  template="pu"
 | 
			
		||||
  url="https://google.com/"
 | 
			
		||||
#+end_src
 | 
			
		||||
 | 
			
		||||
Functions
 | 
			
		||||
#+begin_src bash
 | 
			
		||||
  function debug {
 | 
			
		||||
      if [[ -n $debug ]]
 | 
			
		||||
      then
 | 
			
		||||
          function debug {
 | 
			
		||||
              echo "DEBUG: $@" >&2
 | 
			
		||||
          }
 | 
			
		||||
          debug "$@"
 | 
			
		||||
      else
 | 
			
		||||
          function debug {
 | 
			
		||||
              true
 | 
			
		||||
          }
 | 
			
		||||
      fi
 | 
			
		||||
  }
 | 
			
		||||
  function die {
 | 
			
		||||
      echo "$@" >&2
 | 
			
		||||
      exit 1
 | 
			
		||||
  }
 | 
			
		||||
  function urlencode {
 | 
			
		||||
      python -c "
 | 
			
		||||
  from __future__ import print_function
 | 
			
		||||
  try:
 | 
			
		||||
      from urllib import quote  # Python 2
 | 
			
		||||
  except ImportError:
 | 
			
		||||
      from urllib.parse import quote  # Python 3
 | 
			
		||||
  import sys
 | 
			
		||||
  print(quote(sys.stdin.read()[:-1], safe=''))"
 | 
			
		||||
  }
 | 
			
		||||
#+end_src
 | 
			
		||||
 | 
			
		||||
Documentation
 | 
			
		||||
#+begin_src bash
 | 
			
		||||
  function usage {
 | 
			
		||||
      cat <<EOF
 | 
			
		||||
  $0 [OPTIONS] [HTML]
 | 
			
		||||
  html | $0 [OPTIONS]
 | 
			
		||||
  Send HTML to Emacs through org-protocol, passing it through Pandoc to
 | 
			
		||||
  convert HTML to Org-mode.  HTML may be passed as an argument or
 | 
			
		||||
  through STDIN.  If only URL is given, it will be downloaded and its
 | 
			
		||||
  contents used.
 | 
			
		||||
  Options:
 | 
			
		||||
      -h, --heading HEADING     Heading
 | 
			
		||||
      -t, --template TEMPLATE   org-capture template key (default: pu)
 | 
			
		||||
      -u, --url URL             URL
 | 
			
		||||
      --debug  Print debug info
 | 
			
		||||
      --help   I need somebody!
 | 
			
		||||
  EOF
 | 
			
		||||
  }
 | 
			
		||||
#+end_src
 | 
			
		||||
 | 
			
		||||
Arguments
 | 
			
		||||
#+begin_src bash
 | 
			
		||||
  args=$(getopt -n "$0" -o dh:rt:u: -l debug,help,heading:,template:,url: -- "$@") \
 | 
			
		||||
      || die "Unable to parse args.  Is getopt installed?"
 | 
			
		||||
  eval set -- "$args"
 | 
			
		||||
 | 
			
		||||
  while true
 | 
			
		||||
  do
 | 
			
		||||
      case "$1" in
 | 
			
		||||
          -d|--debug)
 | 
			
		||||
              debug=true
 | 
			
		||||
              debug "Debugging on"
 | 
			
		||||
              ;;
 | 
			
		||||
          --help)
 | 
			
		||||
              usage
 | 
			
		||||
              exit
 | 
			
		||||
              ;;
 | 
			
		||||
          -h|--heading)
 | 
			
		||||
              shift
 | 
			
		||||
              heading="$1"
 | 
			
		||||
              ;;
 | 
			
		||||
          -t|--template)
 | 
			
		||||
              shift
 | 
			
		||||
              template="$1"
 | 
			
		||||
              ;;
 | 
			
		||||
          -u|--url)
 | 
			
		||||
              shift
 | 
			
		||||
              url="$1"
 | 
			
		||||
              ;;
 | 
			
		||||
          --)
 | 
			
		||||
              # Remaining args
 | 
			
		||||
              shift
 | 
			
		||||
              rest=("$@")
 | 
			
		||||
              break
 | 
			
		||||
              ;;
 | 
			
		||||
      esac
 | 
			
		||||
 | 
			
		||||
      shift
 | 
			
		||||
  done
 | 
			
		||||
 | 
			
		||||
  debug "ARGS: $args"
 | 
			
		||||
  debug "Remaining args: ${rest[@]}"
 | 
			
		||||
#+end_src
 | 
			
		||||
 | 
			
		||||
Get HTML
 | 
			
		||||
#+begin_src bash
 | 
			
		||||
  if [[ -n $@ ]]
 | 
			
		||||
  then
 | 
			
		||||
      debug "Text from args"
 | 
			
		||||
 | 
			
		||||
      body="$@"
 | 
			
		||||
  fi
 | 
			
		||||
#+end_src
 | 
			
		||||
 | 
			
		||||
URL-encode
 | 
			
		||||
#+begin_src bash
 | 
			
		||||
  heading=$(urlencode <<<"$heading") || die "Unable to urlencode heading."
 | 
			
		||||
  url=$(urlencode <<<"$url") || die "Unable to urlencode URL."
 | 
			
		||||
  body=$(urlencode <<<"$body") || die "Unable to urlencode text."
 | 
			
		||||
#+end_src
 | 
			
		||||
 | 
			
		||||
Send to Emacs
 | 
			
		||||
#+begin_src bash
 | 
			
		||||
  emacsclient "org-protocol://capture?template=$template&url=$url&title=$heading&body=$body"
 | 
			
		||||
#+end_src
 | 
			
		||||
* Pdf Shrink
 | 
			
		||||
:PROPERTIES:
 | 
			
		||||
:header-args:  :tangle ~/scripts/pdf-shrink.sh
 | 
			
		||||
:header-args+: :comments both :mkdirp yes
 | 
			
		||||
:header-args+: :shebang "#!/usr/bin/env bash"
 | 
			
		||||
:END:
 | 
			
		||||
 | 
			
		||||
#+begin_src bash
 | 
			
		||||
  shrink ()
 | 
			
		||||
  {
 | 
			
		||||
  gs \
 | 
			
		||||
    -q -dNOPAUSE -dBATCH -dSAFER \
 | 
			
		||||
    -sDEVICE=pdfwrite \
 | 
			
		||||
    -dCompatibilityLevel=1.3 \
 | 
			
		||||
    -dPDFSETTINGS=/screen \
 | 
			
		||||
    -dEmbedAllFonts=true \
 | 
			
		||||
    -dSubsetFonts=true \
 | 
			
		||||
    -dAutoRotatePages=/None \
 | 
			
		||||
    -dColorImageDownsampleType=/Bicubic \
 | 
			
		||||
    -dColorImageResolution=$3 \
 | 
			
		||||
    -dGrayImageDownsampleType=/Bicubic \
 | 
			
		||||
    -dGrayImageResolution=$3 \
 | 
			
		||||
    -dMonoImageDownsampleType=/Subsample \
 | 
			
		||||
    -dMonoImageResolution=$3 \
 | 
			
		||||
    -sOutputFile="$2" \
 | 
			
		||||
    "$1"
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  check_smaller ()
 | 
			
		||||
  {
 | 
			
		||||
  # If $1 and $2 are regular files, we can compare file sizes to
 | 
			
		||||
  # see if we succeeded in shrinking. If not, we copy $1 over $2:
 | 
			
		||||
  if [ ! -f "$1" -o ! -f "$2" ]; then
 | 
			
		||||
  return 0;
 | 
			
		||||
  fi
 | 
			
		||||
  ISIZE="$(echo $(wc -c "$1") | cut -f1 -d\ )"
 | 
			
		||||
  OSIZE="$(echo $(wc -c "$2") | cut -f1 -d\ )"
 | 
			
		||||
  if [ "$ISIZE" -lt "$OSIZE" ]; then
 | 
			
		||||
  echo "Input smaller than output, doing straight copy" >&2
 | 
			
		||||
  cp "$1" "$2"
 | 
			
		||||
  fi
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  usage ()
 | 
			
		||||
  {
 | 
			
		||||
  echo "Reduces PDF filesize by lossy recompressing with Ghostscript."
 | 
			
		||||
  echo "Not guaranteed to succeed, but usually works."
 | 
			
		||||
  echo "  Usage: $1 infile [outfile] [resolution_in_dpi]"
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  IFILE="$1"
 | 
			
		||||
 | 
			
		||||
  # Need an input file:
 | 
			
		||||
  if [ -z "$IFILE" ]; then
 | 
			
		||||
  usage "$0"
 | 
			
		||||
  exit 1
 | 
			
		||||
  fi
 | 
			
		||||
 | 
			
		||||
  # Output filename defaults to "-" (stdout) unless given:
 | 
			
		||||
  if [ ! -z "$2" ]; then
 | 
			
		||||
  OFILE="$2"
 | 
			
		||||
  else
 | 
			
		||||
  OFILE="-"
 | 
			
		||||
  fi
 | 
			
		||||
 | 
			
		||||
  # Output resolution defaults to 72 unless given:
 | 
			
		||||
  if [ ! -z "$3" ]; then
 | 
			
		||||
  res="$3"
 | 
			
		||||
  else
 | 
			
		||||
  res="90"
 | 
			
		||||
  fi
 | 
			
		||||
 | 
			
		||||
  shrink "$IFILE" "$OFILE" "$res" || exit $?
 | 
			
		||||
 | 
			
		||||
  check_smaller "$IFILE" "$OFILE"
 | 
			
		||||
#+end_src
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user