1 Star 1 Fork 0

Yekai2233/kapp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
boxtool.py 16.90 KB
一键复制 编辑 原始数据 按行查看 历史
Yekai2233 提交于 2022-01-09 23:09 . asdas
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
import json
from spider_nga.nga import stand_v2
from spider_nga.snowball import mian_do
from spider_xue.stocks import run, stock
from spider_xue.account import saveAccount, update_account
import random
import requests
import time
import numpy as np
import decimal
from spider_xue.settings import KEYS, URL5, COOKIES, ding_url1, ding_url0
from spider_xue.thread_file import mission_day_all_stock, mission_five
from spider_xue.utils import EMA, break_flag, get_record_datasad, get_record_histroy, get_record_histroy1, get_record_histroy2, get_record_histroy3, get_record_histroy4, reset_all_ip, send_msg, send_s_msg, get_record_histroy5
from db import *
from spider_xue.ip import headers_list, ip_obj
from spider_xue.new_ip import check_duplicate_ip, clean_db_ip, clean_db_txt_ip, clean_dirty_db_ip, new_ip_obj
from spider_xue.wx_push import send_info
from spider_xue.get_day import do_day, set_all_stock_tmp
def update_his(his, symbol, key):
his.update_one({"symbol": symbol}, {"$set": key}, upsert=True)
def set_five_history():
test_data = mydb['history_tmp'].find()
count = 0
for data in test_data:
item = data['item']
print(data['symbol'], count)
history = history_five_db.find_one({"symbol": data['symbol']})
if not history:
five_time_list = []
five_time_dict = {}
fifteen_time_list = []
fifteen_time_dict = {}
else:
five_time_list = history['five_time_list']
five_time_dict = history['five_time_dict']
fifteen_time_list = history.get('fifteen_time_list', [])
fifteen_time_dict = history.get('fifteen_time_dict', {})
r = len(item)
flag15, tmp15 = 0, 0
for i in range(r):
d = item[i]
tt = time.localtime(int(d[0] / 1000))
itt = time.strftime('%Y-%m-%d', tt)
set_value_five(five_time_list, five_time_dict, itt, data['symbol'], d[9])
if tt.tm_min in [5, 20, 35, 50]:
set_value_five(fifteen_time_list, fifteen_time_dict, itt, data['symbol'], tmp15)
flag15 = 3
tmp15 = 0
if flag15:
flag15 -= 1
tmp15 += d[9]
update_his(
history_five_db, data['symbol'],
{
"five_time_list": five_time_list,
"five_time_dict": five_time_dict,
"fifteen_time_list": fifteen_time_list,
"fifteen_time_dict": fifteen_time_dict,
}
)
def set_value_five(time_list, time_dict, itt, symbol, cal, ti=None, ttt=None):
if time_list:
if itt not in time_list:
if itt > time_list[-1]:
time_dict[itt] = cal
time_list.append(itt)
else:
send_msg("### 时间不对拉!!!尼玛 %s %s" % (itt, symbol))
else:
if time_dict[itt] < cal:
time_dict[itt] = cal
else:
time_dict[itt] = cal
time_list.append(itt)
def fix():
test_data = []
for x in ['SZ002515', 'SH603233']:
for i in range(50):
iip = new_ip_db.find_one()
try:
tttt = get_res(COOKIES, x, iip['ip'])
break
except:
new_ip_db.delete_many({"ip": iip['ip']})
print('fail....', iip['ip'])
test_data.append(tttt)
mydb['history_tmp'].insert_many(test_data)
set_five_history()
def get_res(cookie, symbol, ippp):
tt = str(int(time.time())) + "000"
ss = requests.Session()
proxies = {'http': f'http://{ippp}'}
ss.headers = {"user-agent": random.choice(headers_list), "cookie": cookie}
html = ss.get(URL5.format(symbol, tt, 1000), proxies=proxies, timeout=5)
if html.status_code != 200:
raise ValueError("not 200")
tempJson = html.json()
if not tempJson.get('data'):
raise ValueError('not data')
return tempJson.get('data')
def set_ip_count():
iipp = mydb['new_ip']
iipp.update_many({}, {"$set": {"status": 1, "count": 2}})
def get_name():
l = history_five_db.find()
for i in l:
f = stock_db.find_one({'symbol': i['symbol']})
history_five_db.update_one({'symbol': i['symbol']}, {"$set": {"name": f['name']}})
print(f['name'], i['symbol'])
def test_son_work_together_one_mintue():
# data = data_one_db.find({'symbol': 'SH600418'})
# f = stock_db.find({"use": 1})
f = stock_db.find({"use": 1})
for i in f:
# if 'thirty_time_list' not in i:
x = history_five_db.find_one({"symbol": i['symbol']})
if not x:
print(i['symbol'])
# count = 0
# for i in data:
# if i['item'][-1][0] < 1634003090000:
# print(i['symbol'])
# count += 1
# print(count)
# for i in data:
# son_work_together_one_mintue2(i, f, 1634088600)
def son_work_together_one_mintue2(x, stock, timestamp):
symbol = x['symbol']
item = x['item']
history = history_five_db.find_one({"symbol": symbol})
end_price = stock['end_price']
lol = (item[-1][5] - end_price) % end_price * 100
if lol > 7:
stock_tmp_db.update({"symbol": symbol}, {"$set": {"today": 0}}, upsert=True)
elif lol < -7:
stock_tmp_db.update({"symbol": symbol}, {"$set": {"today": 1}}, upsert=True)
five_time_list = history['five_time_list']
five_time_dict = history['five_time_dict']
five_max = int(five_time_dict[five_time_list[-1]])
fifteen_time_list = history.get('fifteen_time_list', [])
fifteen_time_dict = history.get('fifteen_time_dict', {})
fifteen_max = int(fifteen_time_dict[fifteen_time_list[-1]])
# thirty_time_list = history['thirty_time_list']
# thirty_time_dict = history['thirty_time_dict']
r = len(item)
msg_list = []
flag = False
count5= 0
for end_index in range(r-1, 0, -1):
if count5 > 0:
count5 -= 1
continue
ts = int(item[end_index][0] / 1000)
if ts < timestamp:
break
head_index = end_index - 4
tmp5 = 0
if item[end_index][5] - item[head_index][2] <= 0:
continue
for x in range(head_index, end_index+1):
tmp5 += item[x][9]
p = round(tmp5 / five_max, 2)
if p >= 2:
# query_find = record_db.find_one({"symbol": symbol, "ts": ts, 'type': 5})
# if not query_find:
# flag = True
# record_db.insert_one({"symbol": symbol, "ts": ts, 'vol': tmp5, "p": p, 'type': 5})
# else:
# break
if end_index + 5 >= r:
flag = True
count5 = 5
msg_list.append(f"{time.strftime('%H:%M', time.localtime(ts))}#{p}倍#5")
count15= 0
for end_index in range(r-1, 0, -1):
if count15 > 0:
count15 -= 1
continue
ts = int(item[end_index][0] / 1000)
if ts < timestamp:
break
head_index = end_index - 14
tmp5 = 0
if item[end_index][5] - item[head_index][2] < 0:
continue
for x in range(head_index, end_index+1):
tmp5 += item[x][9]
p = round(tmp5 / fifteen_max, 2)
if p >= 2:
# query_find = record_db.find_one({"symbol": symbol, "ts": ts, 'type': 15})
# if not query_find:
# flag = True
# record_db.insert_one({"symbol": symbol, "ts": ts, 'vol': tmp5, "p": p, 'type': 5})
# else:
# break
if end_index + 5 >= r:
flag = True
count15 = 7
msg_list.append(f"{time.strftime('%H:%M', time.localtime(ts))}#{p}倍#15")
if flag:
# msg_list = query_find = record_db.find({"symbol": symbol, "ts": {"$gte": NINE_TIME_STAMPi}})
msg = ''
for i in msg_list:
# msg = msg + "- " + f"{time.strftime('%H:%M', time.localtime(i['ts']))}#{i['p']}#{i['type']}" + '\n'
msg = msg + "- " + i + '\n'
if msg:
send_s_msg(symbol, msg, history['name'])
send_info(symbol, msg)
def aaa():
all = history_five_db.find()
for i in all:
a = i['five_time_list']
a1 = i['five_time_dict']
b = i['fifteen_time_list']
b1 = i['fifteen_time_dict']
c = i.get('thirty_time_list', [])
c1 = i.get('thirty_time_dict', {})
if "2021-10-26" in a1:
a1.pop('2021-10-26')
if "2021-10-26" in a:
a.remove("2021-10-26")
if "2021-10-26" in b1:
b1.pop('2021-10-26')
if "2021-10-26" in b:
b.remove("2021-10-26")
if "2021-10-26" in c1:
c1.pop('2021-10-26')
if "2021-10-26" in c:
c.remove("2021-10-26")
print(i['symbol'])
history_five_db.update({"symbol": i['symbol']},
{"$set":
{
"five_time_list": a,
"five_time_dict": a1,
"fifteen_time_list": b,
"fifteen_time_dict": b1,
"thirty_time_list": c,
"thirty_time_dict": c1,
}}, upsert=True)
def dd(sy="SZ002484", ts=1634607000):
f = record_db.find({"symbol": sy, "ts": {"$gte": ts}}).sort([('ts', 1)])
pp = {'symbol': sy}
p5 = []
t5 = []
p15 = []
t15 = []
pp5 = {}
pp15 = {}
for i in f:
if 'p5' in i:
# p5.append({i['ts']: i['p5']})
pp5[i['ts']] = i['p5']
# p5.append(i['p5'])
# t5.append(i['ts'])
if 'p15' in i:
# p15.append(i['p15'])
# t15.append(i['ts'])
# p15.append({i['ts']: i['p15']})
pp15[i['ts']] = i['p15']
pp['p5'] = p5
pp['t5'] = t5
pp['p15'] = p15
pp['t15'] = t15
pp['pp5'] = pp5
pp['pp15'] = pp15
print(pp)
def get_hot_ip_job():
count = settings_db.find_one({"count": 1})
end = new_ip_obj.get_req(int(count['end']))
print(end)
settings_db.update_one({"count": 1}, {"$set": {'end': end}}, upsert=True)
def setss():
all = stock_db.find({"use": 1}) # , 'symbol': 'SH600170'
for i in all:
d = data_day_db.find_one({"symbol": i["symbol"]})
set_all_stock_tmp(d, i, 1)
def seeet():
all = stock_db.find({"today": 7})
for i in all:
record_db.delete_many({"symbol": i["symbol"]})
def sendmsg():
stock = stock_db.find_one({"symbol": 'SH603722'})
send_s_msg(stock, '愚蠢的居居哟', ding_url0)
def set_all_stock_tmpxxx():
ff = stock_db.find({"use": 1})
count = 0
count1 = 0
count2 = 0
count3 = 0
for stock in ff:
# -4 195 467 802 1188
# -3 193 464 799 1185
# -2 185 454 789 1175
# -1 194 466 803 1188
x = data_day_db.find_one({"symbol": stock['symbol']})
item = x['item']
print(stock['symbol'])
last = item[-4]
if stock.get("use", 0):
if last[7] > -9:
msg = stock['gsjj'] + stock['hxtc'] + stock['jyfw']
f = 0
for k in KEYS:
if k in msg:
f = 1
break
if f:
dd = data_day_db.find_one({"symbol": x['symbol']})
ct = 0
ct2 = 0
ct3 = 0
ct4 = 0
for d in dd['item'][-10:]:
if d[7] <= 2:
ct += 1
if d[7] <= 1:
ct2 += 1
if d[7] <= 0.5:
ct3 += 1
if d[7] <= 0:
ct4 += 1
if ct < 7:
count += 1
if ct2 < 7:
count1 += 1
if ct3 < 7:
count2 += 1
if ct4 < 7:
count3 += 1
print(count, count1, count2, count3)
def check_tmp():
all_stocks = stock_db.find()
for i in all_stocks:
if not i.get('gsjj'):
print(i)
def get_record_data():
ts = settings_db.find_one({"name": "nine_timestamp"})['timestamp']
all = record_db.find({"ts": {"$gte": ts}})
kk = {}
for i in all:
i.pop("_id")
i['date'] = time.strftime('%Y-%m-%d %H:%M', time.localtime(i['ts']))
if i['symbol'] not in kk:
# print(i['symbol'])
kk[i['symbol']] = []
if len(kk[i['symbol']]) < 3:
xxx = stock_db.find_one({"symbol": i['symbol']})
i['name'] = xxx['name']
i['important'] = xxx['high']
kk[i['symbol']].append(i)
# print(i)
count = 0
count1 = 0
for k, v in kk.items():
if v[0]['date'] > '2021-11-10 09:40' and v[0]['date'] < '2021-11-10 11:40':
print(k)
count += 1
if v[0]['important']:
count1 +=1
for zz in v:
print(zz)
print(count, count1)
def fifteen_get_five():
fif = record_db.find({"p15": {"$gte": 2}, "ts": {"$gte": 1635696000}})
all_fif = []
for i in fif:
if i['symbol'] not in all_fif:
all_fif.append(i['symbol'])
five = record_db.find({"p5": {"$gte": 2}, 'ts': {"$gte": i['ts']}, 'symbol': i['symbol']}).sort([('ts', 1)])
ll = []
print(time.strftime('%Y-%m-%d', time.localtime(i['ts'])))
for it in five:
tt = time.strftime('%Y-%m-%d', time.localtime(it['ts']))
if tt not in ll:
ll.append(tt)
t2 = time.strftime('%H:%M', time.localtime(it['ts']))
print(time.strftime('%Y-%m-%d %H:%M', time.localtime(it['ts'])), i['symbol'])
def get_five_now_data():
ts = settings_db.find_one({"name": "nine_timestamp"})['timestamp']
all = record_db.find({"ts": {"$gte": ts}, 'high': 1}).sort([('ts', 1)])
kk = []
for i in all:
i.pop("_id")
i['date'] = time.strftime('%Y-%m-%d %H:%M', time.localtime(i['ts']))
if i['symbol'] not in kk:
print(i)
kk.append(i['symbol'])
def save_five_days_record():
st = data_day_db.find_one({'symbol': 'SZ002466'})
ts = st['item'][-10][0] / 1000
all = record_db.find({"ts": {"$gte": ts}}).sort([('ts', 1)])
record_day_db.delete_many({"date": {"$gte": '1'}})
ll = []
for i in all:
datte = time.strftime('%Y-%m-%d', time.localtime(i['ts']))
record_day_db.update_one({"symbol": i['symbol'], 'date': datte}, {"$set": {"symbol": i['symbol'], 'date': datte}}, upsert=True)
if i['symbol'] not in ll:
ll.append(i['symbol'])
print(len(ll))
# for i in ll:
# pr = stock_db.find_one({"symbol": i})
# if pr['price'] < 2000000000:
# record_db.delete_many({"symbol": i})
def save__record_to_tmp():
st = data_day_db.find_one({'symbol': 'SZ002466'})
ts = st['item'][-1][0] / 1000
all = record_db.find({"ts": {"$gte": ts}}).sort([('ts', 1)])
p = []
for i in all:
i.pop('_id')
p.append(i)
record_tmp_db.insert_many(p)
def mamama():
st = data_day_db.find_one({"symbol": 'SH600170'})
x1 = EMA([round(decimal.Decimal(x[5]), 2) for x in st['item'][:-2]])
def fix():
pass
if __name__ == "__main__":
# set_five_history()
# set_history()
# rettt()
# get_name()
# ccccc()
# set_ip_count()
# fix()
# set_five_history()
# compare()
# set_ct()
# update_account()
# tet()
# reset_all_ip()
######################## IPIPIPIP
# iiippp.parse()
# pp.save()
# send_req("121.232.148.208:3256")
# play()
# fix()
# send_info('SH600096', 'teqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqst')
# send_s_msg('SH600096', 'teqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqst')
# update_stock_core()
# get_day_data()
# run()
# t1 = time.time()
# test_son_work_together_one_mintue()
# print(time.time()-t1)
# new_ip_obj.get_req(15363, 15374)
clean_db_ip()
clean_db_txt_ip()
clean_dirty_db_ip()
# new_ip_obj.save()
# new_ip_obj.save_dirty()
# check_duplicate_ip()
# set_account()
# saveAccount()
# update_account()
# get_name()
# dd()
# aaa()
# get_hot_ip_job()
# sset4()
# sset3()
# sset2()
# sset()
# play_without_flag(mission_five)
# play_without_flag_for_all(mission_day_all_stock)
# seeet()
# sendmsg()
# set_all_stock_tmpxxx()
# check_tmp()
# get_record_data()
# get_record_datasad(1636300800, 1636300800 + 24*3600)
# get_record_histroy1()
# get_record_histroy2()
# get_record_histroy3()
# get_record_histroy4()
# get_record_histroy5()
# fifteen_get_five()
# save__record_to_tmp()
# setss()
# get_five_now_data()
# save_five_days_record()
# mamama()
# stand_v2()
# mian_do()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yekai2233/kapp.git
[email protected]:yekai2233/kapp.git
yekai2233
kapp
kapp
master

搜索帮助