Browse Source

Initial commit

master
Bogdan Cordier 2 years ago
commit
a13967401f
5 changed files with 274 additions and 0 deletions
  1. 60
    0
      .gitignore
  2. 8
    0
      LICENSE
  3. 23
    0
      README.md
  4. 134
    0
      ical_fusion.py
  5. 49
    0
      icon.xbm

+ 60
- 0
.gitignore View File

@@ -0,0 +1,60 @@
1
+# ---> Python
2
+# Byte-compiled / optimized / DLL files
3
+__pycache__/
4
+*.py[cod]
5
+*$py.class
6
+
7
+# C extensions
8
+*.so
9
+
10
+# Distribution / packaging
11
+.Python
12
+env/
13
+build/
14
+develop-eggs/
15
+dist/
16
+downloads/
17
+eggs/
18
+.eggs/
19
+lib/
20
+lib64/
21
+parts/
22
+sdist/
23
+var/
24
+*.egg-info/
25
+.installed.cfg
26
+*.egg
27
+
28
+# PyInstaller
29
+#  Usually these files are written by a python script from a template
30
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
31
+*.manifest
32
+*.spec
33
+
34
+# Installer logs
35
+pip-log.txt
36
+pip-delete-this-directory.txt
37
+
38
+# Unit test / coverage reports
39
+htmlcov/
40
+.tox/
41
+.coverage
42
+.coverage.*
43
+.cache
44
+nosetests.xml
45
+coverage.xml
46
+*,cover
47
+
48
+# Translations
49
+*.mo
50
+*.pot
51
+
52
+# Django stuff:
53
+*.log
54
+
55
+# Sphinx documentation
56
+docs/_build/
57
+
58
+# PyBuilder
59
+target/
60
+

+ 8
- 0
LICENSE View File

@@ -0,0 +1,8 @@
1
+MIT License
2
+Copyright (c) 2017 Bogdan Cordier
3
+
4
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 23
- 0
README.md View File

