Mysql0.py

# py1.py
# -*- coding: utf-8 -*-
import sqlalchemy
import tushare
import pandas
import socket
import struct

class Mysql0:

    def __init__(self, user0=‘test‘, password0=‘123456‘, dsn0=‘odbcdsn‘, host0=‘192.168.1.3‘, port0=12345):
        self.user0 = user0
        self.password0 = password0
        self.dsn0 = dsn0
        self.engine0 = sqlalchemy.create_engine(‘mysql+pyodbc://‘+self.user0+‘:‘+self.password0+‘@‘+self.dsn0)
        self.host0 = host0
        self.port0 = port0

    def get_url_data0(self):
        codelist0 = pandas.DataFrame((tushare.get_today_all())[‘code‘])
        codelist0 = codelist0.sort(columns=‘code‘, ascending=True)
        codelist0[‘index‘] = pandas.DataFrame([i for i in range(0, len(codelist0))], codelist0.index)
        codelist0.to_sql(‘codelist‘, self.engine0, if_exists=‘replace‘, index=True, index_label=‘index‘)
        for i in range(0, len(codelist0)):
            stockdata0 = tushare.get_h_data(codelist0[‘code‘][i])
            stockdata0[‘date‘] = pandas.Series(stockdata0.index, stockdata0.index)
            stockdata0 = stockdata0.sort_values(by=‘date‘, ascending=True)
            stockdata0[‘index‘] = pandas.DataFrame([i for i in range(0, len(stockdata0))], stockdata0.index)
            stockdata0.to_sql(codelist0[‘code‘][i], self.engine0, if_exists=‘replace‘, index=True, index_label=‘index‘)

    def get_sql_data0(self, code0=‘sh‘):
        stockdata1 = pandas.read_sql_table(code0, self.engine0)
        return code0, stockdata1

    def run_socket_server0(self):
        socket0 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        socket0.bind((self.host0, self.port0))
        socket0.listen(5)
        code1, stockdata2 = self.get_sql_data0()
        i0 = stockdata2[‘index‘]
        o0 = stockdata2[‘open‘]
        h0 = stockdata2[‘high‘]
        l0 = stockdata2[‘low‘]
        c0 = stockdata2[‘close‘]
        v0 = stockdata2[‘volume‘]
        i = 0
        while True:
            connection0, address0 = socket0.accept()
            if connection0.recv(1024) == b‘connect‘ and i < len(i0):
                connection0.send(struct.pack(‘6si5f‘, code1.encode(‘utf-8‘), i0[i], o0[i], h0[i], l0[i], c0[i], v0[i]))
                i += 1
            else:
                connection0.close()
                socket0.close()

    def run_socket_client0(self, message0=b‘connect‘):
        socket1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        socket1.connect((self.host0, self.port0))
        socket1.send(message0)
        code2, i1, i1, h1, l1, c1, v1 = struct.unpack(‘6si5f‘, socket1.recv(1024)[:32])
        socket1.close()
        return code2.decode(‘utf-8‘), i1, i1, h1, l1, c1, v1
# py2.py
import sys
sys.path.append(‘D:\360data\MyWorkSpace1‘)
import py1
Py1 = py1.Mysql0()
Py1.get_url_data0()
print(‘finished!‘)
时间: 2024-10-17 05:43:34

Mysql0.py的相关文章

使用TDD理解views.py与urls.py的关系

首先必须对MVC的概念有初步的认识,django也遵循这样一套规范,views.py相当于视图函数,是整个架构中的处理引擎,而urls.py的作用就是将用户请求送入这样的引擎. 项目结构: urls.py: from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ # Examples: #url(r'^$', 'mysite.views.home', name='home

layers.py cs231n

如果有错误,欢迎指出,不胜感激. import numpy as np def affine_forward(x, w, b): 第一个最简单的 affine_forward简单的前向传递,返回 out,cache """ Computes the forward pass for an affine (fully-connected) layer. The input x has shape (N, d_1, ..., d_k) and contains a minibat

Python pydoc.py

1. 查看帮助,我们可以在python命令行交互环境下用 help函数,比如: 查看 math 模块: >>> help('math')Help on built-in module math: NAME math DESCRIPTION This module is always available. It provides access to the mathematical functions defined by the C standard. FUNCTIONS acos(..

创建py模板

创建模板之后,每次新建py文件,已初始定义的代码段将会自动出现在py文件中.

python下编译py成pyc和pyo

其实很简单,用python -m py_compile file.py python -m py_compile /root/src/{file1,file2}.py编译成pyc文件.也可以写份脚本来做这事:Code: import py_compile py_compile.compile('path') //path是包括.py文件名的路径 用python -O -m py_compile file.py 编译成pyo文件.1.其中的 -m 相当于脚本中的import,这里的-m py_co

django 运行python manage.py sqlall books 时报错 app has migration

出现这个问题的原因是版本之前的不兼容,我用的django版本是1.8.6 而 这条python manage.py sqlall books 是基于django1.0版本的. 在django1.8.6版本中生成一个表的语句是    $ python manage.py makemigrations books $ python manage.py sqlmigrate books 0001 django book2 是一本不错的教程,但是就是版本太老了,可以通过看book2对django有一个比

word2vec_basic.py

ssh://[email protected]:22/usr/bin/python3 -u /home/win_pymine_clean/feature_wifi/word2vec_basic.py Found and verified text8.zip Data size 17005207 Most common words (+UNK) [['UNK', 418391], ('the', 1061396), ('of', 593677), ('and', 416629), ('one',

如何在Windows下用cpu模式跑通py-faster-rcnn 的demo.py

关键字:Windows.cpu模式.Python.faster-rcnn.demo.py 声明:本篇blog暂时未经二次实践验证,主要以本人第一次配置过程的经验写成.计划在7月底回家去电脑城借台机子试试验证步骤的正确性,本blog将根据实际遇到的问题持续更新.另外blog中除提到的下载链接外我还会给出网盘链接方便下载,包括我的整个工程的网盘链接.如果有些报错解决不了可直接拿本人的相关文件替换,本篇blog具有较高的参考性. 本人微软版caffe工程     下载链接:http://pan.bai

pyinstaller对py脚本进行打包(生成windows可执行程序)

这个没有什么截图,主要步骤如下: a. 安装python-2.7-x64版本(我的系统是win7-x64) b. 下载PyInstaller-2.1 x64版本 c. 下载pywin32-x64版本 d.下载upx.exe (这个在pyinstall官网上面会有提示) e.使用pythone setup.py install 安装pyinstaller 一般我们是生成单文件的exe,方便可以在其他windows机器上可执行. 生成的命令是: python pyinstaller.py  -F