-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathutils.py
More file actions
98 lines (78 loc) · 2.67 KB
/
utils.py
File metadata and controls
98 lines (78 loc) · 2.67 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/python
# coding:utf-8
import datetime
import urllib2
from bs4 import BeautifulSoup
def f(num):
"""
结果四舍五入保留两位小数
:param num: 待格式化数字
:return:
"""
return round(float(num), 2)
def get_start_date(n):
"""
获取n天前的日期
now = datetime.now()
print now.strftime('%Y-%m-%d')
strNow = '2012-01-03'
nowDate = time.strptime(strNow, "%Y-%m-%d")
%a 星期几的简写 Weekday name, abbr.
%A 星期几的全称 Weekday name, full
%b 月分的简写 Month name, abbr.
%B 月份的全称 Month name, full
%c 标准的日期的时间串 Complete date and time representation
%d 十进制表示的每月的第几天 Day of the month
%H 24小时制的小时 Hour (24-hour clock)
%I 12小时制的小时 Hour (12-hour clock)
%j 十进制表示的每年的第几天 Day of the year
%m 十进制表示的月份 Month number
%M 十时制表示的分钟数 Minute number
%S 十进制的秒数 Second number
%U 第年的第几周,把星期日做为第一天(值从0到53)Week number (Sunday first weekday)
%w 十进制表示的星期几(值从0到6,星期天为0)weekday number
%W 每年的第几周,把星期一做为第一天(值从0到53) Week number (Monday first weekday)
%x 标准的日期串 Complete date representation (e.g. 13/01/08)
%X 标准的时间串 Complete time representation (e.g. 17:02:10)
%y 不带世纪的十进制年份(值从0到99)Year number within century
%Y 带世纪部分的十制年份 Year number
%z,%Z 时区名称,如果不能得到时区名称则返回空字符。Name of time zone
%% 百分号
:rtype : object
:param n:
:return:
"""
day = datetime.date.today()
return day + datetime.timedelta(-n)
def is_working_day(dt=datetime.datetime.now()):
"""
检查某天是否是工作日,周一为0
:param dt:
:return:
"""
if 0 <= dt.weekday() <= 4:
return True
else:
return False
def is_working_hour(dt=datetime.datetime.now()):
"""
检查今天是否是交易时间段
:param dt:
:return:
"""
if dt.time().hour <= 9 and dt.time().minute < 15:
return False
elif (dt.time().hour >= 11 and dt.time().minute > 30) and (dt.time().hour < 13):
return False
elif dt.time().hour >= 15 and dt.time().minute > 0:
return False
else:
return True
def get_page(url):
request = urllib2.Request(url)
response = urllib2.urlopen(request)
return response.read()
def parse_page(url):
return BeautifulSoup(get_page(url),"lxml")
if __name__ == "__main__":
pass