标签:
f1.py
# -*- coding: utf-8 -*- import socket import struct import sqlalchemy import pandas ######################################################################## class Socket: #---------------------------------------------------------------------- def __init__(self, Host = ‘192.168.1.3‘, Port = 12345): self.Host = Host self.Port = Port #---------------------------------------------------------------------- def Run_server(self): Socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) Socket.bind((self.Host, self.Port)) Socket.listen(5) Engine = sqlalchemy.create_engine(‘mssql+pyodbc://sa:123456@XiTongDSN‘) ‘‘‘修改1‘‘‘ Dataframe = pandas.read_sql(‘sh‘, Engine) Index = list(Dataframe[‘date‘].index) Close = Dataframe[‘close‘] Volume = Dataframe[‘volume‘] i = 0 while True: Connection, Address = Socket.accept() if Connection.recv(1024) == b‘Link‘ and i < len(Close): ‘‘‘修改2‘‘‘ Connection.send(struct.pack(‘iff‘, Index[i], Close[i], Volume[i])) i += 1 else: Connection.close() Socket.close() #---------------------------------------------------------------------- def Run_client(self, Message = b‘Link‘): Socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) Socket.connect((self.Host, self.Port)) Socket.send(Message) ‘‘‘修改3‘‘‘ Index, Close, Volume = struct.unpack(‘iff‘, Socket.recv(1024)[:12]) Socket.close() return Index, Close, Volume
f2.py
# -*- coding: utf-8 -*- import sys sys.path.append(‘C:\WinPython-32bit-3.5.1.3\myWorkSpace1‘) import f1 F1 = f1.Socket() F1.Run_server()
f3.py
# -*- coding: utf-8 -*- import f1 F1 = f1.Socket() import matplotlib.pylab as Plot ‘‘‘修改1‘‘‘ Sub1 = Plot.subplot(211) Sub2 = Plot.subplot(212) index = [] close = [] volume = [] while True: Index, Close, Volume = F1.Run_client() index.append(Index) close.append(Close) volume.append(Volume) if Index > 10: Sub1.plot(index[Index-10:Index-1:1], close[Index-10:Index-1:1]) Sub2.bar(index[Index-10:Index-1:1], volume[Index-10:Index-1:1]) Plot.pause(0.01)
自设变量,头文字大写!
标签:
原文地址:http://www.cnblogs.com/blog-3123958139/p/5551657.html