equal
deleted
inserted
replaced
1 #!/usr/bin/env python |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 import sqlite3, sys, os.path, codecs, re |
|
5 |
|
6 if len(sys.argv) > 1: |
|
7 filename = sys.argv[1] |
|
8 if os.path.exists(filename): |
|
9 print "Chargement du fichier %s" % filename |
|
10 conn = sqlite3.connect(filename) |
|
11 c = conn.cursor() |
|
12 c.execute("SELECT json FROM tweets") |
|
13 f = codecs.open("%s.txt" % filename, mode='w', encoding='utf-8') |
|
14 for r in c: |
|
15 txt = '' |
|
16 t = re.split("&#([0-9]+);",r[0]) |
|
17 for i in range(len(t)): |
|
18 txt += ( ( '\\u' + hex(int(t[i])).replace('0x','').rjust(4,'0') ) if i % 2 else t[i] ) |
|
19 f.write(u'%s\n' % txt) |
|
20 f.close() |
|
21 print "Le fichier %s.txt a ete cree" % filename |
|
22 else: |
|
23 print "Le fichier n'existe pas" |
|
24 else: |
|
25 print "Merci de preciser le nom du fichier" |
|