用inotify配合php程序处理深圳和上海行情文件
show2003.dbf
SJSXXN.DBF
SJSHQ.DBF
SJSZS.DBF
SJSXX.DBF
hq.php //处理dbf文件,将文件中的数据原样添加至数据库
<?php
/***
* 此文件可以单独运行,无需关联其它文件
*/
$a = microtime(true);
date_default_timezone_set ('Asia/Shanghai');
set_time_limit(0);
ini_set('memory_limit','100M');
ini_set('pcre.backtrack_limit','-1');
class mysql{
private $dbConfig;
public $errno=0;
public function __construct($dbConfig){
$this->dbConfig = $dbConfig;
}
public function __destruct(){
@mysql_close();
}
private function connectiondb(){
$connect = null;
$connect=@mysql_connect($this->dbConfig['DB_HOST'],$this->dbConfig['DB_USER'],$this->dbConfig['DB_PWD']);
if ($connect != null){
if(isset($this->dbConfig['DB_CHARSET'])){
@mysql_query("SET NAMES ".$this->dbConfig['DB_CHARSET'],$connect);
}
return $connect;
}else{
return false;
}
}
private function selectdb(){
if ($this->connectiondb() != false){
return @mysql_select_db($this->dbConfig['DB_NAME']);
}else{
return false;
}
}
public function execute($sqls){
$rt = 0;
$this->errno = 0;
if ($sqls != null && $this->selectdb() != false){
@mysql_query('start transaction');
@mysql_query('SET autocommit=0');
foreach($sqls as $sql){
@mysql_query($sql);
}
$eno = @mysql_errno ();
if($eno){
@mysql_query('rollback');
$this->errno = $eno;
}else{
$rt = @mysql_query('commit');
}
$this->__destruct();
}
return $rt;
}
}
/*****************************处理dbf文件 开始***********************************/
function sh_hq(&$rv,$rk){
$rv = preg_replace("/-.---|-/si","null",$rv);
}
function sz_hq(&$rv,$rk){
}
function sz_xx(&$rv,$rk){
$rv=trim($rv);
$t=strpos($rv,".");
if($t === 0){
$rv = "0".$rv;
}
if($rk == 2){
$rv = addslashes($rv);
}
}
function sz_xxn(&$rv,$rk){
$rv=trim($rv);
$t=strpos($rv,".");
if($t === 0){
$rv = "0".$rv;
}
if($rk == 3){
$rv = addslashes($rv);
}
}
function myReadFile(&$dbObj,&$cacaheObj,$configs){
if(file_exists($configs['tmpSjPath'])) {
$lasttime = file_get_contents($configs['tmpSjPath']);
}else{
$lasttime = "";
}
$sql = "";
$rt = -1;
$ct = "";
$cacheKeySj="";
$fields = array();
if(!file_exists($configs['dbfname'])) {
exit();//文件不存在
}
$fdbf = fopen($configs['dbfname'], 'r');
$buf = fread($fdbf, 32);
$header = unpack("VRecordCount/vFirstRecord/vRecordLength",substr($buf, 4, 8));
$goon = true;
$unpackString = '';
while ($goon && ! feof($fdbf)) { // read fields:
$buf = fread($fdbf, 32);
if (substr($buf, 0, 1) == chr(13)) {
$goon = false;
}else { // end of field list
$field = unpack(
"a11fieldname/A1fieldtype/Voffset/Cfieldlen/Cfielddec",
substr($buf, 0, 18));
//echo 'Field: ' . json_encode($field) . '<br/>';
$unpackString .= "A$field[fieldlen]$field[fieldname]/";
array_push($fields, $field);
}
}
fseek($fdbf, $header['FirstRecord'] + 1); // move back to the start of the
// first record (after the field definitions)
for ($i = 1; $i <= $header['RecordCount']; $i ++) {
$buf = fread($fdbf, $header['RecordLength']);
$record = unpack($unpackString, $buf);
if(!isset($record[$configs['key']])){
continue;
}
if($record[$configs['key']] == '000000'){
$sfm = trim($record[$configs['time']]);
if(strlen($sfm) == 5){
$sfm = "0".$sfm;
}
$tmpLasttime = date("Y-m-d H:i:s",strtotime($record[$configs['date']].$sfm));
if($tmpLasttime != $lasttime){
$lasttime = $tmpLasttime;
if($configs['cacheKeySj'] == 1){
//缓存key的一部分
$cacheKeySj = date("YmdHis",strtotime($record[$configs['date']].$sfm));
}
file_put_contents($configs['tmpSjPath'],$lasttime);
if($configs['is_gl'] == 1 && $tmpLasttime < date("Y-m-d").' 09:25:00'){
fclose($fdbf);//没有新数据,结束流程
exit();
}
if($configs['is_gl'] == 1 && $tmpLasttime >= date("Y-m-d").' 15:00:00'){
$lasttime = date("Y-m-d").' 15:00:00';
}
}else{
fclose($fdbf);//没有新数据,结束流程
exit();
}
}else{
$vt = "";
$code="";
$name="";
$rk = 0;
foreach($record as $k=>$rv){
$rv = preg_replace("/ /si","",$rv);
$rv = iconv ('GBK','UTF-8//IGNORE', $rv);
$configs['tbname']($rv,$rk);//每种类型数据处理不一样
if($i == 2){
if($rk-1 > 0){
$ct .= "`f".($rk-1)."`,";
}
}
if($rk == 0){
$code = $rv;
}else if($rk == 1){
$name = $rv;
}else{
$vt .= "'".$rv."',";
}
$rk++;
}
$sql .= "(".$vt."'".$lasttime."','".$code."','".$name."'),";
$cacaheObj->set($configs['tbname']."_".$code.$cacheKeySj,$vt."'".$lasttime."','".$code."','".$name,false,28800);
}
}
fclose($fdbf);
if($sql != ""){
$sql = "INSERT INTO ".$configs['tbname']."(". $ct ."`f0`,`code`,`name`) VALUES ".$sql;
$sqls = array("DELETE FROM ".$configs['tbname']." WHERE f0 = '".$lasttime."'",rtrim($sql,','));
$rt = $dbObj->execute ($sqls);
}
return $rt;
}
/*****************************处理dbf文件 结束***********************************/
$lastPath = dirname(__FILE__);//上一级目录的绝对路径
if(isset($argv[1])){
$dbfname = $argv[1];
}else{
//$dbfname = "SJSZS.DBF";
exit();//参数不存在
}
$cacheConfigs = array(
'CACHE_MEMCACHE' => array(
array('192.168.1.101', 11211),
),
);
$dbConfigs = array(
'DB_TYPE'=>'mysql',
'DB_HOST'=>'192.168.1.101',
'DB_NAME'=>'db_hq',
'DB_USER'=>'cc',
'DB_PWD'=>'123456',
'DB_CHARSET'=>'UTF8',
);
$cacaheObj = new Memcache();
foreach($cacheConfigs['CACHE_MEMCACHE'] as $v){
$cacaheObj->addServer($v[0],$v[1]);
}
$configs=array();
$configs['dbfname'] = $dbfname;
$configs['cacheKeySj'] = 0;
$configs['is_gl'] = 0;//是否过滤9:25分以前和15:00:00以后的数据
$configs['market'] = 'SZ';
if(strpos($dbfname,"show2003.") !== false){
$configs['tbname'] = "sh_hq";
$configs['key'] = "S1";
$configs['date'] = "S6";
$configs['time'] = "S2";
$configs['cacheKeySj'] = 1;
$configs['type'] = 1;
$configs['is_gl'] = 1;
$configs['market'] = 'SH';
}else if(strpos($dbfname,"SJSHQ.") !== false){
$configs['tbname'] = "sz_hq";
$configs['key'] = "HQZQDM";
$configs['date'] = "HQZQJC";
$configs['time'] = "HQCJBS";
$configs['cacheKeySj'] = 1;
$configs['type'] = 2;
$configs['is_gl'] = 1;
}else if(strpos($dbfname,"SJSXX.") !== false){
$configs['tbname'] = "sz_xx";
$configs['key'] = "XXZQDM";
$configs['date'] = "XXZQJC";
$configs['time'] = "XXBLDW";
}else if(strpos($dbfname,"SJSXXN.") !== false){
$configs['tbname'] = "sz_xxn";
$configs['key'] = "XXZQDM";
$configs['date'] = "XXZQJC";
$configs['time'] = "XXBLDW";
}
if(!isset($configs['tbname'])){
exit();
}else{
$configs['tmpSjPath'] = $lastPath."/tmp_".$configs['tbname']."_sj.txt";
}
$dbObj = new mysql($dbConfigs);
$b=microtime(true);
$rt = myReadFile($dbObj,$cacaheObj,$configs);
$c = microtime(true);
echo $configs['tbname'].(number_format(($b-$a), 10, '.',''))."s"."|".(number_format(($c-$b), 10, '.',''))."s"."|".(number_format(($c-$a), 10, '.',''))."s"."--".$rt.chr(10);
?>
dbf_code.php //获取基础的代码数据,具体字段参见code表
获取汉字首拼方法有缺陷,有很多汉字都无法获取首拼,解决中。。。
<?php
/***
* 此文件可以单独运行,无需关联其它文件
*/
$a = microtime(true);
date_default_timezone_set ('Asia/Shanghai');
set_time_limit(0);
ini_set('memory_limit','100M');
ini_set('pcre.backtrack_limit','-1');
class mysql{
private $dbConfig;
public $errno=0;
public function __construct($dbConfig){
$this->dbConfig = $dbConfig;
}
public function __destruct(){
@mysql_close();
}
private function connectiondb(){
$connect = null;
$connect=@mysql_connect($this->dbConfig['DB_HOST'],$this->dbConfig['DB_USER'],$this->dbConfig['DB_PWD']);
if ($connect != null){
if(isset($this->dbConfig['DB_CHARSET'])){
@mysql_query("SET NAMES ".$this->dbConfig['DB_CHARSET'],$connect);
}
return $connect;
}else{
return false;
}
}
private function selectdb(){
if ($this->connectiondb() != false){
return @mysql_select_db($this->dbConfig['DB_NAME']);
}else{
return false;
}
}
public function execute($sqls){
$rt = 0;
$this->errno = 0;
if ($sqls != null && $this->selectdb() != false){
@mysql_query('start transaction');
@mysql_query('SET autocommit=0');
foreach($sqls as $sql){
@mysql_query($sql);
}
$eno = @mysql_errno ();
if($eno){
@mysql_query('rollback');
$this->errno = $eno;
}else{
$rt = @mysql_query('commit');
}
$this->__destruct();
}
return $rt;
}
}
/*****************************处理dbf文件 开始***********************************/
/**
* @desc 获取单个汉字的首字母
* @param string $s0 中文字串
* @return string|NULL 字母
*/
function getfirstchar($s0){
$fchar = ord($s0{0});
if($fchar >= ord("A") and $fchar <= ord("z") )return strtoupper($s0{0});
$s1 = @iconv("UTF-8","gb2312", $s0);
$s2 = @iconv("gb2312","UTF-8", $s1);
if($s2 == $s0){$s = $s1;}else{$s = $s0;}
$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
if($asc >= -20319 and $asc <= -20284) return "A";
if($asc >= -20283 and $asc <= -19776) return "B";
if($asc >= -19775 and $asc <= -19219) return "C";
if($asc >= -19218 and $asc <= -18711) return "D";
if($asc >= -18710 and $asc <= -18527) return "E";
if($asc >= -18526 and $asc <= -18240) return "F";
if($asc >= -18239 and $asc <= -17923) return "G";
if($asc >= -17922 and $asc <= -17418) return "H";
if($asc >= -17417 and $asc <= -16475) return "J";
if($asc >= -16474 and $asc <= -16213) return "K";
if($asc >= -16212 and $asc <= -15641) return "L";
if($asc >= -15640 and $asc <= -15166) return "M";
if($asc >= -15165 and $asc <= -14923) return "N";
if($asc >= -14922 and $asc <= -14915) return "O";
if($asc >= -14914 and $asc <= -14631) return "P";
if($asc >= -14630 and $asc <= -14150) return "Q";
if($asc >= -14149 and $asc <= -14091) return "R";
if($asc >= -14090 and $asc <= -13319) return "S";
if($asc >= -13318 and $asc <= -12839) return "T";
if($asc >= -12838 and $asc <= -12557) return "W";
if($asc >= -12556 and $asc <= -11848) return "X";
if($asc >= -11847 and $asc <= -11056) return "Y";
if($asc >= -11055 and $asc <= -10247) return "Z";
return null;
}
/**
* @desc 获取汉字首拼
* @param string $zh 汉字字符串
* @return string 首字母拼音
*/
function converHzToSP($zh){
$ret = "";
$s1 = @iconv("UTF-8","gb2312", $zh);
$s2 = @iconv("gb2312","UTF-8", $s1);
if($s2 == $zh){$zh = $s1;}
for($i = 0; $i < strlen($zh); $i++){
$s1 = substr($zh,$i,1);
$p = ord($s1);
if($p > 160){
$s2 = substr($zh,$i++,2);
$ret .= getfirstchar($s2);
}else{
$ret .= $s1;
}
}
return $ret;
}
function setTypeSH($code,&$pid,&$catid,&$catname){
$str = substr($code,0,2);
switch ($str){
case '00':
$pid = 731;
$str = substr($code,2,1);
if($str == '9' || $code == '000300'){
$catid = 748;
$catname = "中证指数";
return 1;
}
$catid = 733;
$catname = "上证指数";
return 1;
break;
case '01':
$pid = 737;
$catid = 738;
$catname = "上证国债";
return 1;
break;
case '02':
$pid = 737;
$catid = 739;
$catname = "上证贴债";
return 1;
break;
case '10':
$pid = 731;
$catid = 744;
$catname = "上证出入库";
return 1;
break;
case '11':
$pid = 731;
$catid = 742;
$catname = "上证转债";
return 1;
break;
case '12':
$pid = 737;
$catid = 740;
$catname = "企业债";
return 1;
break;
case '13':
$pid = 737;
$catid = 741;
$catname = "地债";
return 1;
break;
case '20':
$pid = 731;
$catid = 743;
$catname = "上证回购";
return 1;
break;
case '50':
$pid = 731;
$catid = 736;
$catname = "上证基金";
return 1;
break;
case '51':
$pid = 731;
$str = substr($code,0,3);
if($str == '510'){
$catid = 745;
$catname = "ETF基金";
return 1;
}else if($str == '519'){
$catid = 746;
$catname = "开放基金";
return 1;
}
break;
case '52':
$pid = 731;
$str = substr($code,0,3);
if($str == '521' || $str == '523'){
$catid = 746;
$catname = "开放基金";
return 1;
}else if($str == '522'){
$catid = 745;
$catname = "ETF基金";
return 1;
}
break;
case '60':
$pid = 731;
$catid = 734;
$catname = "上证A股";
return 1;
break;
case '90':
$pid = 731;
$catid = 735;
$catname = "上证B股";
return 1;
break;
}
return 0;
}
function setTypeSZ($code,&$pid,&$catid,&$catname){
$str = substr($code,0,2);
switch ($str){
case '00':
$pid = 732;
$catid = 749;
$catname = "深证A股";
return 1;
break;
case '10':
$pid = 753;
$str = substr($code,0,3);
if($str == "108"){
$catid = 755;
$catname = "深证贴债";
return 1;
}else if($str == "109"){
$catid = 756;
$catname = "深证地债";
return 1;
}
$catid = 754;
$catname = "深证国债";
return 1;
break;
case '11':
$pid = 732;
$catid = 757;
$catname = "企业债";
return 1;
break;
case '12':
$pid = 732;
$catid = 758;
$catname = "深证转债";
return 1;
break;
case '13':
$pid = 732;
$catid = 759;
$catname = "深证回购";
return 1;
break;
case '15':
$pid = 732;
if($code == "159922"){
$catid = 761;
$catname = "深证LOF";
return 1;
}
$str = substr($code,0,3);
if($str == "159"){
$catid = 760;
$catname = "ETF基金";
return 1;
}
$catid = 752;
$catname = "深证基金";
return 1;
break;
case '16':
$pid = 732;
$catid = 761;
$catname = "深证LOF";
return 1;
break;
case '18':
$pid = 732;
$catid = 752;
$catname = "深证基金";
return 1;
break;
case '20':
$pid = 732;
$catid = 751;
$catname = "深证B股";
return 1;
break;
case '30':
$pid = 749;
$catid = 750;
$catname = "创业板";
return 1;
break;
case '39':
$pid = 732;
$catid = 748;
$catname = "深证指数";
return 1;
break;
}
return 0;
}
function myReadFile(&$dbObj,&$cacaheObj,$configs){
$lasttime="";
if(file_exists($configs['tmpSjPath'])) {
$lasttime = file_get_contents($configs['tmpSjPath']);
}
if($lasttime == date('Y-m-d')){
exit();
}
$sql = "";
$rt = -1;
$codestr = "";
$fields = array();
if(!file_exists($configs['dbfname'])) {
exit();//文件不存在
}
$fdbf = fopen($configs['dbfname'], 'r');
$buf = fread($fdbf, 32);
$header = unpack("VRecordCount/vFirstRecord/vRecordLength",substr($buf, 4, 8));
$goon = true;
$unpackString = '';
while ($goon && ! feof($fdbf)) { // read fields:
$buf = fread($fdbf, 32);
if (substr($buf, 0, 1) == chr(13)) {
$goon = false;
}else { // end of field list
$field = unpack(
"a11fieldname/A1fieldtype/Voffset/Cfieldlen/Cfielddec",
substr($buf, 0, 18));
//echo 'Field: ' . json_encode($field) . '<br/>';
$unpackString .= "A$field[fieldlen]$field[fieldname]/";
array_push($fields, $field);
}
}
fseek($fdbf, $header['FirstRecord'] + 1); // move back to the start of the
// first record (after the field definitions)
for ($i = 1; $i <= $header['RecordCount']; $i ++) {
$buf = fread($fdbf, $header['RecordLength']);
$record = unpack($unpackString, $buf);
if(!isset($record[$configs['key']])){
continue;
}
if($record[$configs['key']] == '000000'){
$sfm = trim($record[$configs['time']]);
if(strlen($sfm) == 5){
$sfm = "0".$sfm;
}
$tmpLasttime = date("Y-m-d H:i:s",strtotime($record[$configs['date']].$sfm));
if($lasttime != "" && $tmpLasttime < date("Y-m-d").' 09:25:00'){
fclose($fdbf);//没有新数据,结束流程
exit();
}
file_put_contents($configs['tmpSjPath'],date('Y-m-d'));
}else{
$code = $record[$configs['key']];
$code = trim($code);
$code = iconv ('GBK','UTF-8//IGNORE', $code);
$name = $record[$configs['name']];
$name = preg_replace("/ /si","",$name);
$name = iconv ('GBK','UTF-8//IGNORE', $name);
$name = preg_replace("/A/si","A",$name);
$name = preg_replace("/B/si","B",$name);
$name = trim($name);
$phonetic = converHzToSP($name);
$type = "";
$catid = 0;
$catname = "";
$pid=0;
$func = "setType".$configs['market'];
$tmpRt = $func($code,$pid,$catid,$catname);
if($tmpRt == 0){
continue;
}
$sql .= "('".$code."','".$name."','".$configs['market']."','".$phonetic."','".$pid."','".$catid."','".$catname."'),";
$codestr .= "'".$code."',";
}
}
fclose($fdbf);
if($sql != ""){
$sql = "INSERT INTO ".$configs['tbname']."(`code`,`name`,`market`,`phonetic`,`pid`,`catid`,`catname`) VALUES ".$sql;
$sqls = array("DELETE FROM ".$configs['tbname']." WHERE market='".$configs['market']
. "' AND code IN (".rtrim($codestr,',').")",rtrim($sql,','));
$rt = $dbObj->execute ($sqls);
}
return $rt;
}
/*****************************处理dbf文件 结束***********************************/
$lastPath = dirname(__FILE__);//上一级目录的绝对路径
if(isset($argv[1])){
$dbfname = $argv[1];
}else{
exit(1);//参数不存在
}
$cacheConfigs = array(
'CACHE_MEMCACHE' => array(
array('192.168.1.101', 11211),
),
);
$dbConfigs = array(
'DB_TYPE'=>'mysql',
'DB_HOST'=>'192.168.1.101',
'DB_NAME'=>'db_hq',
'DB_USER'=>'cc',
'DB_PWD'=>'123456',
'DB_CHARSET'=>'UTF8',
);
$cacaheObj = new Memcache();
foreach($cacheConfigs['CACHE_MEMCACHE'] as $v){
$cacaheObj->addServer($v[0],$v[1]);
}
$configs=array();
$configs['dbfname'] = $dbfname;
$configs['tbname'] = "code";
if(strpos($dbfname,"show2003.") !== false){
$configs['key'] = "S1";
$configs['date'] = "S6";
$configs['time'] = "S2";
$configs['name'] = 'S2';
$configs['market'] = 'SH';
}else if(strpos($dbfname,"SJSHQ.") !== false){
$configs['key'] = "HQZQDM";
$configs['date'] = "HQZQJC";
$configs['time'] = "HQCJBS";
$configs['name'] = 'HQZQJC';
$configs['market'] = "SZ";
}
if(!isset($configs['market'])){
exit();
}else{
$configs['tmpSjPath'] = $lastPath."/tmp_".$configs['tbname'].$configs['market']."_sj.txt";
}
$dbObj = new mysql($dbConfigs);
$b=microtime(true);
$rt = myReadFile($dbObj,$cacaheObj,$configs);
$c = microtime(true);
echo $configs['tbname'].(number_format(($b-$a), 10, '.',''))."s"."|".(number_format(($c-$b), 10, '.',''))."s"."|".(number_format(($c-$a), 10, '.',''))."s"."--".$rt.chr(10);
?>
/*******************************以下是创建表的sql语句*****************************************/
/*
SQLyog Enterprise - MySQL GUI v8.1
MySQL - 5.5.20-log : Database - hq_db
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;
/*!40101 SET SQL_MODE=''*/;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`hq_db` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `hq_db`;
/*Table structure for table `hq_kx` */
DROP TABLE IF EXISTS `hq_kx`;
CREATE TABLE `hq_kx` (
`code` VARCHAR(20) NOT NULL COMMENT '代码',
`name` VARCHAR(50) DEFAULT NULL COMMENT '名称',
`market` VARCHAR(10) NOT NULL COMMENT '代码类型(SZ,SH)',
`f0` DATE NOT NULL COMMENT '交易日期',
`f1` DECIMAL(18,4) DEFAULT NULL COMMENT '昨收',
`f2` DECIMAL(18,4) DEFAULT NULL COMMENT '开盘',
`f3` DECIMAL(18,4) DEFAULT NULL COMMENT '最高',
`f4` DECIMAL(18,4) DEFAULT NULL COMMENT '最低',
`f5` DECIMAL(18,4) DEFAULT NULL COMMENT '收盘',
`f6` DECIMAL(22,4) DEFAULT NULL COMMENT '成交量',
`f7` DECIMAL(22,4) DEFAULT NULL COMMENT '成交额',
`tstamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '时间戳',
PRIMARY KEY (`code`,`market`,`f0`),
KEY `code` (`code`),
KEY `f0` (`f0`),
KEY `market` (`market`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC COMMENT='和讯_行情_k线(日)';
/*Table structure for table `sh_hq` */
DROP TABLE IF EXISTS `sh_hq`;
CREATE TABLE `sh_hq` (
`code` CHAR(6) NOT NULL COMMENT '代码',
`name` VARCHAR(50) DEFAULT NULL COMMENT '名称',
`f0` DATETIME NOT NULL COMMENT '日期时间',
`f1` DECIMAL(22,4) DEFAULT NULL COMMENT 'S3|前收盘价格|前收盘指数',
`f2` DECIMAL(22,4) DEFAULT NULL COMMENT 'S4|今开盘价格|今开盘指数',
`f3` DECIMAL(22,4) DEFAULT NULL COMMENT 'S5|今成交金额|参与计算相应指数的成交金额',
`f4` DECIMAL(22,4) DEFAULT NULL COMMENT 'S6|最高价|最高指数',
`f5` DECIMAL(22,4) DEFAULT NULL COMMENT 'S7|最低价|最低指数',
`f6` DECIMAL(22,4) DEFAULT NULL COMMENT 'S8|最新价|最新指数',
`f7` DECIMAL(22,4) DEFAULT NULL COMMENT 'S9|当前买入价',
`f8` DECIMAL(22,4) DEFAULT NULL COMMENT 'S10|当前卖出价',
`f9` DECIMAL(22,4) DEFAULT NULL COMMENT 'S11|成交数量|参与计算相应指数的交易数量',
`f10` DECIMAL(22,4) DEFAULT NULL COMMENT 'S13|市盈率',
`f11` DECIMAL(22,4) DEFAULT NULL COMMENT 'S15|申买量一',
`f12` DECIMAL(22,4) DEFAULT NULL COMMENT 'S16|申买价二',
`f13` DECIMAL(22,4) DEFAULT NULL COMMENT 'S17|申买量二',
`f14` DECIMAL(22,4) DEFAULT NULL COMMENT 'S18|申买价三',
`f15` DECIMAL(22,4) DEFAULT NULL COMMENT 'S19|申买量三',
`f16` DECIMAL(22,4) DEFAULT NULL COMMENT 'S21|申卖量一',
`f17` DECIMAL(22,4) DEFAULT NULL COMMENT 'S22|申卖价二',
`f18` DECIMAL(22,4) DEFAULT NULL COMMENT 'S23|申卖量二',
`f19` DECIMAL(22,4) DEFAULT NULL COMMENT 'S24|申卖价三',
`f20` DECIMAL(22,4) DEFAULT NULL COMMENT 'S25|申卖量三',
`f21` DECIMAL(22,4) DEFAULT NULL COMMENT 'S26|申买价四',
`f22` DECIMAL(22,4) DEFAULT NULL COMMENT 'S27|申买量四',
`f23` DECIMAL(22,4) DEFAULT NULL COMMENT 'S28|申买价五',
`f24` DECIMAL(22,4) DEFAULT NULL COMMENT 'S29|申买量五',
`f25` DECIMAL(22,4) DEFAULT NULL COMMENT 'S30|申卖价四',
`f26` DECIMAL(22,4) DEFAULT NULL COMMENT 'S31|申卖量四',
`f27` DECIMAL(22,4) DEFAULT NULL COMMENT 'S32|申卖价五',
`f28` DECIMAL(22,4) DEFAULT NULL COMMENT 'S33|申卖量五',
`tstamp` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '数据时间',
PRIMARY KEY (`code`,`f0`),
KEY `code` (`code`),
KEY `name` (`name`),
KEY `tstamp` (`tstamp`),
KEY `f0` (`f0`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT='行情->上海show2003.dbf';
/*Table structure for table `sz_hq` */
DROP TABLE IF EXISTS `sz_hq`;
CREATE TABLE `sz_hq` (
`code` CHAR(6) NOT NULL COMMENT 'HQZQDM|证券代码',
`name` VARCHAR(50) DEFAULT NULL COMMENT 'HQZQJC|证券简称',
`f0` DATETIME NOT NULL COMMENT '日期时间',
`f1` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQZRSP|昨日收盘价',
`f2` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQJRKP|今日开盘价',
`f3` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQZJCJ|最近成交价',
`f4` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQCJSL|成交数量',
`f5` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQCJJE|成交金额',
`f6` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQCJBS|成交笔数',
`f7` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQZGCJ|最高成交价',
`f8` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQZDCJ|最低成交价',
`f9` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQSYL1|市盈率1',
`f10` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQSYL2|市盈率2',
`f11` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQJSD1|价格升跌1',
`f12` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQJSD2|价格升跌2',
`f13` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQHYCC|合约持仓量',
`f14` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQSJW5|卖价位五',
`f15` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQSSL5|卖数量五',
`f16` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQSJW4|卖价位四',
`f17` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQSSL4|卖数量四',
`f18` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQSJW3|卖价位三',
`f19` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQSSL3|卖数量三',
`f20` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQSJW2|卖价位二',
`f21` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQSSL2|卖数量二',
`f22` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQSJW1|卖价位一/叫卖揭示价',
`f23` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQSSL1|卖数量一',
`f24` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQBJW1|买价位一/叫买揭示价',
`f25` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQBSL1|买数量一',
`f26` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQBJW2|买价位二',
`f27` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQBSL2|买数量二',
`f28` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQBJW3|买价位三',
`f29` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQBSL3|买数量三',
`f30` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQBJW4|买价位四',
`f31` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQBSL4|买数量四',
`f32` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQBJW5|买价位五',
`f33` DECIMAL(22,4) DEFAULT NULL COMMENT 'HQBSL5|买数量五',
`tstamp` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '数据时间',
PRIMARY KEY (`code`,`f0`),
KEY `code` (`code`),
KEY `name` (`name`),
KEY `tstamp` (`tstamp`),
KEY `f0` (`f0`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT='行情->深圳SJSHQ.DBF';
/*Table structure for table `sz_xx` */
DROP TABLE IF EXISTS `sz_xx`;
CREATE TABLE `sz_xx` (
`code` CHAR(6) NOT NULL COMMENT 'XXZQDM|证券代码',
`name` VARCHAR(50) DEFAULT NULL COMMENT 'XXZQJC|证券简称',
`f0` DATETIME NOT NULL COMMENT '日期时间',
`f1` VARCHAR(50) DEFAULT NULL COMMENT 'XXYWJC|英文简称',
`f2` DECIMAL(8,0) DEFAULT NULL COMMENT 'XXJYDW|交易单位',
`f3` VARCHAR(10) DEFAULT NULL COMMENT 'XXHYZL|行业种类',
`f4` CHAR(2) DEFAULT NULL COMMENT 'XXHBZL|货币种类',
`f5` DECIMAL(14,4) DEFAULT NULL COMMENT 'XXMGMZ|每股面值',
`f6` DECIMAL(22,0) DEFAULT NULL COMMENT 'XXZFXL|总发行量',
`f7` DECIMAL(22,0) DEFAULT NULL COMMENT 'XXLTGS|流通股数',
`f8` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXSNLR|上年每股利润',
`f9` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXBNLR|本年每股利润',
`f10` DECIMAL(8,6) DEFAULT NULL COMMENT 'XXJSFL|经手费率|按成交金额计算',
`f11` DECIMAL(8,6) DEFAULT NULL COMMENT 'XXYHSL|印花税率|按成交金额计算',
`f12` DECIMAL(8,6) DEFAULT NULL COMMENT 'XXGHFL|过户费率',
`f13` DATE DEFAULT NULL COMMENT 'XXSSRQ|上市日期|CCYYMMDD',
`f14` DATE DEFAULT NULL COMMENT 'XXDJRQ|到期/交割日|CCYYMMDD',
`f15` DECIMAL(14,0) DEFAULT NULL COMMENT 'XXMBXL|每笔限量',
`f16` DECIMAL(10,0) DEFAULT NULL COMMENT 'XXBLDW|买数量单位',
`f17` DECIMAL(10,0) DEFAULT NULL COMMENT 'XXSLDW|卖数量单位',
`f18` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXJGDW|价格档位',
`f19` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXJHCS|集合竞价限价参数',
`f20` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXLXCS|连续竞价限价参数',
`f21` CHAR(1) DEFAULT NULL COMMENT 'XXXJXZ|限价参数性质',
`f22` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXZTJG|涨停价格',
`f23` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXDTJG|跌停价格',
`f24` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXZHBL|折合比例',
`f25` CHAR(1) DEFAULT NULL COMMENT 'XXJYZT|交易状态',
`f26` CHAR(1) DEFAULT NULL COMMENT 'XXZQJB|证券级别',
`f27` CHAR(1) DEFAULT NULL COMMENT 'XXTPBZ|停牌标志',
`f28` CHAR(1) DEFAULT NULL COMMENT 'XXCQCX|除权除息标志',
`f29` CHAR(1) DEFAULT NULL COMMENT 'XXCFBZ|成份股标志',
`tstamp` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '数据时间',
PRIMARY KEY (`code`,`f0`),
KEY `code` (`code`),
KEY `name` (`name`),
KEY `tstamp` (`tstamp`),
KEY `f0` (`f0`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT='行情->深圳信息SJSXX.DBF';
/*Table structure for table `sz_xxn` */
DROP TABLE IF EXISTS `sz_xxn`;
CREATE TABLE `sz_xxn` (
`code` CHAR(6) NOT NULL COMMENT 'XXZQDM|证券代码',
`name` VARCHAR(50) DEFAULT NULL COMMENT 'XXZQJC|证券简称',
`f0` DATETIME NOT NULL COMMENT '日期时间',
`f1` CHAR(4) DEFAULT NULL COMMENT 'XXJCQZ|证券简称前缀',
`f2` VARCHAR(50) DEFAULT NULL COMMENT 'XXYWJC|英文简称',
`f3` CHAR(6) DEFAULT NULL COMMENT 'XXJCZQ|基础证券',
`f4` VARCHAR(50) DEFAULT NULL COMMENT 'XXISIN|ISIN|编码',
`f5` VARCHAR(10) DEFAULT NULL COMMENT 'XXHYZL|行业种类',
`f6` CHAR(2) DEFAULT NULL COMMENT 'XXHBZL|货币种类',
`f7` DECIMAL(14,4) DEFAULT NULL COMMENT 'XXMGMZ|每股面值',
`f8` DECIMAL(22,0) DEFAULT NULL COMMENT 'XXZFXL|总发行量',
`f9` DECIMAL(22,0) DEFAULT NULL COMMENT 'XXLTGS|流通股数',
`f10` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXSNLR|上年每股利润',
`f11` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXBNLR|本年每股利润',
`f12` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXLJJZ|基金份额累计净值',
`f13` DECIMAL(8,6) DEFAULT NULL COMMENT 'XXJSFL|经手费率|按成交金额计算',
`f14` DECIMAL(8,6) DEFAULT NULL COMMENT 'XXYHSL|印花税率|按成交金额计算',
`f15` DECIMAL(8,6) DEFAULT NULL COMMENT 'XXGHFL|过户费率',
`f16` DATE DEFAULT NULL COMMENT 'XXSSRQ|上市日期|CCYYMMDD',
`f17` DATE DEFAULT NULL COMMENT 'XXQXRQ|债券起息日|CCYYMMDD',
`f18` DATE DEFAULT NULL COMMENT 'XXDJRQ|到期/交割日|CCYYMMDD',
`f19` DECIMAL(8,0) DEFAULT NULL COMMENT 'XXJYDW|交易单位',
`f20` DECIMAL(10,0) DEFAULT NULL COMMENT 'XXBLDW|买数量单位',
`f21` DECIMAL(10,0) DEFAULT NULL COMMENT 'XXSLDW|卖数量单位',
`f22` DECIMAL(10,0) DEFAULT NULL COMMENT 'XXMBXL|每笔委托限量',
`f23` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXJGDW|价格档位',
`f24` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXJHCS|集合竞价限价参数',
`f25` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXLXCS|连续竞价限价参数',
`f26` CHAR(1) DEFAULT NULL COMMENT 'XXXJXZ|限价参数性质',
`f27` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXZTJG|涨停价格',
`f28` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXDTJG|跌停价格',
`f29` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXJGSX|大宗交易价格上限2',
`f30` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXJGXX|大宗交易价格下限2',
`f31` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXZHBL|债券折合比例',
`f32` DECIMAL(10,4) DEFAULT NULL COMMENT 'XXDBZSL|担保物折算率',
`f33` CHAR(1) DEFAULT NULL COMMENT 'XXRZBD|融资标的标志',
`f34` CHAR(1) DEFAULT NULL COMMENT 'XXRQBD|融券标的标志',
`f35` CHAR(1) DEFAULT NULL COMMENT 'XXCFBZ|成份股标志',
`f36` CHAR(1) DEFAULT NULL COMMENT 'XXZSBZ|做市商标志',
`f37` CHAR(2) DEFAULT NULL COMMENT 'XXSCDM|所属市场代码|预留',
`f38` CHAR(4) DEFAULT NULL COMMENT 'XXZQLB|证券类别|CFICode,预留',
`f39` CHAR(1) DEFAULT NULL COMMENT 'XXZQJB|证券级别',
`f40` CHAR(1) DEFAULT NULL COMMENT 'XXZQZT|证券状态',
`f41` CHAR(1) DEFAULT NULL COMMENT 'XXJYLX|交易类型',
`f42` CHAR(1) DEFAULT NULL COMMENT 'XXJYJD|产品交易阶段',
`f43` CHAR(1) DEFAULT NULL COMMENT 'XXTPBZ|暂停交易标志',
`f44` CHAR(1) DEFAULT NULL COMMENT 'XXRZZT|融资交易状态',
`f45` CHAR(1) DEFAULT NULL COMMENT 'XXRQZT|融券交易状态',
`f46` CHAR(1) DEFAULT NULL COMMENT 'XXRQJX|融券卖出价格限制',
`f47` CHAR(1) DEFAULT NULL COMMENT 'XXWLTP|网络投票标志',
`f48` CHAR(1) DEFAULT NULL COMMENT 'XXYWZT|其他业务状态',
`f49` CHAR(6) DEFAULT NULL COMMENT 'XXGXSJ|记录更新时间|HHMMSS',
`f50` VARCHAR(12) DEFAULT NULL COMMENT 'XXMARK|备用字段|预留',
`f51` CHAR(1) DEFAULT NULL COMMENT 'XXBYBZ|备用标志|券商系统自用',
`tstamp` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '数据时间',
PRIMARY KEY (`code`,`f0`),
KEY `code` (`code`),
KEY `name` (`name`),
KEY `tstamp` (`tstamp`),
KEY `f0` (`f0`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT='行情->深圳信息N(SJSXXN.DBF)';
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/************************************以下是inotify 监控脚本************************************************/
vim myinotifywait.sh
#!/bin/bash
dir="/dbf_hq"
inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f %e' --event CLOSE_WRITE,create,move,delete $dir | while read date time file event
do
##echo $event'-'$file
case $event in MOVED_TO)
##echo "$file"
if [ "${file: -4}" != '4913' ] && [ "${file: -1}" != '~' ]; then
hz=${file##*.}
if [ "$hz" == "DBF" ] || [ "$hz" == "dbf" ]; then
##echo "$file"
##filename=`${file%.*}`
nohup /opt/webserver/php/bin/php -f /dbf/hq.php $file > /tmp/hq.log 2>&1 &
nohup /opt/webserver/php/bin/php -f /dbf/dbf_code.php $file > /tmp/dbf_code.log 2>&1 &
##nohup /opt/webserver/php/bin/php -f /dbf/hq_rkx.php $file > /tmp/hq_rkx.log 2>&1 &
##echo "filename: ${file%.*}"
##echo "extension: $hz"
fi
fi
;;
esac
done
PS:缺陷:获取中文首字母的方法,对一些特殊的中文获取不到首字母,待解决中...