-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils01.py
53 lines (40 loc) · 1.36 KB
/
utils01.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import datetime
def jsonToPyDate(js_date):
"""
Convert javascript date to python date
js_date: 'Date(1415138400000+0200)', should return 5 Nov 2014
timeoffset +0200 = 02 hrs, 00 minites
JavaScript dates are calculated in milliseconds
from 01 January, 1970 00:00:00 Universal Time (UTC).
One day contains 86,400,000 millisecond.
"""
return datetime.datetime(1970, 1, 1,
int(js_date[19:21]),
int(js_date[21:23])) + \
datetime.timedelta(float(js_date[5:18])/86400000)
def YahooDate(dt):
"""
Convert python datetime obj to string 'CCYY-MM-DD'
This is the Yahoo format
"""
return dt.strftime('%Y-%m-%d')
def jsonToYahooDate(js_date):
return YahooDate(jsonToPyDate(js_date))
def POSIX_filename(filename):
"""
generates a POSIX compliant filename
"""
#--POSIX compliant chars
s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-'
fn = ''
for char in filename:
if s.find(char) > -1:
#--char found
fn = '%s%s' % (fn, char)
return fn
#f = '/home/steve/pythonApp/jse/pickle/instruments.pkl'
#print md5sum(f)
#dt = jsonToPyDate('Date(1415138400000+0200)')
#print dt
#print YahooDate(dt)
#print jsonToYahooDate('Date(1415138400000+0200)')