- replace json with anyjson
authorYves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
Thu, 20 Jan 2011 19:28:51 +0100
changeset 18 bd595ad770fc
parent 17 1e7b883645a3
child 19 1c2f13fd785c
- replace json with anyjson - invalidate user id from search twitter query
script/lib/iri_tweet/models.py
script/lib/iri_tweet/utils.py
script/rest/search_enmi.py
--- a/script/lib/iri_tweet/models.py	Thu Jan 20 12:53:01 2011 +0100
+++ b/script/lib/iri_tweet/models.py	Thu Jan 20 19:28:51 2011 +0100
@@ -4,7 +4,7 @@
 from sqlalchemy.orm import relationship, backref
 import datetime
 import email.utils
-import simplejson
+import anyjson
 
 
 Base = declarative_base()
@@ -23,7 +23,7 @@
     if obj is None:
         return None
     else:
-        return simplejson.dumps(obj)
+        return anyjson.serialize(obj)
 
 class Entity(Base):
     __tablename__ = "tweet_entity"
--- a/script/lib/iri_tweet/utils.py	Thu Jan 20 12:53:01 2011 +0100
+++ b/script/lib/iri_tweet/utils.py	Thu Jan 20 19:28:51 2011 +0100
@@ -1,7 +1,7 @@
 from models import *
 import datetime
 import email.utils
-import json
+import anyjson
 import logging
 import os.path
 import sys
@@ -75,12 +75,12 @@
             raise TwitterProcessorException("No json")
         
         if json_dict is None:
-            self.json_dict = json.loads(json_txt)
+            self.json_dict = anyjson.deserialize(json_txt)
         else:
             self.json_dict = json_dict
         
         if not json_txt:
-            self.json_txt = json.dumps(json_dict)
+            self.json_txt = json.serialize(json_dict)
         else:
             self.json_txt = json_txt
         
@@ -244,8 +244,6 @@
         #user
     
         user_fields = {
-            'id' : self.json_dict['from_user_id'],
-            'id_str' : self.json_dict['from_user_id_str'],
             'lang' : self.json_dict['iso_language_code'],
             'profile_image_url' : self.json_dict["profile_image_url"],
             'screen_name' : self.json_dict["from_user"],                   
--- a/script/rest/search_enmi.py	Thu Jan 20 12:53:01 2011 +0100
+++ b/script/rest/search_enmi.py	Thu Jan 20 19:28:51 2011 +0100
@@ -1,5 +1,6 @@
 from iri_tweet import models, utils
 from sqlalchemy.orm import sessionmaker
+import anyjson
 import sqlite3
 import twitter
 
@@ -49,7 +50,9 @@
             results = twitter. search(q=options.query, rpp=options.rpp, page=page)
             for tweet in results["results"]:
                 print tweet
-                processor = utils.TwitterProcessor(tweet, None, session, options.token_filename)
+                tweet_str = anyjson.serialize(tweet)
+                #invalidate user id
+                processor = utils.TwitterProcessor(tweet, tweet_str, session, options.token_filename)
                 processor.process()
                 session.flush()
             page += 1