So I have a script which uses the following imports:
import sys
import os.path
import requests
import json
import csv
import glob2
import shutil
from time import sleep
from time import gmtime, strftime
import time
from datetime import datetime
I'm trying to convert row[15] which is a date string that looks like "23/03/2015 00:00" (read from a csv) into unix time.
This is what that portion of code looks like:
{"name":"referral_date", "value": time.mktime(datetime.strptime(row[15], "%d/%m/%Y %H:%S").timetuple()) }
Every time I try it, it comes back with this:
AttributeError: 'str' object has no attribute 'mktime'
And yet, in a seperate test file, i've tried the following:
import time
from datetime import datetime
mylist = ["23/03/2015 00:00"]
test = time.mktime(datetime.strptime(mylist[0], "%d/%m/%Y %H:%S").timetuple())
print(test)
Which, as you'd expect, results in 1427031000.0 - what am I doing wrong?