Search code examples
pythonjsondjangotwittertweepy

Read specific part of json string with python


I am currently working on a programme within the django environment which operates off a json api provided by a third party. There is an object within that API which I want however the string of information it provides is too much for me.

The data I want is the created_at tag from the twitter api using tweepy. This created_at contains data in the following format:

"created_at": "Mon Aug 27 17:21:03 +0000 2012"

This is all fine however this will return the date AND time whereas I simply want the the time part of the above example i.e. 17:21:03.

Is there any way I can just take this part of the created_at response string and store it in a separate variable?


Solution

  • You can use the dateutil module

    from dateutil import parser
    
    created_at = "Mon Aug 27 17:21:03 +0000 2012"
    created_at = parser.parse(created_at)
    print created_at.time()
    

    Output:

    17:21:03