Advertisement
Guest User

i5513

a guest
May 4th, 2009
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.46 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. introducir_en_orage ()
  4. {
  5.     local fecha_inicio=$1
  6.     local fecha_relleno=$2
  7.     local actividad="$3"
  8.     local fecha=$(date +'%Y%m%d%H%M%S')
  9.     local fecha_dts=$(date --rfc-3339=ns  | sed -e 's/ /T/' -e 's/[:-]//g' -e 's/\..*/Z/')
  10.    
  11.     categoria=$(sed -n 's/\[\(.*\)\]/\1/p' ~/.local/share/orage/orage_categories.txt  |
  12.         DISPLAY=:0 LANG=es_ES.UTF8 zenity --list --text "Categorias" --column categoria
  13. )
  14.  
  15.     sed -i  '/^END:VCALENDAR/i \
  16. BEGIN:VJOURNAL \
  17. CLASS:PUBLIC \
  18. UID:zenity-'"$fecha"' \
  19. DTSTART:'"$fecha_dts"' \
  20. SUMMARY:'"$actividad"' \
  21. DESCRIPTION:Nota automática desde zenity \
  22. CATEGORIES:'"$categoria"' \
  23. END:VJOURNAL
  24. ' ~/.local/share/orage/zenity.ics
  25. }
  26.  
  27. fecha=$(date --rfc-3339=ns  | sed -e 's/ /T/' \
  28.                   -e 's/-\|://g' \
  29.                   -e 's/\(..\)\..*/\1Z/')
  30.  
  31. (
  32. ([ -e ~/tmp/zenity.pid ] &&
  33. ps aux | awk '{print $2}' | grep -q $(cat ~/tmp/zenity.pid) &&
  34. kill $(cat ~/tmp/zenity.pid) &&
  35. sed -i '$d' ~/log/zenity.log ) || true) &&
  36. echo -n "$(date +"%Y%m%d %H:%M")" >> ~/log/zenity.log
  37. (
  38. actividad=$(DISPLAY=:0 LANG=es_ES.UTF8 timeout 1770 zenity --entry --text "¿Qué estás haciendo ahora $(date +\%H:\%M)?")
  39. if [[ "$actividad" = *.GOOGLE ]]
  40. then
  41.     actividad=${actividad/.GOOGLE}
  42.     password=$(DISPLAY=:0 LANG=es_ES.UTF8 zenity --entry --text "Introduce contrasena de google." --hide-text)
  43.     ~/scripts/hh/put_event_args.sh -s $password -t "$actividad" -c "Desde zenity"
  44. fi
  45. fecha_relleno=$(date --rfc-3339=ns  | sed -e 's/ /T/' \
  46.                                       -e 's/-\|://g' \
  47.                                       -e 's/\(..\)\..*/\1Z/')
  48. [ -z "$actividad" ] && exit 1
  49. introducir_en_orage $fecha $fecha_relleno "$actividad"
  50. echo " - "$(date +\%H:\%M)": ${actividad:-Cancelado}" ) >> ~/log/zenity.log &
  51.  
  52. ****************************************************************************************************************************
  53. *                               FOR GOOGLE                                                                               *
  54. ****************************************************************************************************************************
  55. $ cat ~/scripts/hh/put_event_args.sh
  56. email=yourmail@gmail.com
  57.  
  58.  
  59. # Esto habría que hacerlo con getopt ...
  60. if [ $# == 0 -o $# -lt 6 ]
  61. then
  62.     echo "$0 -s \"SECRET\" -t "Titulo" -c \"CONTENIDO\" [ -fi \"2007-01-08T09:31:22.106190000+01:00\" -ff \"2007-01-08T09:31:22.106190000+01:00\" ] "
  63.     exit 1
  64. fi
  65.  
  66. # Password
  67. if [ "$1" == "-s" ]
  68. then
  69.     passwd="$2"
  70. else
  71.     echo "Introduce la contraseña: "
  72.     stty -echo ; read passwd ; stty echo
  73. fi
  74.  
  75. # Titulo
  76. if [ "$3" == "-t" ]
  77. then
  78.     titulo="$4"
  79. else
  80.     titulo="Evento de USER"
  81. fi
  82.  
  83. # Contenido
  84. if [ "$5" == "-c" ]
  85. then
  86.     contenido="$6"
  87. else
  88.     contenido="Falta contenido, elimina esta entrada y revisa la orden desde la que se creó"
  89. fi
  90.  
  91. # Fecha
  92. if [ "$7" == "-fi" ]
  93. then
  94.     fecha_inicio="$8"
  95. else
  96.     fecha_inicio=$(date --rfc-3339=ns -d '1 hour ago' | sed 's/ /T/')
  97. fi
  98.  
  99. if [ "$9" == "-ff" ]
  100. then
  101.     fecha_fin="$10"
  102. else
  103.     fecha_fin=$(date --rfc-3339=ns  | sed 's/ /T/')
  104. fi
  105.  
  106. cat - << EOF > evento.tmp
  107. <entry xmlns='http://www.w3.org/2005/Atom'
  108.     xmlns:gd='http://schemas.google.com/g/2005'>
  109.   <category scheme='http://schemas.google.com/g/2005#kind'
  110.     term='http://schemas.google.com/g/2005#event'></category>
  111.   <title type='text'>$titulo</title>
  112.   <content type='text'>$contenido</content>
  113.   <author>
  114.     <name>YOUR NAME </name>
  115.     <email>yourname@gmail.com</email>
  116.   </author>
  117.   <gd:transparency
  118.     value='http://schemas.google.com/g/2005#event.opaque'>
  119.   </gd:transparency>
  120.   <gd:eventStatus
  121.     value='http://schemas.google.com/g/2005#event.confirmed'>
  122.   </gd:eventStatus>
  123.   <gd:where valueString='Example S.A.'></gd:where>
  124.   <gd:when startTime='$fecha_inicio'
  125.     endTime='$fecha_fin'></gd:when>
  126. </entry>
  127. EOF
  128.  
  129. auth=$(wget --post-data='Email='$email'&Passwd='$passwd'&yourcalendar-1&service=cl' https://www.google.com/accounts/ClientLogin -O - | tail -1 | sed 's/Auth=//')
  130. sessionid=$(wget --header "Authorization: GoogleLogin auth=$auth" --header "Content-Type: application/atom+xml" --post-file="evento.tmp" http://www.google.com/calendar/feeds/default/private/full 2>&1 | tail -2 | grep -o  "gsessionid=[^']*" | sed 's/gsessionid=//')
  131. wget --header "Authorization: GoogleLogin auth=$auth" --header "Content-Type: application/atom+xml" --post-file="evento.tmp" http://www.google.com/calendar/feeds/default/private/full?gsessionid=$sessionid  &> /dev/null
  132. # Limpieza a lo cutre
  133. rm "full?gsessionid=$sessionid"*
  134. rm evento.tmp
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement