Trying to Parse JSON date to POST to another System (Python)
Question: I am trying to write a script to GET project data from Insightly and post to
10000ft. Essentially, I want to take any newly created project in one system
and create that same instance in another system. Both have the concept of a
'Project'

I am extremely new at this but I only to GET certain Project parameters in
Insightly to pass into the other system (PROJECT_NAME, LINKS:ORGANIZATION_ID,
DATE_CREATED_UTC) to name a few.

I plan to add logic to only POST projects with a DATE_CREATED_UTC > yesterday,
but I am clueless on how to setup the script to grab the JSON strings and
create python variables (JSON datestring to datetime). Here is my current
code. I am simply just printing out some of the variables I require to get
comfortable with the code.

    
    
    import urllib, urllib2, json, requests, pprint, dateutil
    from dateutil import parser
    import base64
    
    
    #Set the 'Project' URL
    insightly_url = 'https://api.insight.ly/v2.1/projects'
    insightly_key = 
    api_auth = base64.b64encode(insightly_key)
    
    
    headers = {
                    'GET': insightly_url,
                    'Authorization': 'Basic ' + api_auth
    
                    }
    req = urllib2.Request(insightly_url, None, headers)
    
    response = urllib2.urlopen(req).read()
    
    data = json.loads(response)
    for project in data:
        project_date = project['DATE_CREATED_UTC']
        project_name = project['PROJECT_NAME']
        print project_name + " " + project_date
    

Any help would be appreciated

Edits:

I have updated the previous code with the following:

    
    
    for project in data:
        project_date = datetime.datetime.strptime(project['DATE_CREATED_UTC'], '%Y-%m-%d %H:%M:%S').date()
        if project_date > (datetime.date.today() - datetime.timedelta(days=1)):
            print project_date
        else:
            print 'No New Project'
    

This returns every project that was created after yesterday, but now I need to
isolate these projects and post them to the other system


Answer: Here is an example of returning a
[`datetime`](http://docs.python.org/3.3/library/datetime.html#datetime.datetime)
object from a parsed string. We will use the
[`datetime.strptime`](http://docs.python.org/3.3/library/datetime.html#datetime.datetime.strptime)
method to accomplish this. Here is a [list of the format
codes](http://docs.python.org/3.3/library/datetime.html#strftime-strptime-
behavior) you can use to create a format string.

    
    
    >>> from datetime import datetime
    >>> date_string = '2014-03-04 22:30:55'
    >>> format = '%Y-%m-%d %H:%M:%S'
    >>> datetime.strptime(date_string, format)
    datetime.datetime(2014, 3, 4, 22, 30, 55)
    

As you can see, the `datetime.strptime` method returns a `datetime` object.

