Skip to content

Instantly share code, notes, and snippets.

@eXtrem0us
Last active March 18, 2017 15:31
Show Gist options
  • Save eXtrem0us/48357b7b270fbde350aafb7fb6415866 to your computer and use it in GitHub Desktop.
Save eXtrem0us/48357b7b270fbde350aafb7fb6415866 to your computer and use it in GitHub Desktop.
This python code is written to be used in very specific and personal manner
#!/usr/bin/python
#
# This Code changes lines like:
# "Mar 14, 2017 1:34 PM",blahblahblah
# to This one:
# "2017-03-14T13:34",blahblahblah
#
monthlist={\
'Jan':'01',\
'Feb':'02',\
'Mar':'03',\
'Apr':'04',\
'May':'05',\
'Jun':'06',\
'Jul':'07',\
'Aug':'08',\
'Sep':'09',\
'Oct':'10',\
'Nov':'11',\
'Dec':'12'}
#hourlist={'AM':0,'PM':12}
newdate=open ("revolvedate.csv","w")
with open ("verynewussd.csv","r") as olddate:
for line in olddate:
datepart=line[1:line.find("\"",1)]
b_month=monthlist[datepart[:3]]
temp=datepart.find(',')
b_day=datepart[4:temp]
if len(b_day)==1:
b_day='0'+b_day
b_year=datepart[temp+2:temp+6]
temp1=temp+6
temp2=datepart.find(':',temp1)
b_hour=datepart[temp1:temp2].strip()
temp3=datepart.find(' ',temp2)
b_minute=datepart[temp2+1:temp3]
b_daynight=datepart[temp3+1:]
if b_hour!='12' and b_daynight=='PM':
b_hour=str(int(b_hour)+12)
elif b_hour=='12' and b_daynight=='AM':
b_hour='00'
if len(b_hour)==1:
b_hour='0'+b_hour
finaldate=b_year+'-'+b_month+'-'+b_day+'T'+b_hour+':'+b_minute
finalline="\""+finaldate+line[line.find("\"",1):]
#finalline=line[line.find(",",2):] #PYTHON SUCKS!!
newdate.write(finalline)
newdate.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment