0

So I have many JSON objects which was returned from the Facebook API, one of which is as shown below.

{
  "_id": ObjectId("503ded9103c4b72fef12aa2f"),
  "from": {
    "category": "Company",
    "name": "Fortis Healthcare",
    "id": "165708715950"
  },
  "pid": "165708715950_377424172280794",
  "like_count": NumberInt(0),
  "can_remove": false,
  "created_time": "2012-04-02T09:58:48+0000",
  "message": "For academic info check out http:\/\/www.fortishospitals.com\/about-fortis-hospitals\/academic-initiatives.html",
  "id": "165708715950_377424172280794_4682416",
  "user_likes": false
}

What I need to do here is that I need to group all the dates belonging to their months and extract the 'message' parameter from these objects. How do I group the dates of these months?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
user1452759
  • 8,810
  • 15
  • 42
  • 58
  • 2
    What have you tried so far? What didn't work, and what did you expect to happen? – Martijn Pieters Sep 21 '12 at 06:31
  • 4
    ISO date parsing: [How to parse ISO formatted date in python?](http://stackoverflow.com/q/127803) – Martijn Pieters Sep 21 '12 at 06:33
  • What i need to do is that i need to pull out the date from 'created_time' (which will be 2012-04-02 in the above ex). I would have pulled out many such dates along with their message and they I need to group them according to their months (in this case, april). I have looked at the datetime module but I didn't quite understand it. – user1452759 Sep 21 '12 at 06:56
  • There is not much to understand there :) The parts you need to look at are [`datetime.strptime`](http://docs.python.org/library/datetime.html?highlight=strptime#datetime.datetime.strptime), which creates a `datetime` object from a string, and the property [`month`](http://docs.python.org/library/datetime.html?highlight=strptime#datetime.datetime.month) of this object. What have you tried so far? – filmor Sep 21 '12 at 08:32
  • 1
    Just to be clear - this is technically BSON data from MongoDB isn't it? (ie, not a raw JSON response from FB). Just in case a map/reduce inside the DB is desirable, or whether a fetch all documents from DB, then group it in Python is required... – Jon Clements Sep 21 '12 at 08:43
  • Yes. This data is returned from MongoDB. But I need to group all the message parameters of a single month together..... – user1452759 Oct 01 '12 at 10:56

0 Answers0