Subversion Repositories SmartDukaan

Rev

Rev 4247 | Rev 13263 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
103 ashish 1
'''
2
Created on 26-Mar-2010
3
 
4
@author: ashish
5
'''
104 ashish 6
import datetime
7
import time
2286 ankur.sing 8
from time import strftime
122 ashish 9
from shop2020.thriftpy.model.v1.catalog.ttypes import status
434 ashish 10
from shop2020.thriftpy.model.v1.user.ttypes import Address
2286 ankur.sing 11
from shop2020.config.client.ConfigClient import ConfigClient
103 ashish 12
 
104 ashish 13
def to_py_date(java_timestamp):
155 ashish 14
    try:
15
        seconds = java_timestamp / 1000
16
        sub_seconds  = (java_timestamp % 1000.0) / 1000.0
17
        date = datetime.datetime.fromtimestamp(seconds + sub_seconds)
18
    except:
19
        #some error here. return None
20
        return None
104 ashish 21
 
22
    return date
23
 
24
def to_java_date(py_timestamp):
155 ashish 25
    try:
26
        java_date =  int(time.mktime(py_timestamp.timetuple())) * 1000 + py_timestamp.microsecond / 1000
27
        return java_date
28
    except:
29
        #some error here, return None
30
        return None
104 ashish 31
 
738 chandransh 32
def get_fdate_tdate(from_date, to_date):
104 ashish 33
    current_from_date = ""
34
    current_to_date = ""
304 ashish 35
 
104 ashish 36
    if from_date:
37
        current_from_date = to_py_date(from_date)   
38
    if to_date:
39
        current_to_date = to_py_date(to_date)
40
 
738 chandransh 41
    return current_from_date, current_to_date
115 ashish 42
 
43
def get_mssql_date(date):
44
    mssql_date_year = str(date.year)
45
    if date.month < 10:
46
        mssql_date_month = "0%d"%(date.month)
47
    else:
48
        mssql_date_month = str(date.month)
49
 
50
    if date.day < 10:
51
        mssql_date_day = "0%d"%(date.day)
52
    else:
53
        mssql_date_day = str(date.day)
54
 
55
    mssql_date = "%s%s%s"%(mssql_date_year,mssql_date_month, mssql_date_day)
56
    return int(mssql_date)
57
 
58
def get_mssql_time(date):
59
    mssql_date_hour = str(date.hour)
60
    if date.minute < 10:
61
        mssql_date_minute = "0%d"%(date.minute)
62
    else:
63
        mssql_date_minute = str(date.minute)
64
 
65
    if date.day < 10:
66
        mssql_date_second = "0%d"%(date.second)
67
    else:
68
        mssql_date_second = str(date.second)
69
 
70
    mssql_date = "%s%s%s"%(mssql_date_hour,mssql_date_minute, mssql_date_second)
122 ashish 71
    return int(mssql_date)
72
 
73
def log_entry(log_source, log_entry):
74
    if log_source.__class__.__name__ == 'str':
75
        print "%s : %s : %s" %(str(datetime.datetime.now()), log_source, log_entry)
76
    else:
155 ashish 77
        print "%s : %s : %s" %(str(datetime.datetime.now()), log_source.__class__.__name__, log_entry)
78
 
2286 ankur.sing 79
 
80
def log_risky_flag(item_id, risky):
81
    filename = ConfigClient().get_property('risky_flag_log')
82
    logfile = open(filename, 'a')
83
    logfile.write(str(strftime("%Y-%m-%d %H:%M:%S")) + ', ItemId=' + str(item_id) + ', Flag=' + str(risky) + '\n')
84
    logfile.close()
85
 
434 ashish 86
def to_address_string(address):
87
    address = Address
12979 kshitij.so 88
    pass
89
 
90
def getAsyncOperatorsForRecharge():
91
    return [9]