encoding fix
[lesmianator.git] / init-txt.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Copyright © 2011 Fundacja Nowoczesna Polska
4 #
5 # This file is part of Leśmianator.
6 #
7 # Leśmianator is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Leśmianator is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Affero General Public License for more details.
16 #
17 # You should have received a copy of the GNU Affero General Public License
18 # along with Leśmianator.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 """
22 Inicjalizuje bazę danych Leśmianatora z pobranych plików TXT.
23
24 Skrypt pobiera paczkę plików TXT z utworami lirycznymi
25 i przekazuje ich treść Leśmianatorowi do analizy.
26
27 """
28
29 from StringIO import StringIO
30 from urllib2 import urlopen
31 from zipfile import ZipFile
32
33 from lesmianator import Lesmianator
34
35
36 TXT_FILES = "http://www.wolnelektury.pl/media/packs/txt-liryka.zip"
37
38
39 if __name__ == '__main__':
40     txt_zip = ZipFile(StringIO(urlopen(TXT_FILES).read()))
41
42     poet = Lesmianator()
43     for filename in txt_zip.namelist():
44         print filename
45         poet.add_txt_file(txt_zip.open(filename))
46
47     poet.save()
48