commit f403a3cd1e275fb3545c98d6b00a13f1f070b663 Author: Georg Hopp Date: Sun Mar 20 23:19:50 2016 +0100 initial checkin diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cf3f063 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +silpion.creds diff --git a/README.md b/README.md new file mode 100644 index 0000000..640e62e --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +# getcal + +A small script the retrieve calender entries from zimbra and format them for +the GNU calendar program. + +## Synopsis + + * ruby getcal.rb + * python getcal.py + +## Description + +There is a python and a ruby variant available. Both will write the generated +calendar entries to stdout. + +## Requirements + +Python or ruby. + +## Dependencies + +none + +## Contributing + +No contribution for now... + +## License + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +## Author + +Georg Hopp + diff --git a/getcal.py b/getcal.py new file mode 100644 index 0000000..17cd813 --- /dev/null +++ b/getcal.py @@ -0,0 +1,20 @@ +import requests + +response = requests.get('url', auth=('user', 'password')) + +current = {} +for line in response.text.splitlines(): + if line[0:12] == 'BEGIN:VEVENT': + current = {'location': '', 'summary': '', 'start': ':00000000T080000'} + if line[0:7] == 'SUMMARY': current['summary'] = line[8:].strip() + if line[0:7] == 'DTSTART': current['start'] = line[8:].strip() + if line[0:8] == 'LOCATION': current['location'] = line[9:].strip() + if line[0:10] == 'END:VEVENT': + zone, timestr = current['start'].split(':') + sdate, stime = timestr.split('T') + hour, minute, sec = list(map(''.join, zip(*[iter(stime)]*2))) + line = "%s %s:%s (%s) %s" % ( + sdate, hour, minute, current['location'], current['summary']) + print(line.encode('utf8')) + +# vim: set ft=python et sta ts=4 sts=4 sw=4 tw=80: diff --git a/getcal.rb b/getcal.rb new file mode 100644 index 0000000..46ff2e5 --- /dev/null +++ b/getcal.rb @@ -0,0 +1,42 @@ +require 'net/http' + +uri = URI.parse("url") + +http = Net::HTTP.new(uri.host, uri.port) +http.use_ssl = true +http.verify_mode = OpenSSL::SSL::VERIFY_NONE + +request = Net::HTTP::Get.new(uri.request_uri) +request.basic_auth("user", "password") + +response = http.request(request) + +all = [] +current = {} +response.body.each_line do |line| + case + when line =~ /^BEGIN:VEVENT/ + current = {} + when line =~ /^SUMMARY/ + current[:summary] = line[line.index(':')+1..-1].strip #.gsub(/"/, '\\"') + when line =~ /^DTSTART/ + current[:start] = line[line.index(':')+1..-1].strip + when line =~ /^LOCATION/ + current[:location] = line[line.index(':')+1..-1].strip #.gsub(/"/, '\\"') + when line =~ /^END:VEVENT/ + all << current + else + # just ignore everything else right now. + end +end + +all.each do |c| + sdate, stime = c[:start].split('T') + hour = '08' + min = '00' + hour,min,sec = stime.scan(/../) unless stime.nil? + + puts "#{sdate} #{hour}:#{min} (#{c[:location]}) #{c[:summary]}" +end + +# vim: set ft=ruby et ts=2 sw=2: