# HG changeset patch # User Raphael Velt # Date 1320419511 -3600 # Node ID 9cabcd2709be09529830700067fc65ddd6ddab60 # Parent 60b8281442b813b1edaa3e41f1fe23356f3972b1 Added an export script for sqlite base diff -r 60b8281442b8 -r 9cabcd2709be tweetcast/nodejs/node-direct.js --- a/tweetcast/nodejs/node-direct.js Wed Nov 02 17:13:23 2011 +0100 +++ b/tweetcast/nodejs/node-direct.js Fri Nov 04 16:11:51 2011 +0100 @@ -66,7 +66,7 @@ } function commitReference(from_id, to_id, ref_type) { - commit_script += 'INSERT INTO tweet_refs ( from_id, to_id, ref_type ) VALUES ( "' + from_id + '", "' + to_id + '", "' + ref_type + '" );\n'; + commit_script += 'INSERT OR IGNORE INTO tweet_refs ( from_id, to_id, ref_type ) VALUES ( "' + from_id + '", "' + to_id + '", "' + ref_type + '" );\n'; } function commitTweet(data) { diff -r 60b8281442b8 -r 9cabcd2709be tweetcast/nodejs/sqlite2txt.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tweetcast/nodejs/sqlite2txt.py Fri Nov 04 16:11:51 2011 +0100 @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import sqlite3, sys, os.path, codecs, re + +if len(sys.argv) > 1: + filename = sys.argv[1] + if os.path.exists(filename): + print "Chargement du fichier %s" % filename + conn = sqlite3.connect(filename) + c = conn.cursor() + c.execute("SELECT json FROM tweets") + f = codecs.open("%s.txt" % filename, mode='w', encoding='utf-8') + for r in c: + txt = '' + t = re.split("&#([0-9]+);",r[0]) + for i in range(len(t)): + txt += ( ( '\\u' + hex(int(t[i])).replace('0x','').rjust(4,'0') ) if i % 2 else t[i] ) + f.write(u'%s\n' % txt) + f.close() + print "Le fichier %s.txt a ete cree" % filename + else: + print "Le fichier n'existe pas" +else: + print "Merci de preciser le nom du fichier" \ No newline at end of file