liuyuqi-dellpc 1 year ago
commit
9d0d3b31ea
6 changed files with 152 additions and 0 deletions
  1. 27 0
      README.md
  2. 6 0
      jd/config.ini
  3. 30 0
      jd/jd_seckill.py
  4. 26 0
      jd/main.py
  5. 62 0
      jd/timer.py
  6. 1 0
      requirements.txt

+ 27 - 0
README.md

@@ -0,0 +1,27 @@
+# crawl-maotai
+
+模拟抢购可以有很多方法:
+
+    1、集成 Chrome web开发插件,自动执行某些操作
+    2、Python 脚本模拟 API 登录/提交表单操作
+    3、通过 root 的 android 手机,在指定位置插桩。
+
+## 环境搭建
+
+```
+
+```
+
+## 京东抢购教程
+
+
+
+## 天猫抢购教程
+
+天猫web端限制比较严格,所以采用模拟app操作。
+
+
+
+
+## 苏宁抢购教程
+

+ 6 - 0
jd/config.ini

@@ -0,0 +1,6 @@
+eid=""
+fp=""
+
+sku_id=""
+
+buy_time=""

+ 30 - 0
jd/jd_seckill.py

@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2020/12/31 16:16:19
+@License :   Copyright © 2017-2020 liuyuqi. All Rights Reserved.
+@Desc    :   
+'''
+import os, sys, re
+import time, random, requests, json
+
+class JDSeckill():
+    def __init__(self):
+        self.cookiePath = "./cookies"
+        self.userAgent = ""
+        self.session = requests.session()
+        
+    
+
+    def reserve(self,):
+        '''
+        预定
+        '''
+        pass
+
+    def buy(self,):
+        '''
+        抢购
+        '''
+        pass

+ 26 - 0
jd/main.py

@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2020/12/31 15:27:03
+@License :   Copyright © 2017-2020 liuyuqi. All Rights Reserved.
+@Desc    :   京东茅台抢购入口
+选项:
+    1、预约
+    2、秒杀抢购
+'''
+import os
+import sys
+import re
+import jd_seckill
+
+if __name__ == "__main__":
+    jd = jd_seckill.JDSeckill()
+    userchoose = input("功能选择:")
+    if userchoose == "1":
+        jd.reserve()
+    elif userchoose == "2":
+        jd.buy()
+    else:
+        print("请输入数字: 1或2")
+        sys.exit(1)

+ 62 - 0
jd/timer.py

@@ -0,0 +1,62 @@
+# -*- coding:utf-8 -*-
+import time
+import requests
+import json
+
+from datetime import datetime
+
+
+class Timer(object):
+    def __init__(self, sleep_interval=0.5):
+        # '2018-09-28 22:45:50.000'
+        # buy_time = 2020-12-22 09:59:59.500
+        buy_time_everyday = global_config.getRaw('config', 'buy_time').__str__()
+        localtime = time.localtime(time.time())
+        self.buy_time = datetime.strptime(
+            localtime.tm_year.__str__() + '-' + localtime.tm_mon.__str__() + '-' + localtime.tm_mday.__str__()
+            + ' ' + buy_time_everyday,
+            "%Y-%m-%d %H:%M:%S.%f")
+        self.buy_time_ms = int(time.mktime(self.buy_time.timetuple()) * 1000.0 + self.buy_time.microsecond / 1000)
+        self.sleep_interval = sleep_interval
+
+        self.diff_time = self.local_jd_time_diff()
+
+
+
+    def jd_time(self):
+        """
+        从京东服务器获取时间毫秒
+        :return:
+        """
+        url = 'https://a.jd.com//ajax/queryServerData.html'
+        ret = requests.get(url).text
+        js = json.loads(ret)
+        return int(js["serverTime"])
+
+    def local_time(self):
+        """
+        获取本地毫秒时间
+        :return:
+        """
+        return int(round(time.time() * 1000))
+
+    def local_jd_time_diff(self):
+        """
+        计算本地与京东服务器时间差
+        :return:
+        """
+        return self.local_time() - self.jd_time()
+
+    def start(self):
+        while True:
+            # 本地时间减去与京东的时间差,能够将时间误差提升到0.1秒附近
+            # 具体精度依赖获取京东服务器时间的网络时间损耗
+            if self.local_time() - self.diff_time >= self.buy_time_ms:
+                break
+            else:
+                time.sleep(self.sleep_interval)
+
+
+if __name__ == "__main__":
+    timer = Timer()
+    print(timer.buy_time)

+ 1 - 0
requirements.txt

@@ -0,0 +1 @@
+certifi