Skip to content

Commit 9430ecb

Browse files
committed
Merge branch 'dev'
2 parents 769804c + 35f54f4 commit 9430ecb

16 files changed

+618
-1
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Editor configuration, see http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 4
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
max_line_length = off
13+
trim_trailing_whitespace = false

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,7 @@ venv.bak/
102102

103103
# mypy
104104
.mypy_cache/
105+
106+
*.sqlite3
107+
*.stackdump
108+
*.csv

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,28 @@
11
# shfe
2-
Shanghai Futures Exchange
2+
3+
This ia a simple spider designed to crawl in [Shanghai Futures Exchange official website](http://www.shfe.com.cn/).
4+
5+
# Install
6+
7+
```
8+
pip install -r requirements.txt
9+
```
10+
11+
# How to Run
12+
13+
## Windows
14+
15+
```
16+
> start.bat
17+
```
18+
19+
## Linux
20+
21+
```
22+
$ ./start.sh
23+
```
24+
25+
# Test Suite
26+
27+
You can test this project by either executing script `futures.py` directly,
28+
or, change directory into `/test/` and run script `test.py`.

app.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import sys
5+
import signal
6+
7+
from flask import Flask, render_template, url_for
8+
9+
from futures import SHFE
10+
11+
app = Flask(__name__)
12+
13+
@app.route('/', methods=['GET'])
14+
def index():
15+
return render_template('index.temp.html',
16+
pathAppJs=url_for('static', filename='app.js'),
17+
pathAppCss=url_for('static', filename='app.css'),
18+
)
19+
20+
@app.route('/ajax/spider/start/', methods=['POST'])
21+
def ajax():
22+
shfe = SHFE()
23+
24+
try:
25+
shfe.startSpider()
26+
finally:
27+
shfe.saveTable()
28+
29+
return 'hello'

dtutil.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import datetime
5+
import logging
6+
7+
import pandas as pd
8+
import numpy as np
9+
10+
'''
11+
@see https://docs.python.org/3/library/datetime.html
12+
@see https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Timestamp.html
13+
'''
14+
class MonthDay:
15+
def __init__(self, month, day, duration=None):
16+
self.month = month
17+
self.day = day
18+
self.duration = duration
19+
20+
def __eq__(self, date):
21+
if not date:
22+
raise TypeError('Argument `date` is not specified!')
23+
if isinstance(date, datetime.date) \
24+
or isinstance(date, datetime.datetime) \
25+
or isinstance(date, pd.Timestamp):
26+
return self.month == date.month \
27+
and (self.day == date.day \
28+
or (self.duration and date.day in self.getDuration()))
29+
else:
30+
raise TypeError(f'Argument `date` has invalid type: `{type(date)}`!')
31+
32+
def getDuration(self):
33+
return range(self.day + 1, self.day + self.duration)
34+
35+
'''
36+
公历新年(元旦),放假1天(1月1日);
37+
春节,放假3天(农历正月初一、初二、初三);
38+
清明节,放假1天(阳历清明当日);
39+
劳动节,放假1天(5月1日);
40+
端午节,放假1天(农历端午当日);
41+
中秋节,放假1天(农历中秋当日);
42+
国庆节,放假3天(10月1日、2日、3日)。
43+
44+
@see https://zh.wikipedia.org/wiki/中华人民共和国节日与公众假期
45+
'''
46+
Holiday = dict(
47+
# 元旦节
48+
NEW_YEAR = MonthDay(1, 1),
49+
# 劳动节
50+
LABORS_DAY = MonthDay(5, 1),
51+
# 国庆节
52+
NATION_DAY = MonthDay(10, 1, 3),
53+
)
54+
55+
def isWeekend(date):
56+
weekday = date.weekday()
57+
return weekday > 4
58+
59+
def isHoliday(date):
60+
for holiday in Holiday.values():
61+
if holiday == date:
62+
return True
63+
return False

0 commit comments

Comments
 (0)