Example #1
0
    def test_how_many_leap_days_valueerror(self):
        """Test ValueError raised by when.how_many_leap_days()"""
        d1 = when.today()
        d2 = when.yesterday()

        # from_date must be before to_date
        self.assertRaises(ValueError, when.how_many_leap_days, d1, d2)
Example #2
0
    def test_how_many_leap_days_valueerror(self):
        """Test ValueError raised by when.how_many_leap_days()"""
        d1 = when.today()
        d2 = when.yesterday()

        # from_date must be before to_date
        self.assertRaises(ValueError, when.how_many_leap_days, d1, d2)
Example #3
0
def calc_by_id(id):
    # print id
    try:
        data= connection.OSL15mk().collection.find({'id':id})[0]['data']
        data=pd.read_json(data)
        # print data
        # macdhist上穿0轴, 61均线斜率大于131均线或者在其上方, 5均线一次导数大于0,二次导数大于等于0, //还需要加入kdj, k>d并且d<20或30
        data['buy_mask']=(data['dmacdhist']>0)&(data['macdhist']>0) & \
                         ((data['macdhist']-data['dmacdhist'])<0 ) & \
                         (data['macd']<0) & (data['macdsignal']<0) & \
                         (( data['dma61']> data['dma131']) |(data['ma61']>data['ma131'])) & \
                         (data['ddma5']>=0)&(data['dma5']>0) & \
                         (data['volume']>=10000)
        # &(data['KDJ_K']>data['KDJ_D']) #& (data['dma61']>-0.1)
        #macdhist下穿0轴, 5日均线斜率小于0,
        # todo: 卖出点判断, 买入点加入前面几个周期. 面积小于某某值, 或者计分.
        data['sell_mask']=(data['dmacdhist']<0)&(data['macdhist']<0) & ((data['macdhist']-data['dmacdhist'])>0 ) & (data['dma5']<=0)
        # print data
        # print data['buy_mask']|(data.index>"2015-08-31 11:30:00")
        # start_date = datetime.datetime(yestorrday)

        # todo: 这里处理成时间的形式比较好
        today= str(when.today())+" 09:30:00"
        # print type(data.index[1])
        today_point = data[(data['buy_mask']|data['sell_mask'])&(data.index>today)][['buy_mask','sell_mask']]

        if data.ix[-1]['buy_mask']:
            return ('buy',today_point)
        if data.ix[-1]['sell_mask']:
            return ('sell',today_point)
        return False,False
    except:
        return False,False
Example #4
0
    def test_how_many_leap_days_typeerror(self):
        """Test TypeError raised by when.how_many_leap_days()"""
        d1 = when.today()
        d2 = when.yesterday()

        # from_date must be valid
        self.assertRaises(TypeError, when.how_many_leap_days, 'a', d2)
        # to_date must be valid
        self.assertRaises(TypeError, when.how_many_leap_days, d1, 'b')
Example #5
0
    def test_how_many_leap_days_typeerror(self):
        """Test TypeError raised by when.how_many_leap_days()"""
        d1 = when.today()
        d2 = when.yesterday()

        # from_date must be valid
        self.assertRaises(TypeError, when.how_many_leap_days, "a", d2)
        # to_date must be valid
        self.assertRaises(TypeError, when.how_many_leap_days, d1, "b")
Example #6
0
def is_valid_pack(pack, today=None):
    today = today if today else when.today()
    valid_days = [int(day) for day in pack['day'].split(',')]
    day = get_day_of_week(today)

    if pack['state'] == STATE['valid'] and pack['start_date'] <= today <= pack['end_date'] and day in valid_days:
        return True

    return False
Example #7
0
    def find_today(self):
        date = str(when.today())
        models = self.session.query(NewsModel).filter(
            NewsModel.date >= date).all()

        news = []
        for model in models:
            new = self.model_to_entity(model)
            news.append(new)
        return news
Example #8
0
    def test_how_many_leap_days_assert(self):
        """Test AssertionError raised by when.how_many_leap_days()"""
        d1 = when.today()
        d2 = when.yesterday()

        # from_date must be valid
        self.assertRaises(AssertionError, when.how_many_leap_days, 'a', d2)
        # to_date must be valid
        self.assertRaises(AssertionError, when.how_many_leap_days, d1, 'b')
        # from_date must be before to_date
        self.assertRaises(AssertionError, when.how_many_leap_days, d1, d2)
Example #9
0
    def test_how_many_leap_days_assert(self):
        """Test AssertionError raised by when.how_many_leap_days()"""
        d1 = when.today()
        d2 = when.yesterday()

        # from_date must be valid
        self.assertRaises(AssertionError, when.how_many_leap_days, 'a', d2)
        # to_date must be valid
        self.assertRaises(AssertionError, when.how_many_leap_days, d1, 'b')
        # from_date must be before to_date
        self.assertRaises(AssertionError, when.how_many_leap_days, d1, d2)
