python 同花順和雪球同步

2022-09-24 06:15:10 字數 4442 閱讀 5435

import re

import time

from pprint import pprint

import pandas as pd

import requests

class snowball:

xq = ''

# 雪球自選股列表相關json

url =

# 預設cookie

df_cookie = ('s=××××××; '

'xq_a_token=×××××××××××××××××××××; '

'xq_r_token=×××××××××××××××××××××; '

)def __init__(self, uid, cookie=df_cookie):

self.uid = uid # 使用者頁面如 /×××××××××

self.cookie = cookie # 操作列表需要該使用者登入的cookie

self.headers =

self.stocks = pd.dataframe() # 雪球自選股清單

def get_stocks(self):

# 獲取雪球自選股列表

try:

payload =

response = requests.get(snowball.url['get'], params=payload, headers=self.headers, timeout=10)

# pprint(response.content)

self.stocks = pd.dataframe(response.json()['stocks'])

except exception, e:

print 'get_stocks @', self.uid, '; error:', e

pprint(payload)

pprint(self.headers)

return false

else:

# pprint(self.stocks)

return self.stocks

def del_stock(self, code):

# 在雪球刪除指定**的**

try:

payload =

response = requests.post(snowball.url['del'], data=payload, headers=self.headers, timeout=10)

# pprint(response.content)

response = response.json()['success']

if response == true:

print 'del_stock', code, 'success.'

else:

print 'del_stock', code, 'failed.'

except exception, e:

print 'del_stock', code, '@', self.uid, '; error:', e

pprint(payload)

pprint(self.headers)

return false

else:

self.get_stocks()

return response

def add_stock(self, code):

# 在雪球新增指定**的**

try:

payload =

response = requests.post(snowball.url['add'], data=payload, headers=self.headers, timeout=10)

# pprint(response.content)

response = response.json()['success']

if response == true:

print 'add_stock', code, 'success.'

else:

print 'add_stock', code, 'failed.'

except exception, e:

print 'add_stock', code, '@', self.uid, '; error:', e

pprint(payload)

pprint(self.headers)

return false

else:

self.get_stocks()

return response

def modify_stocks(self, code_list=):

# 雪球自選股列表排序

try:

payload =

response = requests.post(snowball.url['modify'], data=payload, headers=self.headers, timeout=10)

# pprint(response.content)

response = response.json()['success']

if response == true:

print 'modify_stocks', code_list, 'success.'

else:

print 'modify_stocks', code_list, 'failed.'

except exception, e:

print 'modify_stocks', code_list, '@', self.uid, '; error:', e

pprint(payload)

pprint(self.headers)

return false

else:

self.get_stocks()

return response

class tonghuashun:

# 同花順自選股列表相關

url =

def __init__(self, uid, cookie):

self.uid = uid

self.cookie = cookie # 該使用者登入的cookie

self.headers =

self.stocks = pd.dataframe() # 同花順自選股清單

def get_stocks(self):

# 獲取同花順自選股列表

try:

payload =

response = requests.get(tonghuashun.url['get'], params=payload, headers=self.headers, timeout=10)

# pprint(response.content)

self.stocks = pd.dataframe(response.json())

except exception, e:

print 'get_stocks @', self.uid, '; error:', e

pprint(payload)

pprint(self.headers)

return false

else:

# pprint(self.stocks)

return self.stocks

def modify_stock(self, code, method, pos='1'):

# 更改同花順自選股列表

# method: add 新增, del 刪除, exc 排序

# pos: 排序用的序號, 從1開始

try:

payload = ,

'del': ,

'exc':

}# self.get_stocks()

response = requests.get(tonghuashun.url['modify'], params=payload[method], headers=self.headers, timeout=10)

# pprint(response.content)

response = response.content.decode('gbk')

print 'modify_stocks', method, pos, code, response

if response == u'修改自選股成功':

response = true

except exception, e:

print 'modify_stock', method, code, '@', self.uid, '; error:', e

pprint(payload[method])

pprint(self.headers)

return false

else:

self.get_stocks()

return response

同花順公式轉python 同花順公式轉通達信,謝謝

drawtext 賣出條件andd2 93andd2 97,high 1.13,賺95 coloryellow drawtext 賣出條件andd2 97andd2 100,high 1.13,賺99 coloryellow drawtext 賣出條件andd2 100,high drawtext ...

滾雪球學 Python 之 lambda 表示式

橡皮擦,乙個逗趣的網際網路高階網蟲,新的系列,讓我們一起be more pythonic。五 lambda 表示式 滾雪球學 python 第二輪開啟,高階之路,列表與元組那些事兒 說完列表說字典,說完字典說集合,滾雪球學 python 關於 python 中的字串,我在補充兩點,滾雪球學 pyth...

python同步執行 在python中同步執行迴圈

我有一段 可以爬行到乙個無限高度的 如facebook 我需要頁面等待頁面首先載入然後繼續,但是我這樣做失敗.以下是我到目前為止嘗試過的事情.如下 while int number of news int len news driver.execute script window.scrollto ...