test.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. import inspect
  2. import utils
  3. from loguru import logger
  4. def get_stock_list():
  5. '''
  6. 闪购
  7. :return:
  8. '''
  9. url = "https://api.qiandao.com/c2c-web/v1/stock-order/bargin-v3"
  10. data = {
  11. "tagIds": [
  12. 1422849,
  13. 1132249,
  14. 1275579,
  15. 1622975,
  16. 1583218,
  17. 1706130,
  18. 1113003,
  19. 1000375,
  20. 1572324,
  21. 1436291,
  22. 1560387,
  23. 1276355,
  24. 1423075,
  25. 1583179,
  26. 42474,
  27. 324,
  28. 1446179,
  29. 1533642,
  30. 1542944,
  31. 1568717,
  32. 1572231,
  33. 1532176,
  34. 1506156,
  35. 1568683,
  36. 1541805,
  37. 1277151,
  38. 1529427,
  39. 1514792,
  40. 1515959,
  41. 1541749
  42. ],
  43. "withStockCount": 4
  44. }
  45. return utils.reuqest_post_data(url, data)
  46. def get_stock_tag_list(tag_id, sort):
  47. '''
  48. 闪购-按卡牌ID搜索
  49. :param tag_id: 卡片名称,比如:小马宝莉
  50. :param sort: 排序类型,0-最多人买,1-最低价格,2-最多在售,7-最新降价
  51. :return:
  52. '''
  53. url = "https://api.qiandao.com/stock-order/bargin"
  54. data = {
  55. "tagIds": [
  56. tag_id
  57. ],
  58. "sort": sort,
  59. "offset": 0,
  60. "limit": 10
  61. }
  62. return utils.reuqest_post_data(url, data)
  63. def get_spu_trading(spu_id):
  64. '''
  65. SPU一年成交
  66. :param spu_id:
  67. :return:
  68. '''
  69. url = "https://api.qiandao.com/c2c-web/v1/common/get-spu-trading-summary-by-time"
  70. data = {
  71. "spuId": spu_id,
  72. "tradingType": "EXCHANGE",
  73. "timeBucketWidth": "365 days"
  74. }
  75. return utils.reuqest_post_data(url, data)
  76. def get_spu_trading_history_list(spu_id, page):
  77. '''
  78. 分页采集SPU历史成交
  79. :param spu_id:
  80. :param page:
  81. :return:
  82. '''
  83. url = "https://api.qiandao.com/c2c-web/v1/common/get-spu-trading-history-list"
  84. limit = 20
  85. offset = (page - 1) * limit
  86. data = {
  87. "spuId": spu_id,
  88. "skuId": "0",
  89. "tradingType": "EXCHANGE",
  90. "limit": limit,
  91. "offset": offset
  92. }
  93. resp = utils.reuqest_post_data(url, data)
  94. return resp['data']
  95. def get_auctions_list(offest):
  96. url = "https://api.qiandao.com/c2c-web/v1/auctioneer/auctions/by-tags"
  97. data = {
  98. "tagIds": [
  99. "1405184",
  100. "1132249",
  101. "1000375",
  102. "49695",
  103. "1002041",
  104. "1540933",
  105. "1439689"
  106. ],
  107. "limit": 10,
  108. # "offset": 0,
  109. "offset": offest,
  110. "sort": "NewestBidTime"
  111. }
  112. return utils.request_post_data(logger, url, data)
  113. def get_auction_list_all_page():
  114. offest = 0
  115. while True:
  116. resp = get_auctions_list(offest)
  117. if not resp:
  118. break
  119. offest += 10
  120. logger.info(f'分页采集,{offest}:{resp}')
  121. def get_luckybag_list(offest):
  122. url = "https://api.qiandao.com/c2c-web/v1/luckybag/list"
  123. params = {
  124. "limit": "10",
  125. # "offset": "0",
  126. "offset": offest,
  127. "hostId": "228946998408215136",
  128. "orderBy": "updatedAt.desc",
  129. "tagIds": "1429578",
  130. "typeIds": "1405184,1132249,1000375,49695,1443553,1002041"
  131. }
  132. return utils.reuqest_get_data(url, params)
  133. def get_luckybag_list_all_page():
  134. offest = 0
  135. while True:
  136. resp = get_luckybag_list(offest)
  137. if not resp:
  138. break
  139. logger.info(f'分页采集,{offest}:{resp}')
  140. offest += 10
  141. def get_recommender_list():
  142. url = "https://api.qiandao.com/shelf-web/list-home-recommender"
  143. params = {
  144. "offset": 0,
  145. # "offset": offset,
  146. "limit": 20,
  147. "cmd": "b2c_homepage_feed",
  148. "name": "",
  149. "project": "",
  150. "recommendTagIds": [
  151. 49695,
  152. 1572285,
  153. 1542944,
  154. 1541805,
  155. 1515843,
  156. 1436291,
  157. 1422849,
  158. 1398583,
  159. 1132249,
  160. 1000375
  161. ],
  162. "fixedShelfId": 676864889976963108,
  163. "withLive": "true"
  164. }
  165. return utils.request_get_data(logger, url, params)
  166. def get_recommender_list_all_page():
  167. offset = 0
  168. while True:
  169. resp = get_recommender_list(offset)
  170. if not resp:
  171. break
  172. logger.info(f'分页采集,{offset}:{resp}')
  173. offset += 20
  174. def cw_list():
  175. url = 'https://api.qiandao.com/shelf-web/list-home-recommender'
  176. params = {
  177. 'offset': 0,
  178. 'limit': 20,
  179. 'cmd': 'b2c_homepage_feed',
  180. 'name': '',
  181. 'project': '',
  182. 'recommendTagIds': [
  183. 307, 682, 302, 305, 1163995, 50124, 303, 1153225, 525, 57703,
  184. 1285426, 313, 671, 589, 590, 10210, 1206, 1387773, 1424125,
  185. 1270645, 1285466, 42474
  186. ],
  187. 'fixedShelfId': 568851822601738191,
  188. 'withLive': 'true'
  189. }
  190. # params1 = {
  191. # 'offset': 0,
  192. # 'limit': 20,
  193. # 'cmd': 'b2c_homepage_feed',
  194. # 'name': '',
  195. # 'project': '',
  196. # "recommendTagIds": [
  197. # 15,1443323],
  198. # 'fixedShelfId': 568851822601738191,
  199. # 'withLive': 'true'
  200. # }
  201. # url = "https://api.qiandao.com/shelf-web/list-home-recommender"
  202. # params = {
  203. # "limit": '10',
  204. # "offset": '0',
  205. # "cmd": "b2c_homepage_feed",
  206. # "project": "channel",
  207. # "name": "manghe",
  208. # "type[]": [
  209. # "BLIND_BOX_MACHINE",
  210. # "KUJI",
  211. # "NEW_LUCKY_BAG",
  212. # "B2C"
  213. # ],
  214. # "typeIds": [15],
  215. # "channelId": '397228442736842784',
  216. # "screenName": "推荐"
  217. # }
  218. # # url = 'https://api.qiandao.com/shelf-web/list-home-recommender?limit=10&offset=0&cmd=b2c_homepage_feed&project=channel&name=manghe&type%5B%5D=BLIND_BOX_MACHINE&type%5B%5D=KUJI&type%5B%5D=NEW_LUCKY_BAG&type%5B%5D=B2C&typeIds%5B%5D=15&channelId=397228442736842784&screenName=%E6%8E%A8%E8%8D%90'
  219. # params = {
  220. # 'limit': '10',
  221. # 'offset': '0',
  222. # 'cmd': 'b2c_homepage_feed',
  223. # 'project': 'channel',
  224. # 'name': 'manghe',
  225. # 'type[]': ['BLIND_BOX_MACHINE', 'KUJI', 'NEW_LUCKY_BAG', 'B2C'],
  226. # 'typeIds[]': [15],
  227. # 'channelId': 397228442736842784,
  228. # 'screenName': '推荐'
  229. # }
  230. # url = "https://api.qiandao.com/shelf-web/list-home-recommender"
  231. # params = {
  232. # "offset": "40",
  233. # "limit": "20",
  234. # "cmd": "b2c_homepage_feed",
  235. # "name": "manghe",
  236. # "project": "channel",
  237. # "type": [
  238. # "BLIND_BOX_MACHINE",
  239. # "KUJI",
  240. # "NEW_LUCKY_BAG",
  241. # "B2C"
  242. # ],
  243. # "withLive": "true"
  244. # }
  245. return utils.request_get_data(logger, url, params)
  246. def zuzui111():
  247. url = "https://api.qiandao.com/box/live-groupon/group"
  248. params = {
  249. "shelfId": "866155019739620861"
  250. }
  251. response = utils.request_get_data(logger, url, params)
  252. print(response)
  253. def ttt():
  254. url = "https://api.qiandao.com/shelf-web/list-home-recommender"
  255. params = {
  256. "offset": "0",
  257. # "offset": str((page - 1) * 20),
  258. "limit": "20",
  259. "cmd": "b2c_homepage_feed",
  260. "name": "cgmarket",
  261. "project": "channel",
  262. # "type": "LIVE_GROUPON",
  263. "type": "",
  264. "typeIds": [1443323],
  265. "withLive": "true",
  266. "tagIds": [1572283],
  267. "quickCouponTemplateId": "0"
  268. }
  269. # cookies = {
  270. # "acw_tc": "0bca30fa17504130952641968e04896b05764741c46f0da6fec6561158ee4f"
  271. # }
  272. resp_json = utils.request_get_data(logger, url, params)
  273. print(resp_json)
  274. def rourou(log, page):
  275. url = "https://api.qiandao.com/c2c-web/v1/common/get-spu-trading-history-list"
  276. data = {
  277. "spuId": "654833013418492066",
  278. # "spuId": spu_id,
  279. "skuId": "0",
  280. # "tradingType": "EXCHANGE",
  281. "tradingType": "",
  282. "limit": "20",
  283. "offset": f"{(page - 1) * 20}"
  284. }
  285. resp_json = utils.request_post_data(log, url, data)
  286. print(resp_json)
  287. def paimai(log, page):
  288. url = "https://api.qiandao.com/c2c-web/v1/auctioneer/auctions/by-tags"
  289. data = {
  290. "tagIds": [
  291. "1405184",
  292. "1132249",
  293. "1000375",
  294. "49695",
  295. "1002041",
  296. "1540933",
  297. "1439689"
  298. ],
  299. "limit": "10",
  300. "offset": (page - 1) * 10,
  301. "filterOfficialCertification": False,
  302. "sort": "End"
  303. }
  304. resp_json = utils.request_post_data(log, url, data)
  305. print(resp_json)
  306. def kbs_detail_test(log, pid, sql_pool):
  307. url = "https://api.qiandao.com/box/kuji/query/detail"
  308. params = {
  309. # "id": "873770249084734603"
  310. "id": "774626078722365753"
  311. # "id": pid
  312. }
  313. resp_json = utils.request_get_data(log, url, params)
  314. print(resp_json)
  315. if resp_json.get("code") == 0:
  316. parse_card_bag_reward_details_data(log, resp_json, pid, sql_pool)
  317. else:
  318. log.error(f"{inspect.currentframe().f_code.co_name} error: {resp_json.get('message')}")
  319. def parse_card_bag_reward_details_data(log, resp_json, pid, sql_pool):
  320. log.debug(f"--------------- {inspect.currentframe().f_code.co_name} ---------------")
  321. data = resp_json.get("data")
  322. specification = data.get("packageConfigRamark") # 规格说明
  323. introImages = data.get('images', {}).get("introImages", [])
  324. introImages = '|'.join(introImages) # 多图链接, |分割
  325. # categoryId = data.get("categoryId")
  326. vipPrice = data.get("vipPrice")
  327. unitPriceOfCash = data.get("unitPriceOfCash")
  328. detail_dict = {
  329. # "pid": pid,
  330. "specification": specification,
  331. "images": introImages,
  332. # "category_id": categoryId,
  333. "unit_price_of_cash": unitPriceOfCash,
  334. "vip_price": vipPrice,
  335. }
  336. print(detail_dict)
  337. def kbs_list(log, sql_pool):
  338. url = "https://api.qiandao.com/shelf-web/list-home-recommender"
  339. params = {
  340. "offset": "0",
  341. # "offset": str((page - 1) * 20),
  342. "limit": "20",
  343. "cmd": "b2c_homepage_feed",
  344. "name": "cgmarket",
  345. "project": "channel",
  346. "type": "LIVE_GROUPON",
  347. "typeIds": [1443323],
  348. "withLive": "true",
  349. "tagIds": [1701791],
  350. "quickCouponTemplateId": "0"
  351. }
  352. resp_json = utils.request_get_data(log, url, params)
  353. print(resp_json)
  354. rows = resp_json["data"]["rows"]
  355. sql_pid_list = []
  356. parse_card_bag_reward_data(log, rows, sql_pool, sql_pid_list)
  357. def parse_card_bag_reward_data(log, resp_json, sql_pool, sql_pid_list):
  358. log.debug(f"--------------- {inspect.currentframe().f_code.co_name} ---------------")
  359. info_list = []
  360. for item in resp_json:
  361. # print(item)
  362. pid = item.get("id")
  363. if pid in sql_pid_list:
  364. log.debug(f"{inspect.currentframe().f_code.co_name}, pid: {pid} already exists")
  365. continue
  366. p_type = item.get("type")
  367. orgId = item.get("orgId")
  368. title = item.get("name")
  369. # description = item.get("description")
  370. isSoldOut = item.get("isSoldOut")
  371. price = item.get("price", {}).get("unitPriceOfCash")
  372. soldAmountText = item.get("soldAmountText")
  373. nickname = item.get("org", {}).get("nickname", '')
  374. info_dict = {
  375. "pid": pid,
  376. "p_type": p_type,
  377. "title": title,
  378. "price": price,
  379. "sold_amount_text": soldAmountText,
  380. "org_id": orgId,
  381. "nickname": nickname,
  382. # "description": description,
  383. "is_sold_out": isSoldOut
  384. }
  385. print(info_dict)
  386. def kbs_buy(log, pid):
  387. url = "https://api.qiandao.cn/b2c-web/v1/kuji/query/group/next"
  388. params = {
  389. # "shelfId": "776833910955877820"
  390. "shelfId": pid
  391. }
  392. token = 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Ijg2NTIxNTgzOTI0MDk4MzQ1NyIsInR5cGUiOiJVU0VSIiwiZGV2aWNlSWQiOiIxMDA2IiwiZXhwIjoxNzU3MjE0MDYwLCJpYXQiOjE3NTY5NTQ4NjB9.zhQ_mM74Q5apewGXoMXpGRR2O2bjVExSFOjj7gJzf59yM10pE02pOCqClj3H5YQu6t3UHTXdoiuWlumkpyFy3e7ujtdJFv2IBg25XIx24Eklxm6xWsTM7cTzNlq3QrB78IP74pRhu-XDNu3tCdukhjls5Uipe3_hrtPt9LZJUt48agIfAnApiIpGqsXD9V302Lr8fuigVclH-3DMh0YZElKyLrAV0PCWS65nr4INwKljQPtKj83co6N0Q3K_ntg8h5F68OIJf9Tgcome9LuT2_jvJ75n7Qnnr4AZiv9rQuum51ygeZtYiINPghd7zbEbL5L-oATB3xhT_MqR0NVWQg'
  393. resp_json = utils.request_get_data(log, url, params, token)
  394. # resp_json = utils.request_get_data(log, url, params)
  395. print(resp_json)
  396. # ----------------------------------------------------------------------------------------------------------------------
  397. # 潮玩
  398. def tttt(log, page_num, tag_id):
  399. url = "https://api.qiandao.cn/stock-order/bargin"
  400. data = {
  401. # "tagId": "682",
  402. "tagId": int(tag_id),
  403. "limit": 10,
  404. "offset": (page_num - 1) * 10,
  405. # "isWished": False,
  406. "sort": 0 # 最多人买
  407. }
  408. data = {
  409. "tagIds": [
  410. int(tag_id)
  411. ],
  412. "sort": 0, # 最多人买
  413. "offset": (page_num - 1) * 10,
  414. "limit": 10
  415. }
  416. resp_json = utils.request_post_data(log, url, data)
  417. print(resp_json)
  418. if __name__ == '__main__':
  419. kbs_buy(logger, '885836131847950829')
  420. # kbs_detail_test(logger, '11111', None)
  421. # kbs_list(logger, None)
  422. # ttt()
  423. # cw_list()
  424. # logger.info(f'闪购:{get_recommender_list()}')
  425. # logger.info(f'闪购:{cw_list()}')
  426. # page = 500
  427. # for i in range(1, page):
  428. # ttt(logger, i, 682)