Example #10
0
def get_today_start_end_time(st, ed):
    today = when.today()
    format_str = '%s %s'

    if st < ed:
        st_time_str = format_str % (today, st)
        ed_time_str = format_str % (today, ed)

        return st_time_str, ed_time_str

    tomorrow = when.tomorrow()
    st_time_str = format_str % (today, st)
    ed_time_str = format_str % (tomorrow, ed)

    return st_time_str, ed_time_str
Example #11
0
def get_yesterday_start_end_time(st, ed):
    yesterday = when.yesterday()
    format_str = '%s %s'

    if st < ed:
        st_time_str = format_str % (yesterday, st)
        ed_time_str = format_str % (yesterday, ed)

        return st_time_str, ed_time_str

    today = when.today()
    st_time_str = format_str % (yesterday, st)
    ed_time_str = format_str % (today, ed)

    return st_time_str, ed_time_str
Example #12
0
def get_30days_start_end_time(st, ed):
    today = when.today()
    thirty_days_ago = when.past(days=30).date()
    format_str = '%s %s'

    if st < ed:
        st_time_str = format_str % (thirty_days_ago, st)
        ed_time_str = format_str % (today, ed)

        return st_time_str, ed_time_str

    tomorrow = when.tomorrow()
    st_time_str = format_str % (thirty_days_ago, st)
    ed_time_str = format_str % (tomorrow, ed)

    return st_time_str, ed_time_str
Example #13
0
    def test_format(self):
        """Test when.format()"""
        now = when.now()
        today = when.today()
        current_time = now.time()

        for format_string in (
            "%a",
            "%A",
            "%b",
            "%B",
            "%c",
            "%d",
            "%f",
            "%H",
            "%I",
            "%j",
            "%m",
            "%M",
            "%p",
            "%S",
            "%U",
            "%w",
            "%W",
            "%x",
            "%X",
            "%y",
            "%Y",
            "%z",
            "%Z",
            "%A, %B %d, %Y %I:%M %p",
        ):
            # Test date objects
            builtin_date = now.strftime(format_string)
            result_date = when.format(now, format_string)
            self.assertEqual(builtin_date, result_date)

            # Test datetime objects
            builtin_datetime = today.strftime(format_string)
            result_datetime = when.format(today, format_string)
            self.assertEqual(builtin_datetime, result_datetime)

            # Test time objects
            builtin_time = current_time.strftime(format_string)
            result_time = when.format(current_time, format_string)
            self.assertEqual(builtin_time, result_time)
Example #14
0
def tag_image(image, name, fill_color=(0,0,0,128), shadowcolor=(227,43,23,128)):
    font_name = first_font()
    screen = image.convert("RGBA")
    font_size = 1
    font = ImageFont.truetype(font_name, font_size)
    border_size = 5
    scaler = 1.25
    year = str(when.today()).partition("-")[0]
    text = "%s %s %s" % (copyright_symbol, name, year)
    while font.getsize(text)[0] < img_fraction*image.size[0]:
        # iterate until the text size is just larger than the criteria
        font_size += 1
        font = ImageFont.truetype(font_name, font_size)
    #Draw Name
    x = screen.width * 0.05
    y = screen.height-(font_size*scaler)
    font = ImageFont.truetype(font_name, font_size)
    out = draw_stroke(x, y, screen, font, border_size=border_size, text=text, shadowcolor=shadowcolor, fill_color=fill_color)
    #Save Image
    return out
Example #15
0
    def test_format(self):
        """Test when.format()"""
        now = when.now()
        today = when.today()
        current_time = now.time()

        for format_string in ('%a', '%A', '%b', '%B', '%c', '%d', '%f', '%H',
                              '%I', '%j', '%m', '%M', '%p', '%S', '%U', '%w',
                              '%W', '%x', '%X', '%y', '%Y', '%z', '%Z',
                              '%A, %B %d, %Y %I:%M %p'):
            # Test date objects
            builtin_date = now.strftime(format_string)
            result_date = when.format(now, format_string)
            self.assertEqual(builtin_date, result_date)

            # Test datetime objects
            builtin_datetime = today.strftime(format_string)
            result_datetime = when.format(today, format_string)
            self.assertEqual(builtin_datetime, result_datetime)

            # Test time objects
            builtin_time = current_time.strftime(format_string)
            result_time = when.format(current_time, format_string)
            self.assertEqual(builtin_time, result_time)
