Commit f403a3cd1e275fb3545c98d6b00a13f1f070b663

Authored by Georg Hopp
0 parents

initial checkin

  1 +silpion.creds
... ...
  1 +# getcal
  2 +
  3 +A small script the retrieve calender entries from zimbra and format them for
  4 +the GNU calendar program.
  5 +
  6 +## Synopsis
  7 +
  8 + * ruby getcal.rb
  9 + * python getcal.py
  10 +
  11 +## Description
  12 +
  13 +There is a python and a ruby variant available. Both will write the generated
  14 +calendar entries to stdout.
  15 +
  16 +## Requirements
  17 +
  18 +Python or ruby.
  19 +
  20 +## Dependencies
  21 +
  22 +none
  23 +
  24 +## Contributing
  25 +
  26 +No contribution for now...
  27 +
  28 +## License
  29 +
  30 + This program is free software: you can redistribute it and/or modify
  31 + it under the terms of the GNU General Public License as published by
  32 + the Free Software Foundation, either version 3 of the License, or
  33 + (at your option) any later version.
  34 +
  35 + This program is distributed in the hope that it will be useful,
  36 + but WITHOUT ANY WARRANTY; without even the implied warranty of
  37 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  38 + GNU General Public License for more details.
  39 +
  40 + You should have received a copy of the GNU General Public License
  41 + along with this program. If not, see <http://www.gnu.org/licenses/>.
  42 +
  43 +## Author
  44 +
  45 +Georg Hopp <georg@steffers.org>
  46 +
... ...
  1 +import requests
  2 +
  3 +response = requests.get('url', auth=('user', 'password'))
  4 +
  5 +current = {}
  6 +for line in response.text.splitlines():
  7 + if line[0:12] == 'BEGIN:VEVENT':
  8 + current = {'location': '', 'summary': '', 'start': ':00000000T080000'}
  9 + if line[0:7] == 'SUMMARY': current['summary'] = line[8:].strip()
  10 + if line[0:7] == 'DTSTART': current['start'] = line[8:].strip()
  11 + if line[0:8] == 'LOCATION': current['location'] = line[9:].strip()
  12 + if line[0:10] == 'END:VEVENT':
  13 + zone, timestr = current['start'].split(':')
  14 + sdate, stime = timestr.split('T')
  15 + hour, minute, sec = list(map(''.join, zip(*[iter(stime)]*2)))
  16 + line = "%s %s:%s (%s) %s" % (
  17 + sdate, hour, minute, current['location'], current['summary'])
  18 + print(line.encode('utf8'))
  19 +
  20 +# vim: set ft=python et sta ts=4 sts=4 sw=4 tw=80:
... ...
  1 +require 'net/http'
  2 +
  3 +uri = URI.parse("url")
  4 +
  5 +http = Net::HTTP.new(uri.host, uri.port)
  6 +http.use_ssl = true
  7 +http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  8 +
  9 +request = Net::HTTP::Get.new(uri.request_uri)
  10 +request.basic_auth("user", "password")
  11 +
  12 +response = http.request(request)
  13 +
  14 +all = []
  15 +current = {}
  16 +response.body.each_line do |line|
  17 + case
  18 + when line =~ /^BEGIN:VEVENT/
  19 + current = {}
  20 + when line =~ /^SUMMARY/
  21 + current[:summary] = line[line.index(':')+1..-1].strip #.gsub(/"/, '\\"')
  22 + when line =~ /^DTSTART/
  23 + current[:start] = line[line.index(':')+1..-1].strip
  24 + when line =~ /^LOCATION/
  25 + current[:location] = line[line.index(':')+1..-1].strip #.gsub(/"/, '\\"')
  26 + when line =~ /^END:VEVENT/
  27 + all << current
  28 + else
  29 + # just ignore everything else right now.
  30 + end
  31 +end
  32 +
  33 +all.each do |c|
  34 + sdate, stime = c[:start].split('T')
  35 + hour = '08'
  36 + min = '00'
  37 + hour,min,sec = stime.scan(/../) unless stime.nil?
  38 +
  39 + puts "#{sdate} #{hour}:#{min} (#{c[:location]}) #{c[:summary]}"
  40 +end
  41 +
  42 +# vim: set ft=ruby et ts=2 sw=2:
... ...
Please register or login to post a comment