Best Python code snippet using lemoncheesecake
k1.py
Source:k1.py
...35 and ref_open(0) <= ref_close(1)36 rule2 = False37 if rule1 or rule2:38 rv = 139 log_debug("nice: hammer")40 log_debug("rate1: %.2f", rate1)41 log_debug("rate2: %.2f", rate2)42 log_debug("hp2: %.2f", hp2)43 log_debug("amp2: %.2f", amp2)44 log_debug("%.2f, %.2f", zt1, zt2)45 else:46 rv = 047 # log_debug("not match")48 return rv49###50# åºé 2017-4-551# éè¦å线åæ£52# 600242, 2017-03-14: -6.7%; 2017-03-15: 10%, é³æ±å
æ¬é´æ±53# 600165, 2017-03-27, -6.6%; 2017-03-28: 8.08%54# bad -- 00263455def citou():56 rate1 = (ref_close(1) - ref_close(2)) / ref_close(2) * 100 # æ¨æ¥æ¶¨å¹
57 rate2 = (ref_close(0) - ref_close(1)) / ref_close(1) * 100 # ä»æ¥æ¶¨å¹
58 log_debug("rate1: %.2f", rate1)59 log_debug("rate2: %.2f", rate2)60 # if rate1 <= -5 and rate2 >= 5 and ref_open(0) < ref_low(1) and ref_close(0) > mid: # 2016-11-2061 if rate1 <= -6.5 and rate2 >= 8.0 \62 and ref_open(0) <= ref_close(1)*1.01 \63 and ref_close(0) > ref_high(1):64 rv = 165 log_debug("nice: citou")66 log_debug("rate1: %.2f", rate1)67 log_debug("rate2: %.2f", rate2)68 log_debug("open0: %.2f", ref_open(0))69 log_debug("close0:%.2f", ref_close(0))70 log_debug("close1:%.2f", ref_close(1)*1.01)71 log_debug("high1: %.2f", ref_high(1))72 else:73 rv = 074 # log_debug("not match")75 return rv76###77# åºé 2017-5-2978# éè¦ç©¿è¶4线+å线åæ£79# 60309880# 00215881# ################82# 60389683# 00085684# ################85def citou2():86 rate1 = (ref_close(1) - ref_close(2)) / ref_close(2) * 100 # æ¨æ¥æ¶¨å¹
87 rate2 = (ref_close(0) - ref_close(1)) / ref_close(1) * 100 # ä»æ¥æ¶¨å¹
88 zt1 = (ref_close(1) - ref_open(1)) / ref_close(2) * 100 # 第ä¸å¤©89 zt2 = (ref_close(0) - ref_open(0)) / ref_close(1) * 100 # 第äºå¤©90 # 60309891 # 00215892 rule1 = rate1 <= -9.8 and rate2 >= 9.8 \93 and ref_close(0) >= ref_high(1) \94 and ref_low(0) <= ref_close(1) \95 and zt1 < -5 \96 and zt2 > 897 # 603896, zt14, 1598 # 000856, zt5, 1099 rule2 = rate1 <= -9.8 and rate2 >= 9.8 \100 and ref_close(0)*1.05 >= ref_high(1) \101 and ref_open(0) <= ref_close(1) \102 and zt1 < -5 \103 and zt2 >= 10104 # 002761105 rule3 = rate1 <= -9.9 and rate2 >= 9.9106 if rule1 or rule2 or rule3:107 rv = 1108 log_debug("nice: citou2")109 log_debug("rate1: %.2f", rate1)110 log_debug("rate2: %.2f", rate2)111 log_debug("low: %.2f", ref_low(1))112 log_debug("close: %.2f", ref_close(0))113 log_debug("open: %.2f", ref_open(0))114 log_debug("%.2f, %.2f", zt1, zt2)115 else:116 rv = 0117 # log_debug("not match")118 return rv119# è¶
çº§æ¨¡å¼ 2017-2-11120# 002346 -- 2016-12-26121# 300311 -- 2017-1-17122# 600698 -- 2017-1-17123#######################124# 第ä¸å¤©è·åï¼å¤§è· -8%125# 第äºå¤©æ¶¨åï¼å¤§æ¶¨ +8%126# ä»æ¥å¼ç < æ¨æ¥æä½127# ä»æ¥æ¶ç > æ¨æ¥æé«128#######################129def fanbao():130 rate1 = (ref_close(1) - ref_close(2)) / ref_close(2) * 100131 rate2 = (ref_close(0) - ref_close(1)) / ref_close(1) * 100132 if rate1 <= -8 and rate2 >= 8 and ref_open(0) < ref_low(1) and ref_close(0) > ref_high(1):133 rv = 1134 log_debug("nice: fanbao")135 log_debug("rate1: %.2f", rate1)136 log_debug("rate2: %.2f", rate2)137 log_debug("low: %.2f", ref_low(1))138 log_debug("close: %.2f", ref_close(0))139 log_debug("open: %.2f", ref_open(0))140 else:141 rv = 0142 # log_debug("not match")143 return rv144def qiming():145 rate1 = (ref_close(2) - ref_close(3)) / ref_close(3) * 100 # 第ä¸å¤© å天146 rate3 = (ref_close(0) - ref_close(1)) / ref_close(1) * 100 # 第ä¸å¤© today147 md1 = (ref_open(2)*2 + ref_close(2))/ 3148 zt1 = (ref_close(2) - ref_open(2)) / ref_close(3) * 100 # 第ä¸å¤©149 zt2 = (ref_close(1) - ref_open(1)) / ref_close(2) * 100 # 第äºå¤©150 zt3 = (ref_close(0) - ref_open(0)) / ref_close(1) * 100 # 第ä¸å¤© today151 # 1. å天大å¹
ä¸è·152 # 2. æ¨å¤©ä½å¼153 # 3. ä»å¤©é«å¼154 # 4. ä»å¤©æ¶çè¶
è¿å天2/3155 if rate1 <= -8 and rate3 >= 7\156 and ref_open(1) < ref_close(2) \157 and ref_open(0)*1.01 >= ref_close(1) \158 and ref_close(0) >= md1 \159 and zt1 <= -4 \160 and zt3 >= 6 \161 and abs(zt2) <= 4:162 rv = 1163 log_debug("nice: qiming")164 log_debug("rate1: %.2f pk %.2f => %.2f", ref_close(2), ref_close(3), rate1)165 log_debug("rate3: %.2f pk %.2f => %.2f", ref_close(0), ref_close(1), rate3)166 log_debug("%.2f < %.2f", ref_open(1), ref_close(2))167 log_debug("%.2f > %.2f", ref_open(0), ref_close(1))168 log_debug("%.2f >= %.2f", ref_close(0), md1)169 log_debug("%.2f , %.2f , %.2f", zt1, zt2, zt3)170 else:171 rv = 0172 # log_debug("not match")173 return rv174"""175002011 - 2017-5-24176"""177def qiming2():178 rate1 = (ref_close(2) - ref_close(3)) / ref_close(3) * 100 # 第ä¸å¤© å天179 rate3 = (ref_close(0) - ref_close(1)) / ref_close(1) * 100 # 第ä¸å¤© today180 md1 = (ref_open(2)*2 + ref_close(2))/ 3181 zt1 = (ref_close(2) - ref_open(2)) / ref_close(3) * 100 # 第ä¸å¤©182 zt2 = (ref_close(1) - ref_open(1)) / ref_close(2) * 100 # 第äºå¤©183 zt3 = (ref_close(0) - ref_open(0)) / ref_close(1) * 100 # 第ä¸å¤© today184 # 1. å天大å¹
ä¸è·185 # 2. æ¨å¤©ä½å¼186 # 3. ä»å¤©é«å¼187 # 4. ä»å¤©æ¶çè¶
è¿å天2/3188 if rate1 <= -6 and rate3 >= 9.8 \189 and ref_open(1) <= ref_close(2) \190 and ref_open(0)*1.01 >= ref_close(1) \191 and ref_close(0) >= ref_high(2) \192 and zt1 <= -5 \193 and zt3 >= 9 \194 and abs(zt2) <= 2:195 rv = 1196 log_debug("nice: qiming2")197 log_debug("rate1: %.2f pk %.2f => %.2f", ref_close(2), ref_close(3), rate1)198 log_debug("rate3: %.2f pk %.2f => %.2f", ref_close(0), ref_close(1), rate3)199 log_debug("%.2f <= %.2f", ref_open(1), ref_close(2))200 log_debug("%.2f >= %.2f", ref_open(0)*1.01, ref_close(1))201 log_debug("%.2f >= %.2f", ref_close(0), ref_high(2))202 log_debug("%.2f , %.2f , %.2f", zt1, zt2, zt3)203 else:204 rv = 0205 # log_debug("not match")206 return rv207"""208002837 - 2017-6-5209"""210def qiming3():211 rate1 = (ref_close(2) - ref_close(3)) / ref_close(3) * 100 # 第ä¸å¤© å天212 rate3 = (ref_close(0) - ref_close(1)) / ref_close(1) * 100 # 第ä¸å¤© today213 zt1 = (ref_close(2) - ref_open(2)) / ref_close(3) * 100 # 第ä¸å¤©214 zt2 = (ref_close(1) - ref_open(1)) / ref_close(2) * 100 # 第äºå¤©215 zt3 = (ref_close(0) - ref_open(0)) / ref_close(1) * 100 # 第ä¸å¤© today216 # 1. å天-10217 # 2. æ¨å¤©ä½å¼+218 # 3. ä»å¤©+10219 # 002837220 rule1 = rate1 <= -9.8 and rate3 >= 9.8 \221 and zt2 > 0 \222 and ref_open(1) <= ref_close(2) \223 and zt3 > 2 224 # XXX225 rule2 = False226 if rule1 or rule2:227 rv = 1228 log_debug("nice: qiming3")229 log_debug("rate1: %.2f pk %.2f => %.2f", ref_close(2), ref_close(3), rate1)230 log_debug("rate3: %.2f pk %.2f => %.2f", ref_close(0), ref_close(1), rate3)231 log_debug("%.2f <= %.2f", ref_open(1), ref_close(2))232 log_debug("%.2f >= %.2f", ref_open(0)*1.01, ref_close(1))233 log_debug("%.2f >= %.2f", ref_close(0), ref_high(2))234 log_debug("%.2f , %.2f , %.2f", zt1, zt2, zt3)235 else:236 rv = 0237 # log_debug("not match")238 return rv239# è¦æ±len >= 6240def up_sanfa():241 if ref_len() < 6:242 log_info("data not enough: 6")243 return -1244 rate1 = (ref_close(4) - ref_close(5)) / ref_close(5) * 100 # day1 涨å¹
245 zt1 = (ref_close(4) - ref_open(4)) / ref_close(5) * 100 # day1 æ±ä½246 rate2 = (ref_close(3) - ref_close(4)) / ref_close(4) * 100 # day2247 md2 = (ref_close(3) + ref_open(3))/ 2248 rate3 = (ref_close(2) - ref_close(3)) / ref_close(3) * 100 # day3249 md3 = (ref_close(2) + ref_open(2))/ 2250 rate4 = (ref_close(1) - ref_close(2)) / ref_close(2) * 100 # day4251 md4 = (ref_close(1) + ref_open(1))/ 2252 rate5 = (ref_close(0) - ref_close(1)) / ref_close(1) * 100 # day5 涨å¹
253 zt5 = (ref_close(0) - ref_open(0)) / ref_close(1) * 100 # day5 æ±ä½254 # 1. day1 大涨255 # 2. day2,3,4 è¿è·3天256 # 3. day5 大涨257 if rate1 >=2 and zt1 >= 3 \258 and md2 <= ref_high(4) and abs(rate2) <= 0.8 \259 and md3 <= md2 and abs(rate3) <= 0.8 and ref_close(2) < ref_close(3) \260 and md4 <= md3 and abs(rate4) <= 0.8 and ref_close(1) < ref_close(2) \261 and ref_open(0) >= ref_open(4) \262 and ref_close(0) >= ref_close(4) \263 and ref_open(0) <= ref_close(1) \264 and rate5 >= 2 and zt5 >= 3:265 rv = 1266 log_debug("nice: sanfa")267 log_debug("rate1: %.2f pk %.2f => %.2f", ref_close(4), ref_close(5), rate1)268 log_debug("rate5: %.2f pk %.2f => %.2f", ref_close(0), ref_close(1), rate5)269 log_debug("%.2f , %.2f , %.2f", md2, md3, md4)270 else:271 rv = 0272 # log_debug("not match")273 return rv274"""275000507 - 2017-5-24276"""277def qiming4():278 rate1 = (ref_close(2) - ref_close(3)) / ref_close(3) * 100 # 第ä¸å¤© å天279 rate3 = (ref_close(0) - ref_close(1)) / ref_close(1) * 100 # 第ä¸å¤© today280 md1 = (ref_open(2)*2 + ref_close(2))/ 3281 zt1 = (ref_close(2) - ref_open(2)) / ref_close(3) * 100 # 第ä¸å¤©282 zt2 = (ref_close(1) - ref_open(1)) / ref_close(2) * 100 # 第äºå¤©283 zt3 = (ref_close(0) - ref_open(0)) / ref_close(1) * 100 # 第ä¸å¤© today284 log_debug("rate1: %.2f pk %.2f => %.2f", ref_close(2), ref_close(3), rate1)285 log_debug("rate3: %.2f pk %.2f => %.2f", ref_close(0), ref_close(1), rate3)286 log_debug("%.2f <= %.2f", ref_open(1), ref_close(2))287 log_debug("%.2f >= %.2f", ref_open(0)*1.01, ref_close(1))288 log_debug("%.2f >= %.2f", ref_close(0), ref_high(2))289 log_debug("%.2f , %.2f , %.2f", zt1, zt2, zt3)290 # 1. å天大å¹
ä¸è·291 # 2. æ¨å¤©ä½å¼292 # 3. ä»å¤©é«å¼293 # 4. ä»å¤©æ¶çè¶
è¿å天2/3294 if rate1 <= -7 and rate3 >= 9.5 \295 and ref_open(1) <= ref_close(2) \296 and ref_open(0)*1.01 >= ref_close(1) \297 and ref_close(0)*1.01 >= ref_high(2) \298 and zt1 <= -5 \299 and zt3 >= 9 \300 and abs(zt2) <= 2:301 rv = 1302 log_debug("nice: qiming4")303 log_debug("rate1: %.2f pk %.2f => %.2f", ref_close(2), ref_close(3), rate1)304 log_debug("rate3: %.2f pk %.2f => %.2f", ref_close(0), ref_close(1), rate3)305 log_debug("%.2f <= %.2f", ref_open(1), ref_close(2))306 log_debug("%.2f >= %.2f", ref_open(0)*1.01, ref_close(1))307 log_debug("%.2f >= %.2f", ref_close(0), ref_high(2))308 log_debug("%.2f , %.2f , %.2f", zt1, zt2, zt3)309 else:310 rv = 0311 # log_debug("not match")312 return rv313def work_one(_trade_date, _db):314 log_info("date: %s", _trade_date)315 ref_set_date(_trade_date)316 rv = ref_init(_db)317 if rv != 0:318 log_error("error: ref_init")319 return rv320 begin = get_micro_second()321 stocks = ref_get_list()322 rownum = 0323 content1 = "" # fanbao324 content2 = "" # qiming325 content3 = "" # sanfa 2016-12-3326 content4 = "" # citou 2017-4-5327 content5 = "" # qiming2 2017-5-29328 content6 = "" # citou2 2017-5-29329 content7 = "" # qiming3 2017-6-8330 content8 = "" # hammer 2017-6-10331 content9 = "" # qiming4 2017-6-25332 for s_index, s_val in stocks.iteritems():333 rownum = rownum + 1334 stock_id = s_index335 log_info("%s -- %s", _trade_date, stock_id)336 rv = ref_set(stock_id)337 if rv < 0:338 log_error("error: ref_set: %s", stock_id)339 return rv340 elif rv < 5:341 log_error("warn: %s small %d", stock_id, rv)342 continue343 rv = fanbao()344 if rv == 1:345 one = "%s -- %s\n" % (_trade_date, stock_id)346 one += get_basic_info_all(stock_id, _db)347 one += "--------------------------------\n"348 log_info("nice1-fanbao: %s", one)349 content1 += one350 else:351 # log_debug("wait...")352 pass353 rv = qiming()354 if rv == 1:355 two = "%s -- %s\n" % (_trade_date, stock_id)356 if tech_is_cross5(stock_id, _trade_date, _db):357 good = "+++withä¸é³5线\n"358 elif tech_is_cross4(stock_id, _trade_date, _db):359 good = "++with ä¸é³4线\n"360 else:361 good = "better if could cross\n"362 two += good363 two += get_basic_info_all(stock_id, _db)364 two += "--------------------------------\n"365 log_info("nice2-qiming: %s", two)366 content2 += two367 else:368 # log_debug("wait...")369 pass370 rv = up_sanfa()371 if rv == 1:372 three = "%s -- %s\n" % (_trade_date, stock_id)373 three += get_basic_info_all(stock_id, _db)374 three += "--------------------------------\n"375 log_info("nice3-sanfa: %s", three)376 content3 += three377 else:378 # log_debug("wait...")379 pass380 rv = citou()381 if rv == 1:382 four = "%s -- %s\n" % (_trade_date, stock_id)383 four+= get_basic_info_all(stock_id, _db)384 four+= "--------------------------------\n"385 log_info("nice4-citou: %s", four)386 content4 += four387 else:388 # log_debug("wait...")389 pass390 rv = qiming2()391 if rv == 1:392 five = "%s -- %s\n" % (_trade_date, stock_id)393 five += get_basic_info_all(stock_id, _db)394 five += "--------------------------------\n"395 log_info("nice5-qiming2: %s", five)396 content5 += five397 else:398 # log_debug("wait...")399 pass400 rv = citou2()401 if rv == 1:402 six = "%s -- %s\n" % (_trade_date, stock_id)403 six+= get_basic_info_all(stock_id, _db)404 six+= "--------------------------------\n"405 log_info("nice6-citou2: %s", six)406 content6 += six407 else:408 # log_debug("wait...")409 pass410 rv = qiming3()411 if rv == 1:412 seven = "%s -- %s\n" % (_trade_date, stock_id)413 if tech_is_cross5(stock_id, _trade_date, _db):414 good = "+++bingo withä¸é³5线\n"415 elif tech_is_cross4(stock_id, _trade_date, _db):416 good = "++good with ä¸é³4线\n"417 else:418 good = "NEEDä¸é³5线\n"419 seven += good420 seven += get_basic_info_all(stock_id, _db)421 seven += "--------------------------------\n"422 log_info("nice7-qiming3:\n%s", seven)423 content7 += seven424 else:425 # log_debug("wait...")426 pass427 rv = hammer()428 if rv == 1:429 eight = "%s -- %s\n" % (_trade_date, stock_id)430 good = ""431 eight += good432 eight += get_basic_info_all(stock_id, _db)433 eight += "--------------------------------\n"434 log_info("nice8-hammer:\n%s", eight)435 content8 += eight436 else:437 # log_debug("wait...")438 pass439 rv = qiming4()440 if rv == 1:441 nine = "%s -- %s\n" % (_trade_date, stock_id)442 if tech_is_cross5(stock_id, _trade_date, _db):443 good = "+++withä¸é³5线\n"444 elif tech_is_cross4(stock_id, _trade_date, _db):445 good = "++with ä¸é³4线\n"446 else:447 good = ""448 if len(good) > 0:449 nine += good450 nine += get_basic_info_all(stock_id, _db)451 nine += "--------------------------------\n"452 log_info("nice9-qiming4:\n%s", nine)453 content9 += nine454 else:455 # log_debug("wait...")456 pass457 log_info("%d costs %d us", rownum, get_micro_second() - begin)458 mailed = 0459 if len(content1) > 0:460 subject = "##fanbao: %s" % (_trade_date)461 warning = "éè¦é´æ±å¾é¿\n"462 content1 = warning + content1463 log_info(subject)464 log_info("\n%s", content1)465 if sai_is_product_mode():466 mailed = 1467 saimail(subject, content1)468 else:469 log_info("sorry1: %s", _trade_date)470 if len(content2) > 0:471 subject = "qiming: %s" % (_trade_date)472 good = "###ä¸é³5线æ´ä½³\n"473 content2 = good + content2474 log_info(subject)475 log_info("\n%s", content2)476 if sai_is_product_mode():477 mailed = 1478 saimail(subject, content2)479 else:480 log_info("sorry2: %s", _trade_date)481 if len(content3) > 0:482 subject = "sanfa: %s" % (_trade_date)483 warning = "éè¦å线åæ£!!!\n"484 content3 = warning + content3485 log_info(subject)486 log_info("\n%s", content3)487 if sai_is_product_mode():488 mailed = 1489 saimail(subject, content3)490 else:491 log_info("sorry3: %s", _trade_date)492 if len(content4) > 0:493 subject = "citou: %s" % (_trade_date)494 warning = "éè¦å线åæ£!!!\n"495 content4 = warning + content4496 log_info(subject)497 log_info("\n%s", content4)498 if sai_is_product_mode():499 mailed = 1500 saimail(subject, content4)501 else:502 log_info("sorry1: %s", _trade_date)503 if len(content5) > 0:504 subject = "qiming2: %s" % (_trade_date)505 # good = "###ä¸é³5线æ´ä½³\n"506 # content5 = good + content5507 log_info(subject)508 log_info("\n%s", content5)509 if sai_is_product_mode():510 mailed = 1511 saimail(subject, content5)512 else:513 log_info("sorry1: %s", _trade_date)514 if len(content6) > 0:515 subject = "citou2: %s" % (_trade_date)516 good = "ç©¿è¶4线æ´ä½³\n"517 content6 = good + content6518 log_info(subject)519 log_info("\n%s", content6)520 if sai_is_product_mode():521 mailed = 1522 saimail(subject, content6)523 else:524 log_info("sorry1: %s", _trade_date)525 if len(content7) > 0:526 subject = "qiming3: %s" % (_trade_date)527 log_info(subject)528 log_info("\n%s", content7)529 if sai_is_product_mode():530 mailed = 1531 saimail(subject, content7)532 else:533 log_info("sorry1: %s", _trade_date)534 if len(content8) > 0:535 subject = "hammer: %s" % (_trade_date)536 log_info(subject)537 log_info("\n%s", content8)538 if sai_is_product_mode():539 mailed = 1540 saimail(subject, content8)541 else:542 log_info("sorry1: %s", _trade_date)543 if len(content9) > 0:544 subject = "qiming4: %s" % (_trade_date)545 log_info(subject)546 log_info("\n%s", content9)547 if sai_is_product_mode():548 mailed = 1549 saimail(subject, content9)550 else:551 log_info("sorry1: %s", _trade_date)552 if sai_is_product_mode():553 if mailed == 0:554 subject = "No Good K: %s" % (_trade_date)555 # saimail(subject, "the last chance in your life?")556 return557def regression(_db):558 max_date = "2016-11-08"559 max_date = get_date_by(0)560 max_date = "2016-11-04"561 days = 10562 max_date = "2016-11-25"563 days = 1564 max_date = "2017-02-11"565 days = 60566 max_date = "2016-12-31"567 days = 10568 max_date = "2017-03-31"569 days = 20570 max_date = "2017-05-19"571 days = 10572 max_date = "2017-05-03"573 days = 3574 max_date = "2017-05-24"575 days = 3576 max_date = "2017-05-09"577 days = 3578 max_date = "2017-04-25"579 days = 2580 max_date = "2017-05-23"581 days = 2582 max_date = "2017-06-05"583 days = 2584 # 000507585 max_date = "2017-05-24"586 days = 2587 # 000852588 max_date = "2017-05-15"589 days = 2590 log_info("regress")591 date_df = get_recent_pub_date(max_date, days, _db)592 if date_df is None:593 log_error("error: get_recent_pub_date failure")594 return -1595 else:596 date_df.set_index("pub_date", inplace=True)597 for row_index, row in date_df.iterrows():598 trade_date = row_index599 log_debug("[%s]------------------", trade_date)600 work_one(trade_date, _db)601 return 0602def work():603 db = db_init()604 if sai_is_product_mode():605 trade_date = "2016-12-26" # 002346606 trade_date = "2017-04-04"607 trade_date = get_date_by(0)608 work_one(trade_date, db)609 else:610 regression(db)611 db_end(db)612#######################################################################613def main():614 sailog_set("k1.log")615 log_info("let's begin here!")616 if sai_is_product_mode():617 # check holiday618 if today_is_weekend():619 log_info("today is weekend, exit")620 else:621 log_info("today is workday, come on")622 work()623 else:624 log_debug("test mode")625 work()626 log_info("main ends, bye!")627 return628main()629exit()630#######################################################################...
k2.py
Source:k2.py
...57 rule2 = False and (rule2_sub1 and rule2_sub2 and rule2_sub3)58 rule3 = False59 if rule1:60 rv = 161 log_debug("nice: up-accumulate rule1")62 log_debug("1-rate:%.3f, zt:%.3f, vol: %.3f", rate1, zt1, vol1)63 log_debug("2-rate:%.3f, zt:%.3f, vol: %.3f", rate2, zt2, vol2)64 log_debug("3-rate:%.3f, zt:%.3f, vol: %.3f", rate3, zt3, vol3)65 log_debug("4-rate:%.3f, zt:%.3f, vol: %.3f", rate4, zt4, vol4)66 log_debug("5-rate:%.3f, zt:%.3f, vol: %.3f", rate5, zt5, vol5)67 elif rule2:68 rv = 269 log_debug("nice: up-accumulate rule2")70 log_debug("1-rate:%.3f, zt:%.3f, vol: %.3f", rate1, zt1, vol1)71 log_debug("2-rate:%.3f, zt:%.3f, vol: %.3f", rate2, zt2, vol2)72 log_debug("3-rate:%.3f, zt:%.3f, vol: %.3f", rate3, zt3, vol3)73 log_debug("4-rate:%.3f, zt:%.3f, vol: %.3f", rate4, zt4, vol4)74 log_debug("5-rate:%.3f, zt:%.3f, vol: %.3f", rate5, zt5, vol5)75 else:76 rv = 077 # log_debug("not match")78 return rv79# 2017-6-1680# 00002581# 1. ä¸ä¸ªæ¶¨å82# 2. 第å天åå83def up_fly():84 if ref_len() < 6:85 log_info("data not enough: 6")86 return -187 # è¿ç»5天æ°æ®88 # å¯ä»¥åæè¿4天ï¼å³ä¸ç¨rate189 rate1 = (ref_close(4) - ref_close(5)) / ref_close(5) * 100 # day1 涨å¹
90 zt1 = (ref_close(4) - ref_open(4)) / ref_close(5) * 100 # day1 æ±ä½91 vol1 = ref_vol(4)92 rate2 = (ref_close(3) - ref_close(4)) / ref_close(4) * 100 # day2 涨å¹
93 zt2 = (ref_close(3) - ref_open(3)) / ref_close(4) * 100 # day2 æ±ä½94 vol2 = ref_vol(3) # day2 æ交é95 rate3 = (ref_close(2) - ref_close(3)) / ref_close(3) * 100 # day3 涨å¹
96 zt3 = (ref_close(2) - ref_open(2)) / ref_close(3) * 100 # day3 æ±ä½97 vol3 = ref_vol(2) # day3 æ交é98 rate4 = (ref_close(1) - ref_close(2)) / ref_close(2) * 100 # day4 涨å¹
99 zt4 = (ref_close(1) - ref_open(1)) / ref_close(2) * 100 # day4 æ±ä½100 vol4 = ref_vol(1) # day4 æ交é101 rate5 = (ref_close(0) - ref_close(1)) / ref_close(1) * 100 # day5 涨å¹
102 zt5 = (ref_close(0) - ref_open(0)) / ref_close(1) * 100 # day5 æ±ä½103 vol5 = ref_vol(0) # day5 æ交é104 # rule1: 5105 # 1.106 # 2.107 rule1_sub1 = rate4 > 9.8 and rate3 > 9.8 and rate2 > 9.8108 rule1_sub2 = rate5 > 1 and abs(zt5) < 1109 rule1_sub3 = zt2 > 9.8 and zt3 > 9.8 and zt4 > 6.8110 rule1_sub4 = vol4 > vol3 and vol3 > vol2 and vol2 > vol1111 rule1 = rule1_sub1 and rule1_sub2 and rule1_sub3 and rule1_sub4112 # rule2: 4113 rule2 = False114 rule3 = False115 if rule1:116 rv = 1117 log_debug("nice: up-fly rule1")118 log_debug("1-rate:%.3f, zt:%.3f, vol: %.3f", rate1, zt1, vol1)119 log_debug("2-rate:%.3f, zt:%.3f, vol: %.3f", rate2, zt2, vol2)120 log_debug("3-rate:%.3f, zt:%.3f, vol: %.3f", rate3, zt3, vol3)121 log_debug("4-rate:%.3f, zt:%.3f, vol: %.3f", rate4, zt4, vol4)122 log_debug("5-rate:%.3f, zt:%.3f, vol: %.3f", rate5, zt5, vol5)123 log_debug("zt5: %.3f", zt5)124 elif rule2:125 rv = 2126 log_debug("nice: up-fly rule2")127 log_debug("rate:%.3f, vol:%.3f, zt: %.3f", rate1, zt1, vol1)128 log_debug("rate:%.3f, vol:%.3f, zt: %.3f", rate2, zt2, vol2)129 log_debug("rate:%.3f, vol:%.3f, zt: %.3f", rate3, zt3, vol3)130 log_debug("rate:%.3f, vol:%.3f, zt: %.3f", rate4, zt4, vol4)131 log_debug("rate:%.3f, vol:%.3f, zt: %.3f", rate5, zt5, vol5)132 else:133 rv = 0134 # log_debug("not match")135 return rv136# 2017-6-16137# 300506138# 1. ä¸ä¸²ç½æ¦å£«139# 2. æ¶å¤ma20140def up_warrior():141 if ref_len() < 6:142 log_info("data not enough: 6")143 return -1144 # è¿ç»5天æ°æ®145 # å¯ä»¥åæè¿4天ï¼å³ä¸ç¨rate1146 rate1 = (ref_close(4) - ref_close(5)) / ref_close(5) * 100 # day1 涨å¹
147 zt1 = (ref_close(4) - ref_open(4)) / ref_close(5) * 100 # day1 æ±ä½148 vol1 = ref_vol(4)149 rate2 = (ref_close(3) - ref_close(4)) / ref_close(4) * 100 # day2 涨å¹
150 zt2 = (ref_close(3) - ref_open(3)) / ref_close(4) * 100 # day2 æ±ä½151 vol2 = ref_vol(3) # day2 æ交é152 rate3 = (ref_close(2) - ref_close(3)) / ref_close(3) * 100 # day3 涨å¹
153 zt3 = (ref_close(2) - ref_open(2)) / ref_close(3) * 100 # day3 æ±ä½154 vol3 = ref_vol(2) # day3 æ交é155 rate4 = (ref_close(1) - ref_close(2)) / ref_close(2) * 100 # day4 涨å¹
156 zt4 = (ref_close(1) - ref_open(1)) / ref_close(2) * 100 # day4 æ±ä½157 vol4 = ref_vol(1) # day4 æ交é158 rate5 = (ref_close(0) - ref_close(1)) / ref_close(1) * 100 # day5 涨å¹
159 zt5 = (ref_close(0) - ref_open(0)) / ref_close(1) * 100 # day5 æ±ä½160 vol5 = ref_vol(0) # day5 æ交é161 log_debug("1-rate:%.3f, zt:%.3f, vol: %.3f", rate1, zt1, vol1)162 log_debug("2-rate:%.3f, zt:%.3f, vol: %.3f", rate2, zt2, vol2)163 log_debug("3-rate:%.3f, zt:%.3f, vol: %.3f", rate3, zt3, vol3)164 log_debug("4-rate:%.3f, zt:%.3f, vol: %.3f", rate4, zt4, vol4)165 log_debug("5-rate:%.3f, zt:%.3f, vol: %.3f", rate5, zt5, vol5)166 # rule1: 5167 # 1.168 # 2.169 rule1_sub1 = rate1 > 0 and rate2 > 0 and rate3 > 0 and rate4 > 0 and rate5 > 0170 rule1_sub2 = rate1 < 4 and rate2 < 4 and rate3 < 4 and rate4 < 4 and rate5 < 4171 rule1_sub3 = vol5 > vol4 and vol4 > vol3172 rule1_sub4 = zt5 > zt4 and zt4 > zt3 and zt3 > 0173 rule1 = False and rule1_sub1 and rule1_sub2 and rule1_sub3 and rule1_sub4174 # rule2: 4175 rule2 = False176 rule3 = False177 if rule1:178 rv = 1179 log_debug("nice: up-warrior rule1")180 log_debug("1-rate:%.3f, zt:%.3f, vol: %.3f", rate1, zt1, vol1)181 log_debug("2-rate:%.3f, zt:%.3f, vol: %.3f", rate2, zt2, vol2)182 log_debug("3-rate:%.3f, zt:%.3f, vol: %.3f", rate3, zt3, vol3)183 log_debug("4-rate:%.3f, zt:%.3f, vol: %.3f", rate4, zt4, vol4)184 log_debug("5-rate:%.3f, zt:%.3f, vol: %.3f", rate5, zt5, vol5)185 log_debug("zt5: %.3f", zt5)186 elif rule2:187 rv = 2188 log_debug("nice: up-warrior rule2")189 log_debug("rate:%.3f, vol:%.3f, zt: %.3f", rate1, zt1, vol1)190 log_debug("rate:%.3f, vol:%.3f, zt: %.3f", rate2, zt2, vol2)191 log_debug("rate:%.3f, vol:%.3f, zt: %.3f", rate3, zt3, vol3)192 log_debug("rate:%.3f, vol:%.3f, zt: %.3f", rate4, zt4, vol4)193 log_debug("rate:%.3f, vol:%.3f, zt: %.3f", rate5, zt5, vol5)194 else:195 rv = 0196 # log_debug("not match")197 return rv198def work_one(_trade_date, _db):199 good = ""200 log_info("date: %s", _trade_date)201 ref_set_date(_trade_date)202 rv = ref_init(_db)203 if rv != 0:204 log_error("error: ref_init")205 return rv206 begin = get_micro_second()207 stocks = ref_get_list()208 rownum = 0209 content1 = "" # up-accu210 content2 = "" # up-fly211 content3 = "" # up-warrior212 for s_index, s_val in stocks.iteritems():213 rownum = rownum + 1214 stock_id = s_index215 log_info("%s -- %s", _trade_date, stock_id)216 rv = ref_set(stock_id)217 if rv < 0:218 log_error("error: ref_set: %s", stock_id)219 return rv220 elif rv < 5:221 log_error("warn: %s small %d", stock_id, rv)222 continue223 rv = up_accum()224 if rv == 1:225 one = "%s -- %s\n" % (_trade_date, stock_id)226 """227 if tech_is_cross5(stock_id, _trade_date, _db):228 good = "+++bingo withä¸é³5线\n"229 elif tech_is_cross4(stock_id, _trade_date, _db):230 good = "++good with ä¸é³4线\n"231 else:232 good = "NEEDä¸é³5线\n"233 """234 one += good235 one += get_basic_info_all(stock_id, _db)236 one += "--------------------------------\n"237 log_info("nice1-up_accum:\n%s", one)238 content1 += one239 else:240 # log_debug("wait...")241 pass242 rv = up_fly()243 if rv == 1:244 two = "%s -- %s\n" % (_trade_date, stock_id)245 two += good246 two += get_basic_info_all(stock_id, _db)247 two += "--------------------------------\n"248 log_info("nice2-up_accum:\n%s", two)249 content2 += two250 else:251 # log_debug("wait...")252 pass253 rv = up_warrior()254 if rv == 1:255 three = "%s -- %s\n" % (_trade_date, stock_id)256 three += good257 three += get_basic_info_all(stock_id, _db)258 three += "--------------------------------\n"259 log_info("nice3-up_warrior:\n%s", three)260 content3 += three261 else:262 # log_debug("wait...")263 pass264 log_info("%d costs %d us", rownum, get_micro_second() - begin)265 mailed = 0266 if len(content1) > 0:267 subject = "up_accum: %s" % (_trade_date)268 log_info(subject)269 log_info("\n%s", content1)270 if sai_is_product_mode():271 mailed = 1272 saimail_dev(subject, content1)273 else:274 log_info("sorry1: %s", _trade_date)275 if len(content2) > 0:276 subject = "up_fly: %s" % (_trade_date)277 log_info(subject)278 log_info("\n%s", content2)279 if sai_is_product_mode():280 mailed = 1281 saimail_dev(subject, content2)282 else:283 log_info("sorry1: %s", _trade_date)284 if len(content3) > 0:285 subject = "up_warrior: %s" % (_trade_date)286 log_info(subject)287 log_info("\n%s", content3)288 if sai_is_product_mode():289 mailed = 1290 saimail_dev(subject, content3)291 else:292 log_info("sorry1: %s", _trade_date)293 if sai_is_product_mode():294 if mailed == 0:295 subject = "No Good K: %s" % (_trade_date)296 # saimail(subject, "the last chance in your life?")297 return298def regression(_db):299 # 002695300 max_date = "2017-06-09"301 days = 1302 max_date = "2017-06-14"303 days = 20304 # 000025305 max_date = "2017-06-13"306 days = 1307 # 000506308 max_date = "2017-06-09"309 days = 1310 log_info("regress")311 date_df = get_recent_pub_date(max_date, days, _db)312 if date_df is None:313 log_error("error: get_recent_pub_date failure")314 return -1315 else:316 date_df.set_index("pub_date", inplace=True)317 for row_index, row in date_df.iterrows():318 trade_date = row_index319 log_debug("[%s]------------------", trade_date)320 work_one(trade_date, _db)321 return 0322def work():323 db = db_init()324 if sai_is_product_mode():325 trade_date = get_date_by(0)326 work_one(trade_date, db)327 else:328 regression(db)329 db_end(db)330#######################################################################331def main():332 sailog_set("k2.log")333 log_info("let's begin here!")334 if sai_is_product_mode():335 # check holiday336 if today_is_weekend():337 log_info("today is weekend, exit")338 else:339 log_info("today is workday, come on")340 work()341 else:342 log_debug("test mode")343 work()344 log_info("main ends, bye!")345 return346main()347exit()348#######################################################################...
syslog.sh
Source:syslog.sh
1#!/usr/bin/python2import os3import sys4import time5import cx_Oracle6import subprocess7import datetime8import curlsend9debugflag = 010syslog_server_ip = '127.0.0.1'11syslog_server_port = '514'12max_seq = 013DEBUG_FILE = '/home/irass/log/syslog.log'14LOG_DEBUG = open(DEBUG_FILE, "a+")15LOG_DEBUG.write("Syslog service start : "+str(datetime.datetime.now())+"\n")16LOG_DEBUG.flush()17#select login_events max seq18try:19 dbconn = cx_Oracle.connect('appm', 'appmadmin', 'XE')20 cursor = dbconn.cursor()21except Exception as err:22 if debugflag == 1:23 print(err)24 LOG_DEBUG.write("Database connect error : "+str(datetime.datetime.now())+"\n")25 LOG_DEBUG.write(str(err)+"\n")26 LOG_DEBUG.flush()27 sys.exit(-1)28cursor.execute("SELECT MAX(SEQ) FROM APPM.LOGIN_EVENTS",29 {30 }31)32try:33 event_max_seq = cursor.fetchall()[0][0]34 if debugflag == 1:35 print('event_max_seq:',event_max_seq)36except Exception as err:37 if debugflag == 1:38 print(err)39 LOG_DEBUG.write("LOGIN_EVENTS SEQ Number read error : "+str(datetime.datetime.now())+"\n")40 LOG_DEBUG.write(str(err)+"\n")41 LOG_DEBUG.flush()42 sys.exit(-1) 43#select login_trans max seq44cursor.execute("SELECT MAX(SEQ) FROM APPM.LOGIN_TRANS",45 {46 }47)48try:49 login_max_seq = cursor.fetchall()[0][0]50 if debugflag == 1:51 print('login_max_seq:',login_max_seq)52except Exception as err:53 if debugflag == 1:54 print(err)55 LOG_DEBUG.write("LOGIN_TRANS SEQ Number read error : "+str(datetime.datetime.now())+"\n")56 LOG_DEBUG.write(str(err)+"\n")57 LOG_DEBUG.flush()58 sys.exit(-1)59#select audit_trail max auditdate60cursor.execute("SELECT TO_CHAR(MAX(AUDITDATE),'mm-dd-yyyy hh24:mi:ss') FROM APPM.AUDIT_TRAIL",61 {62 }63)64try:65 auditdate_max = cursor.fetchall()[0][0]66 if debugflag == 1:67 print('auditdate_max:',auditdate_max)68except Exception as err:69 if debugflag == 1:70 print(err)71 LOG_DEBUG.write("AUDIT_TRAIL SEQ Number read error : "+str(datetime.datetime.now())+"\n")72 LOG_DEBUG.write(str(err)+"\n")73 LOG_DEBUG.flush()74 sys.exit(-1)75#event_max_seq = 117676#login_max_seq = 647477#auditdate_max = '10-25-2018 18:23:41'78while True:79 try:80 if debugflag == 1:81 print('event_max_seq:',event_max_seq)82 cursor.execute("SELECT SEQ,PERSONID,PERSONNAME,HOSTNAME,IPADDR,ACCOUNTID,CLIENT_IPADDR, PROTOCOL,EVENT_TYPE,COMMAND,SUCCESSFAILFLAG,TO_CHAR(EVENTDATE,'mm-dd-yyyy HH24:mi:ss') FROM APPM.LOGIN_EVENTS WHERE SUCCESSFAILFLAG != 1 AND SEQ > :v1 ORDER BY SEQ",83 {84 'v1' : int(event_max_seq),85 }86 )87 info = cursor.fetchall()88 for x in info:89 seq = x[0]90 personid = x[1]91 personname = x[2]92 hostname = x[3]93 ipaddr = x[4]94 accountid = x[5]95 client_ipaddr = x[6]96 protocol = x[7]97 event_type = x[8]98 command = x[9]99 successfailflag = x[10]100 eventdate = x[11]101 if debugflag == 1:102 print(seq,personid,personname,hostname,ipaddr,accountid,client_ipaddr, protocol,event_type,command,successfailflag,eventdate)103 #send syslog104 cmd = '/usr/bin/logger -n ' + syslog_server_ip + ' -T -P ' + syslog_server_port + ' \"'+eventdate+' '+personid+' '+personname+' '+hostname+' '+ipaddr+' '+accountid+' '+client_ipaddr+' '+ protocol+' '+event_type+' '+command+'\"'105 if debugflag == 1:106 print(cmd)107 popen = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)108 out, error = popen.communicate()109 if debugflag == 1:110 print("logger out:",out)111 #webex112 payload = curlsend.getcontent1(eventdate, personid, personname, client_ipaddr, hostname+' '+ipaddr+' '+accountid+' '+client_ipaddr+' '+ protocol+' '+event_type+' '+command)113 cmd = """curl --request POST --url https://webexapis.com/v1/messages --header 'Authorization: Bearer <Key>' --header 'Content-Type: application/json' --data '"""\114 + payload + "'"115 if debugflag == 1:116 print(cmd)117 popen = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)118 out, error = popen.communicate()119 if debugflag == 1:120 print("logger out:",out)121 event_max_seq = seq122 except Exception as err:123 if debugflag == 1:124 print(err)125 LOG_DEBUG.write("EVENT_TRANS Exception error : "+str(datetime.datetime.now())+"\n")126 LOG_DEBUG.write(str(err)+"\n")127 LOG_DEBUG.flush()128 129 sys.exit(-1)130 131 try:132 if debugflag == 1:133 print('auditdate_max:',auditdate_max)134 135 cursor.execute("SELECT PERSONID,PERSONNAME,IPADDR,ACTION,TO_CHAR(AUDITDATE,'mm-dd-yyyy HH24:mi:ss') FROM APPM.AUDIT_TRAIL WHERE AUDITDATE > TO_DATE(:v1,'mm-dd-yyyy hh24:mi:ss') AND DETAIL LIKE ('%client=APPM Client%') ORDER BY AUDITDATE",136 {137 'v1' : auditdate_max,138 }139 )140 info = cursor.fetchall()141 for x in info:142 personid = x[0]143 personname = x[1]144 ipaddr = x[2]145 action = x[3]146 logindate = x[4]147 if debugflag == 1:148 print(personid,personname,ipaddr,action,logindate)149 #send syslog150 cmd = '/usr/bin/logger -n ' + syslog_server_ip + ' -T -P ' + syslog_server_port + ' \"'+logindate+' '+personid+' '+personname+' '+ipaddr+' '+ action+'\"'151 if debugflag == 1:152 print(cmd)153 popen = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)154 out, error = popen.communicate()155 if debugflag == 1:156 print("logger out:",out)157 #webex158 payload = curlsend.getcontent(logindate, personid, personname, ipaddr, action)159 cmd = """curl --request POST --url https://webexapis.com/v1/messages --header 'Authorization: Bearer <Key>' --header 'Content-Type: application/json' --data '"""\160 + payload + "'"161 if debugflag == 1:162 print(cmd)163 popen = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)164 out, error = popen.communicate()165 if debugflag == 1:166 print("logger out:",out)167 auditdate_max = logindate168 except Exception as err:169 if debugflag == 1:170 print(err)171 LOG_DEBUG.write("AUDIT_TRAIL Exception error : "+str(datetime.datetime.now())+"\n")172 LOG_DEBUG.write(str(err)+"\n")173 LOG_DEBUG.flush()174 175 sys.exit(-1)176 177 try:178 if debugflag == 1:179 print('login_max_seq:',login_max_seq)180 181 cursor.execute("SELECT SEQ,PERSONID,PERSONNAME,HOSTNAME,IPADDR,ACCOUNTID,CLIENT_IPADDR, PROTOCOL,SUCCESSFAILFLAG,TO_CHAR(LOGINDATE,'mm-dd-yyyy HH24:mi:ss') FROM APPM.LOGIN_TRANS WHERE SEQ > :v1 ORDER BY SEQ",182 {183 'v1' : int(login_max_seq),184 }185 )186 info = cursor.fetchall()187 for x in info:188 seq = x[0]189 personid = x[1]190 personname = x[2]191 hostname = x[3]192 ipaddr = x[4]193 accountid = x[5]194 client_ipaddr = x[6]195 protocol = x[7]196 successfailflag = x[8]197 logindate = x[9]198 if debugflag == 1:199 print(seq,personid,personname,hostname,ipaddr,accountid,client_ipaddr, protocol,successfailflag,logindate)200 #send syslog201 cmd = '/usr/bin/logger -n ' + syslog_server_ip + ' -T -P ' + syslog_server_port + ' \"'+logindate+' '+personid+' '+personname+' '+hostname+' '+ipaddr+' '+accountid+' '+client_ipaddr+' '+ protocol+'\"'202 if debugflag == 1:203 print(cmd)204 popen = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)205 out, error = popen.communicate()206 if debugflag == 1:207 print("logger out:",out)208 #webex209 payload = curlsend.getcontent(logindate, personid, personname, client_ipaddr, hostname+' '+ipaddr+' '+accountid+' '+protocol)210 cmd = """curl --request POST --url https://webexapis.com/v1/messages --header 'Authorization: Bearer <key>' --header 'Content-Type: application/json' --data '"""\211 + payload + "'"212 if debugflag == 1:213 print(cmd)214 popen = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)215 out, error = popen.communicate()216 if debugflag == 1:217 print("logger out:",out)218 login_max_seq = seq219 except Exception as err:220 if debugflag == 1:221 print(err)222 LOG_DEBUG.write("LOGIN_TRANS Exception error : "+str(datetime.datetime.now())+"\n")223 LOG_DEBUG.write(str(err)+"\n")224 LOG_DEBUG.flush()225 ...
retrieveAutoFocusExport.py
Source:retrieveAutoFocusExport.py
...40def collect_events(helper, inputs, ew):41 helper.set_log_level('debug')42 sessionKey = inputs.metadata.get('session_key')43 # Get API KEY44 # helper.log_debug("Getting Autofocus APIKey from encrypted store")45 af_apikey = helper.get_global_setting("autofocus_api_key")46 # helper.log_debug(af_apikey)47 opt_labels = helper.get_arg('label')48 if hasattr(opt_labels, 'lower'):49 opt_labels = [opt_labels, ]50 # Loop through labels and call AF API to get entries.51 for label in opt_labels:52 helper.log_debug("Current Label: " + label)53 # Check if Label already exsist and get last submit date54 helper.log_debug("Getting AutoFocus Export for results")55 # Use API to get entries in Export List from AutoFocus56 values = {57 "apiKey": af_apikey,58 # "panosFormatted": "true",59 "exportMetadata": "true",60 "label": label61 }62 try:63 afapi = pan.afapi.PanAFapi(api_key=af_apikey)64 jsAfapi = afapi.export(json.dumps(values)).json65 af_export = jsAfapi['export_list']66 # helper.log_debug(jsAfapi)67 except pan.afapi.PanAFapiError as e:68 helper.log_debug(e)69 sys.exit(1)70 sync_kvstore = sync_to_kvstore(helper, sessionKey, label, af_export)71 helper.log_debug(sync_kvstore)72 # Label does not exsist in KVstore go ahead and batch import.73 if sync_kvstore == 1:74 helper.log_debug("New to KVSTORE")75 send_to_kvstore(helper, sessionKey, jsAfapi['export_list'])76 # Label does exsist in KVstore. Change Detected.77 elif sync_kvstore == -1:78 helper.log_debug("Update KVSTORE")79 # Delete entries for given label80 options = {81 "app": "Splunk_TA_paloalto",82 "owner": "nobody",83 "collection": "autofocus_export"84 }85 query = {"label": label}86 delete = True87 helper.log_debug("Delete entries for this label.")88 remove = KvStoreHandler.query(query, sessionKey, options, delete)89 helper.log_debug("Add entries with this label to kvstore")90 send_to_kvstore(helper, sessionKey, jsAfapi['export_list'])91 # NO CHANGE TO EXPORT LIST92 else:93 helper.log_debug("No Change")94def sync_to_kvstore(helper, sessionKey, label, af_export):95 helper.log_debug("checking KVSTORE")96 url_options = {97 "app": "Splunk_TA_paloalto",98 "owner": "nobody",99 "collection": "autofocus_export"100 }101 query = {"label": label}102 arg = {103 "query": query104 }105 response = KvStoreHandler.adv_query(arg, url_options, sessionKey)106 # helper.log_debug(response)107 results = 0108 kv_export = json.loads(response[1])109 # helper.log_debug("kv_export:")110 # helper.log_debug(kv_export)111 # helper.log_debug("af_export:")112 # helper.log_debug(af_export)113 # Check to see if we have entries in the KVstore already.114 if kv_export:115 helper.log_debug("Label Exist")116 # Check if list are same size117 if len(kv_export) == len(af_export):118 for entry in kv_export:119 # Remove fields from kv_export so dicts will match.120 if '_key' in entry:121 del(entry['_key'])122 if '_user' in entry:123 del(entry['_user'])124 if entry not in af_export:125 helper.log_debug("not a match")126 helper.log_debug(entry)127 results = -1128 return results129 else:130 helper.log_debug("Match")131 else:132 helper.log_debug("List count not same.")133 results = -1134 return results135 else:136 helper.log_debug("Label return empty")137 results = 1138 return results139def send_to_kvstore(helper, sessionKey, export_list):140 helper.log_debug("Inside Send to KVSTORE")141 url_options = {142 "app": "Splunk_TA_paloalto",143 "owner": "nobody",144 "collection": "autofocus_export"145 }146 helper.log_debug(export_list)147 response = KvStoreHandler.batch_create(export_list, sessionKey, url_options)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!