Example #16
0
    def test_format(self):
        """Test when.format()"""
        now = when.now()
        today = when.today()
        current_time = now.time()

        for format_string in ('%a', '%A', '%b', '%B', '%c', '%d', '%f', '%H',
                              '%I', '%j', '%m', '%M', '%p', '%S', '%U', '%w',
                              '%W', '%x', '%X', '%y', '%Y', '%z', '%Z',
                              '%A, %B %d, %Y %I:%M %p'):
            # Test date objects
            builtin_date = now.strftime(format_string)
            result_date = when.format(now, format_string)
            self.assertEqual(builtin_date, result_date)

            # Test datetime objects
            builtin_datetime = today.strftime(format_string)
            result_datetime = when.format(today, format_string)
            self.assertEqual(builtin_datetime, result_datetime)

            # Test time objects
            builtin_time = current_time.strftime(format_string)
            result_time = when.format(current_time, format_string)
            self.assertEqual(builtin_time, result_time)
Example #17
0
 def test_shift_typeerror(self):
     """Test TypeError raised by when.shift()"""
     self.assertRaises(TypeError, when.shift, 'a')
     self.assertRaises(TypeError, when.shift, when.today())
Example #18
0
def get_day_of_week(day=None):
    '''
    取值1-7,对应周一至周日
    '''
    day = day if day else when.today()
    return day.weekday() + 1
Example #19
0
 def test_today(self):
     """Test when.today()"""
     self.assertEqual(when.today(), self.today)
Example #20
0
 def test_shift_assert(self):
     """Test AssertionError raised by when.shift()"""
     self.assertRaises(AssertionError, when.shift, 'a')
     self.assertRaises(AssertionError, when.shift, when.today())
Example #21
0
 def test_is_timezone_aware_naive(self):
     """Test AssertionError raised by when.is_timezone_naive()"""
     today = when.today()
     self.assertRaises(AssertionError, when.is_timezone_aware, today)
Example #22
0
 def test_is_timezone_naive_typeerror(self):
     """Test TypeError raised by when.is_timezone_naive()"""
     today = when.today()
     self.assertRaises(TypeError, when.is_timezone_aware, today)
Example #23
0
#-*-coding:utf-8-*-
from openpyxl import load_workbook
import when

##装载表格
wb = load_workbook(filename='58发房.xlsx')

# sheet_ranges = wb['6月22日']

##打印worksheet
# print (wb.get_sheet_names())

##确定当日时间
i = when.today()
today = str(i.month) + "月" + str(i.day) + "日"
# print (today)

##如果当日sheet未建立的话,就建立
if today not in wb.get_sheet_names():
    ws2 = wb.create_sheet(title="6月23日")

##选择今日sheet
sheet_ranges = wb[today]
# print (sheet_ranges)

##打印I21值
# print (type(sheet_ranges['I21'].value))

##赋值表格J21
# sheet_ranges['J21'].value = 99
# print(sheet_ranges['J21'].value)
Example #24
0
 def get_holiday_room_fees(self, store_id, rt_id, day=None):
     day = day if day else when.today()
     fees = self.get_room_fees_ctl(store_id, rt_id, str(day), 'holiday')
     return fees
Example #25
0
 def test_shift_typeerror(self):
     """Test TypeError raised by when.shift()"""
     self.assertRaises(TypeError, when.shift, "a")
     self.assertRaises(TypeError, when.shift, when.today())
Example #26
0
#coding=utf8
import when

print when.timezone()

print when.today()

print when.tomorrow()

print when.now()
Example #27
0
 def test_shift_assert(self):
     """Test AssertionError raised by when.shift()"""
     self.assertRaises(AssertionError, when.shift, 'a')
     self.assertRaises(AssertionError, when.shift, when.today())
Example #28
0
 def test_is_timezone_naive_typeerror(self):
     """Test TypeError raised by when.is_timezone_naive()"""
     today = when.today()
     self.assertRaises(TypeError, when.is_timezone_aware, today)
Example #29
0
 def test_today(self):
     """Test when.today()"""
     self.assertEqual(when.today(), self.today)
Example #30
0
 def test_is_timezone_aware_naive(self):
     """Test AssertionError raised by when.is_timezone_naive()"""
     today = when.today()
     self.assertRaises(AssertionError, when.is_timezone_aware, today)
Example #31
0
 def test_today(self):
     self.assertEqual(when.today(), self.today)
Example #32
0
#-*-coding:utf-8-*-
from openpyxl import load_workbook
import when

##装载表格
wb = load_workbook(filename = '58发房.xlsx')

# sheet_ranges = wb['6月22日']

##打印worksheet
# print (wb.get_sheet_names())

##确定当日时间
i = when.today()
today = str(i.month) + "月" + str(i.day) + "日"
# print (today)

##如果当日sheet未建立的话,就建立
if today not in wb.get_sheet_names():
	ws2 = wb.create_sheet(title="6月23日")

##选择今日sheet
sheet_ranges = wb[today]
# print (sheet_ranges)

##打印I21值
# print (type(sheet_ranges['I21'].value))

##赋值表格J21
# sheet_ranges['J21'].value = 99
# print(sheet_ranges['J21'].value)