Permalink
Browse files

Fixed minors errors in docs.

  • Loading branch information...
eamartin committed Jan 3, 2011
1 parent 3b68066 commit 96bde0f74ad3602b15f61225536f6d562052854d
Showing with 34 additions and 18 deletions.
  1. +9 −10 README.md
  2. +25 −8 twitterexample.py
View
@@ -55,30 +55,29 @@ Perfect for (amongst other things) wrapping Python objects around JSON data retu
user = micromodels.ModelField(TwitterUser)
- json_data = urlopen('http://api.twitter.com/1/statuses/show/20.json')
+ json_data = urlopen('http://api.twitter.com/1/statuses/show/20.json').read()
tweet = Tweet(json_data, is_json=True)
print tweet.user.name
print tweet.user.get_profile_url()
print tweet.id
print tweet.created_at.strftime('%A')
+ #new fields can also be added to the model instance
+ #a method needs to be used to do this to handle serialization
+
+ tweet.add_field('retweet_count', 44, micromodels.IntegerField())
+ print tweet.retweet_count
+
#the data can be cast to a dict (still containing time object)
- tweet.to_dict()
+ print tweet.to_dict()
#it can also be cast to JSON (fields handle their own serialization)
- tweet.to_json()
+ print tweet.to_json()
#tweet.to_json() is equivalent to this call
- import json
json.dumps(tweet.to_dict(serial=True))
- #new fields can also be added to the model instance
- #a method needs to be used to do this to handle serialization
-
- tweet.add_field('retweet_count', 44, micromodels.IntegerField())
- print tweet.retweet_count
-
## Field reference
View
@@ -19,11 +19,28 @@ class Tweet(micromodels.Model):
created_at = micromodels.DateTimeField(format="%a %b %d %H:%M:%S +0000 %Y")
user = micromodels.ModelField(TwitterUser)
-json_data = urlopen('http://api.twitter.com/1/statuses/show/20.json')
-tweet = Tweet(json.load(json_data))
-
-print "Tweet was posted by %s (%s) on a %s" % (
- tweet.user.name,
- tweet.user.get_profile_url(),
- tweet.created_at.strftime("%A")
-)
+
+json_data = urlopen('http://api.twitter.com/1/statuses/show/20.json').read()
+tweet = Tweet(json_data, is_json=True)
+
+print tweet.user.name
+print tweet.user.get_profile_url()
+print tweet.id
+print tweet.created_at.strftime('%A')
+
+#new fields can also be added to the model instance
+#a method needs to be used to do this to handle serialization
+
+tweet.add_field('retweet_count', 44, micromodels.IntegerField())
+print tweet.retweet_count
+
+#the data can be cast to a dict (still containing time object)
+print tweet.to_dict()
+
+#it can also be cast to JSON (fields handle their own serialization)
+print tweet.to_json()
+
+#tweet.to_json() is equivalent to this call
+json.dumps(tweet.to_dict(serial=True))
+
+

0 comments on commit 96bde0f

Please sign in to comment.