@@ -0,0 +1,23 @@
1
+# ICal Fusion
2
+
3
+
4
+This software allows to merge multiple ical files into one.
5
+
6
+### Features
7
+
8
+- Simple filtering by field.
9
+- Duplicates detection based on a field.
10
+
11
+### Todo
12
+
13
+- Multiple filters
14
+- Date filtering
15
+- Command-line interface
16
+
17
+## Requirements
18
+    
19
+- [icalendar](https://pypi.python.org/pypi/icalendar/)
20
+
21
+## Usage
22
+
23
+    python3 ical_fusion.py

+ 134
- 0
ical_fusion.py View File

@@ -0,0 +1,134 @@
1
+#! /usr/bin/env python3
2
+# -*- coding: utf-8 -*-
3
+# vim:fenc=utf-8
4
+#
5
+# Copyright © 2017 Bogdan Cordier
6
+#
7
+# Distributed under terms of the MIT license.
8
+
9
+from icalendar import Calendar
10
+from tkinter import Tk, filedialog, Listbox, Button, Entry, StringVar, \
11
+    LabelFrame, BooleanVar, Frame, ttk, END, Checkbutton, messagebox
12
+
13
+ical_fields = ('SUMMARY', 'UID', 'LOCATION', 'CATEGORIES')
14
+
15
+
16
+class GUI:
17
+    def __init__(self):
18
+        self.root = Tk()
19
+        self.root.title('ICal Fusion')
20
+        self.root.iconbitmap('@icon.xbm')
21
+        self.create_filter_frame()
22
+        self.files = []
23
+        self.create_files_list_frame()
24
+        self.create_duplicates_frame()
25
+        self.btn_frame = Frame(self.root)
26
+        self.create_button_frame()
27
+        self.calendar = Calendar()
28
+        self.root.mainloop()
29
+
30
+    def create_filter_frame(self):
31
+        filter_frame = LabelFrame(self.root, text='Filter')
32
+        self.filter_type = ttk.Combobox(filter_frame, values=ical_fields)
33
+        self.filter_type.current(0)
34
+        self.filter_type.state(('!disabled', 'readonly'))
35
+        self.filter_type.grid(row=0)
36
+
37
+        self.filter_cond = ttk.Combobox(filter_frame,
38
+                                        values=('EQUAL TO',
39
+                                                'CONTAINS'))
40
+        self.filter_cond.current(1)
41
+        self.filter_cond.state(('!disabled', 'readonly'))
42
+        self.filter_cond.grid(row=0, column=1)
43
+
44
+        self.filter_value = StringVar()
45
+
46
+        self.filter_entry = Entry(filter_frame,
47
+                                  textvariable=self.filter_value,
48
+                                  width=25,
49
+                                  bg='white')
50
+        self.filter_entry.grid(row=0, column=2)
51
+        filter_frame.pack(fill='x', side='top')
52
+
53
+    def create_files_list_frame(self):
54
+        files_list_frame = LabelFrame(self.root, text='Files to merge')
55
+        self.FilesList = Listbox(files_list_frame)
56
+        self.FilesList.pack(side='left', fill='both', expand=1)
57
+        files_list_frame.pack(fill='x')
58
+
59
+    def create_duplicates_frame(self):
60
+        frame = Frame(self.root)
61
+        self.duplicates_check = BooleanVar()
62
+        self.duplicates_filter = ttk.Combobox(frame, value=ical_fields)
63
+        self.duplicates_filter.current(0)
64
+        self.duplicates_filter.state(('!disabled', 'readonly'))
65
+        self.duplicates_filter.pack(side='right')
66
+        self.duplicates_cbox = Checkbutton(frame,
67
+                                           variable=self.duplicates_check,
68
+                                           text='Remove duplicates by')
69
+        self.duplicates_cbox.pack(side='right')
70
+        frame.pack(fill='x')
71
+
72
+    def create_button_frame(self):
73
+        Button(self.btn_frame, text='Add...',
74
+               command=self.add_files).grid(row=0, column=0)
75
+        Button(self.btn_frame, text='Merge',
76
+               command=self.join_files).grid(row=0, column=1)
77
+        self.btn_frame.pack(side='bottom')
78
+
79
+    def add_files(self):
80
+        files = filedialog.askopenfilenames(title="Load ICal files",
81
+                                            filetypes=[('ICal files', '.ics'),
82
+                                                       ('all files', '.*')])
83
+        for file in files:
84
+            self.FilesList.insert(END, file)
85
+
86
+    def filter(self, event):
87
+        value = self.filter_value.get()
88
+        field = self.filter_type.get()
89
+        if self.filter_cond.get() == 'CONTAINS':
90
+            if value in event.get(field):
91
+                return True
92
+        if self.filter_cond.get() == 'EQUAL TO':
93
+            if value == event.get(field):
94
+                return True
95
+
96
+        return False
97
+
98
+    def join_files(self):
99
+        if self.FilesList.get(0, END):
100
+            ical = filedialog.asksaveasfilename(title='Save as...')
101
+            self.checked_values = set()
102
+
103
+            for file in self.FilesList.get(0, END):
104
+                ics = open(file, 'r')
105
+                cal = Calendar.from_ical(ics.read())
106
+                ics.close()
107
+                events = (co for co in cal.walk() if co.name == 'VEVENT')
108
+                for event in events:
109
+                    if self.duplicates_check.get():
110
+                        field = self.duplicates_filter.get()
111
+                        value = event.get(field)
112
+                        if value in self.checked_values:
113
+                            break
114
+                        else:
115
+                            self.checked_values.add(value)
116
+
117
+                    if self.filter_value:
118
+                        if self.filter(event):
119
+                            self.calendar.add_component(event)
120
+                    else:
121
+                        if self.duplicates_cbox.getboolean():
122
+                            pass
123
+                        else:
124
+                            self.calendar.add_component(event)
125
+
126
+            with open(ical, 'wb') as f:
127
+                f.write(self.calendar.to_ical())
128
+
129
+            messagebox.showinfo('Success', 'Files were successfully joined !')
130
+        else:
131
+            messagebox.showerror('No files', 'Please add files to merge...')
132
+
133
+if __name__ == '__main__':
134
+    GUI()

+ 49
- 0
icon.xbm View File

@@ -0,0 +1,49 @@
1
+#define icon_width 64
2
+#define icon_height 68
3
+static char icon_bits[] = {
4
+  0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x87, 0xF8, 0xFF, 0xFF, 0xFF, 
5
+  0xFF, 0xFF, 0xFF, 0x03, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 
6
+  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xDF, 0xFF, 0xFF, 0xFF, 
7
+  0xFF, 0xFF, 0xFF, 0x03, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 
8
+  0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0xCF, 0xFF, 0xFF, 0xFF, 
9
+  0xFF, 0xFF, 0xFF, 0x03, 0xC7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 
10
+  0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xEF, 0xFF, 0xFF, 0xFF, 
11
+  0xFF, 0xFF, 0xFF, 0x07, 0xCF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 
12
+  0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xEF, 0x01, 0x18, 0x80, 
13
+  0x01, 0x18, 0xC0, 0x07, 0xCF, 0x01, 0x18, 0x00, 0x01, 0x18, 0x80, 0x07, 
14
+  0xE7, 0x01, 0x18, 0x80, 0x01, 0x10, 0x80, 0x03, 0xEF, 0x01, 0x18, 0x80, 
15
+  0x01, 0x10, 0x80, 0x07, 0xC7, 0x01, 0x08, 0x00, 0x01, 0x18, 0x80, 0x03, 
16
+  0xCF, 0x01, 0x18, 0x80, 0x01, 0x10, 0x80, 0x07, 0xEF, 0x01, 0x08, 0x80, 
17
+  0x01, 0x18, 0x80, 0x03, 0xC7, 0x01, 0x18, 0x80, 0x01, 0x10, 0x80, 0x03, 
18
+  0xEF, 0x01, 0x18, 0x00, 0x01, 0x18, 0x80, 0x07, 0xCF, 0x01, 0x18, 0x80, 
19
+  0x01, 0x10, 0x80, 0x07, 0xEF, 0xAD, 0xBA, 0xED, 0xDB, 0xDD, 0xD5, 0x03, 
20
+  0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0xEF, 0x01, 0x18, 0x80, 
21
+  0x01, 0x10, 0x80, 0x03, 0xCF, 0x01, 0x08, 0x00, 0x01, 0x10, 0x80, 0x07, 
22
+  0xE7, 0x01, 0x18, 0x80, 0x01, 0x10, 0x80, 0x03, 0xCF, 0x01, 0x18, 0x80, 
23
+  0x01, 0x18, 0x80, 0x03, 0xE7, 0x01, 0x18, 0x00, 0x01, 0x10, 0x80, 0x07, 
24
+  0xCF, 0x01, 0x08, 0x80, 0x01, 0x10, 0x80, 0x07, 0xEF, 0x01, 0x18, 0x80, 
25
+  0x01, 0x18, 0x80, 0x03, 0xC7, 0x01, 0x18, 0x80, 0x01, 0x18, 0x80, 0x07, 
26
+  0xEF, 0x01, 0x08, 0x00, 0x01, 0x10, 0x80, 0x03, 0xEF, 0x01, 0x18, 0x80, 
27
+  0x01, 0x10, 0x80, 0x07, 0xCF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 
28
+  0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xEF, 0x01, 0x18, 0x80, 
29
+  0x01, 0x10, 0x80, 0x07, 0xCF, 0x01, 0x08, 0x00, 0x01, 0x10, 0x80, 0x07, 
30
+  0xE7, 0x01, 0x18, 0x80, 0x01, 0x18, 0x80, 0x03, 0xEF, 0x01, 0x18, 0x80, 
31
+  0x01, 0x10, 0x80, 0x07, 0xC7, 0x01, 0x08, 0x00, 0x01, 0x18, 0x80, 0x03, 
32
+  0xCF, 0x01, 0x18, 0x80, 0x01, 0x10, 0x80, 0x07, 0xEF, 0x01, 0x08, 0x80, 
33
+  0x01, 0x18, 0x80, 0x03, 0xC7, 0x01, 0x18, 0x00, 0x01, 0x10, 0x80, 0x03, 
34
+  0xEF, 0x01, 0x18, 0x80, 0x01, 0x18, 0x80, 0x07, 0xCF, 0x01, 0x18, 0x80, 
35
+  0x01, 0x10, 0x80, 0x03, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 
36
+  0xCF, 0xB7, 0x5D, 0xDB, 0xAB, 0xBB, 0xDB, 0x07, 0xCF, 0x01, 0x18, 0x00, 
37
+  0x01, 0x30, 0x80, 0x07, 0xEF, 0x03, 0x10, 0x00, 0x01, 0x10, 0x80, 0x07, 
38
+  0xC7, 0x01, 0x18, 0x00, 0x03, 0x30, 0x80, 0x07, 0xCF, 0x01, 0x10, 0x00, 
39
+  0x03, 0x30, 0x80, 0x07, 0xC7, 0x03, 0x30, 0x00, 0x03, 0x20, 0x00, 0x07, 
40
+  0xCF, 0x03, 0x30, 0x00, 0x02, 0x60, 0x80, 0x0F, 0xCF, 0x03, 0x20, 0x00, 
41
+  0x06, 0x60, 0x00, 0x0F, 0x8F, 0x07, 0x60, 0x00, 0x06, 0x40, 0x00, 0x0F, 
42
+  0x87, 0x07, 0x40, 0x00, 0x0C, 0xC0, 0x00, 0x1F, 0x8F, 0xAF, 0xF9, 0x66, 
43
+  0xAD, 0xD9, 0x65, 0x1F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 
44
+  0x0F, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x0F, 0xFC, 0xFF, 0xFF, 
45
+  0xFF, 0xFF, 0xFF, 0x7F, 0x0F, 0x00, 0x82, 0x20, 0x08, 0x82, 0xF0, 0x08, 
46
+  0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x7F, 0xDB, 0xB6, 0x6D, 
47
+  0xDB, 0xB6, 0xFD, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 
48
+  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 
49
+  0xFF, 0xFF, 0xFF, 0x00, };

Loading…
Cancel
Save