当前位置: 移动技术网 > IT编程>脚本编程>Python > 基于python3.7的一个闯越自动签到脚本--demo版

基于python3.7的一个闯越自动签到脚本--demo版

2019年06月11日  | 移动技术网IT编程  | 我要评论

撸师爷影音先锋,住房按揭贷款计算器,爱我网

望指正demo的定位,有时候会抽风无法接受我的定位信息

  1 #! /usr/bin/python3
  2 # -*- coding:utf-8 -*-
  3 # time : 2019/5/20  20:53
  4 # file : chuangyue.py
  5 # by 卤蛋
  6 from urllib.parse import quote
  7 import datetime
  8 import requests
  9 import calendar
 10 import sys
 11 import time
 12 import random
 13 import urllib3
 14 urllib3.disable_warnings(urllib3.exceptions.insecurerequestwarning)
 15 
 16 request = requests.session()
 17 
 18 d = datetime.datetime.now()
 19 
 20 stateid = 3
 21 
 22 index_html = __file__.replace("requestforch.py", "") + ""
 23 index_img = __file__.replace("requestforch.py", "") + "index.jpg"
 24 
 25 useragent_list = [r"mozilla/5.0 (linux; android 8.1.0; redmi 6 build/o11019; wv) " +
 26                   r"applewebkit/537.36 (khtml, like gecko) version/4.0 chrome/71.0.3578.99 mobile safari/537.36",
 27                   r"mozilla/5.0 (linux; android 4.1.1; nexus 7 build/jro03d) applewebkit/535.19 (khtml, like gecko) chrome/18.0.1025.166 safari/535.19",
 28                   r"mozilla/5.0 (linux; u; android 4.0.4; en-gb; gt-i9300 build/imm76d) applewebkit/534.30 (khtml, like gecko) version/4.0 mobile safari/534.30",
 29                   r"mozilla/5.0 (linux; u; android 6.2; en-gb; gt-p1000 build/froyo) applewebkit/533.1 (khtml, like gecko) version/4.0 mobile safari/533.1"]
 30 
 31 with open(__file__.replace("requestforch.py", "") + r'cookie.txt', 'r') as file:
 32     cookie = file.read()
 33 cookies = {}  # 初始化cookies字典变量
 34 for line in cookie.split(';'):  # 按照字符:进行划分读取
 35     # 其设置为1就会把字符串拆分成2份
 36     name, value = line.strip().split('=', 1)
 37     cookies[name] = value  # 为字典cookies添加内容
 38 
 39 
 40 def useragent():
 41     return useragent_list[random.randint(0, len(useragent_list)-1)]
 42 
 43 
 44 def locationstateadd(userid):
 45     headers = {
 46         "content-type": "application/x-www-form-urlencoded",
 47         "host": "sqg.cydgsx.com",
 48         "connection": "keep-alive",
 49         "accept-encoding": "gzip",
 50         "user-agent": "okhttp/3.10.0",
 51     }
 52     data = {"params": str({"state": stateid, "user_id": userid})}
 53     response = request.get(
 54         url="https://sqg.cydgsx.com/locationstateadd",
 55         headers=headers,
 56         data=data,
 57         timeout=60,
 58         verify=false)
 59     return response.json()
 60 
 61 
 62 def studentlocationadd(userid):
 63     headers = {
 64         "content-type": "application/x-www-form-urlencoded",
 65         "host": "sqg.cydgsx.com",
 66         "connection": "keep-alive",
 67         "accept-encoding": "gzip",
 68         "user-agent": r"okhttp/3.10.0",
 69     }
 70     data = {"params": '{"address":"中国广东省广州市海珠区","latitude":"23.09610289210092","longitude":"113.33666163412784","user_id":%s}' % userid}
 71     response = request.post(
 72         url="https://sqg.cydgsx.com/studentlocationadd",
 73         data=data,
 74         headers=headers,
 75         timeout=60,
 76         verify=false)
 77     print("定位:",response.text)
 78     for key, value in response.json().items():
 79         if value == "成功" and key == "meg":
 80             return true
 81     return false
 82 
 83 
 84 def index(url="https://sqg.cydgsx.com/m/s/log/index"):
 85     headers = {
 86         "host": "sqg.cydgsx.com",
 87         "connection": "keep-alive",
 88         "upgrade-insecure-requests": "1",
 89         "user-agent": useragent(),
 90         "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
 91         "referer": url,
 92         "accept-encoding": "gzip, deflate",
 93         "accept-language": "zh-cn,en-us;q=0.9",
 94         "x-requested-with": "com.gcykj.boss",
 95     }
 96     temp_cookies = {"chref": url}
 97     temp_cookies.update(cookies)
 98     response = request.get(
 99         url=url,
100         headers=headers,
101         cookies=temp_cookies,
102         timeout=60,
103         verify=false)
104     html = response.text.replace('href="', 'href="https://sqg.cydgsx.com').replace("'get','", "'get','https://sqg.cydgsx.com").replace(r'src="', 'src="https://sqg.cydgsx.com')
105     with open(index_html, "w", encoding='utf-8') as file:
106         file.write(html)
107     print(locationstateadd(cookies["loginuser_id"].split("&")[0]))  # 等待服务器添加定位
108     # studentlocationadd(cookies["loginuser_id"].split("&")[0])  # 添加定位
109     return studentlocationadd(cookies["loginuser_id"].split("&")[0])  # 添加定位
110 
111 
112 def day(string=d.strftime('%y-%m-%d')):
113 
114     if d.day == getmonthfirstdayandlastday()[1].day:
115         month(d.strftime('%y-%m-%d') + "\n无人值守\n" + "每月小结")
116     elif d.weekday() == 6:
117         week(d.strftime('%y-%m-%d') + "\n无人值守\n" + "每周周报")
118     headers = {
119         "host": "sqg.cydgsx.com",
120         "user-agent": useragent(),
121         "referer": "https://sqg.cydgsx.com/m/s/log/wlog",
122         "accept-encoding": "gzip, deflate",
123         "accept-language": "zh-cn,en-us;q=0.9",
124         "accept": "application/json",
125         "origin": "https://sqg.cydgsx.com",
126         "x-requested-with": "xmlhttprequest",
127         "connection": "keep-alive",
128         "content-type": "application/x-www-form-urlencoded"
129     }
130 
131     data = {"internstateid": stateid,
132             "intercontent": quote(string, 'utf-8'),
133             "logimg": "",
134             "newlogimg": "",
135             "posaddress": "",
136             "poslong": "",
137             "poslati": ""}
138     response = request.post(
139         url="https://sqg.cydgsx.com/m/s/log/savewritelog",
140         data=data,
141         headers=headers,
142         cookies=cookies,
143         timeout=60,
144         verify=false)
145     for key, value in response.json().items():
146         if value == "成功" and key == "meg":
147             print("每日小结: ",response.json())
148             return true
149     return false
150 
151 
152 def week(string=d.strftime('%y-%m-%d')):
153     if d.weekday() != 6:
154         return false
155     else:
156         headers = {
157             "host": "sqg.cydgsx.com",
158             "connection": "keep-alive",
159             "accept": "application/json",
160             "origin": "https://sqg.cydgsx.com",
161             "x-requested-with": "xmlhttprequest",
162             "user-agent": useragent(),
163             "content-type": "application/x-www-form-urlencoded",
164             "referer": "https://sqg.cydgsx.com/m/s/log/wweeksmy?date={}".format(d.strftime('%y-%m-%d')),
165             "accept-encoding": "gzip, deflate",
166             "accept-language": "zh-cn,en-us;q=0.9",
167         }
168         data = {
169             "summaryinfo": string,
170             "logimg": "",
171             "newlogimg": "",
172             "smydate": quote(d.strftime('%y/%m/%d'),
173                              'utf-8').replace("2f05%",
174                                               "2f5%") + "+" + quote("0:00:00", 'utf-8'),
175             "summarytype": "周小结",
176         }
177         response = request.post(
178             url="https://sqg.cydgsx.com/m/s/log/savesmyjson",
179             data=data,
180             headers=headers,
181             cookies=cookies,
182             timeout=60,
183             verify=false)
184 
185         for key, value in response.json().items():
186             if value == "成功" and key == "meg":
187                 print("每周小结: ",response.json())
188                 return true
189     return false
190 
191 
192 def month(string=d.strftime('%y-%m-%d')):
193     if d.day != getmonthfirstdayandlastday()[1].day:
194         return false
195     else:
196         headers = {
197             "host": "sqg.cydgsx.com",
198             "connection": "keep-alive",
199             "accept": "application/json",
200             "origin": "https://sqg.cydgsx.com",
201             "x-requested-with": "xmlhttprequest",
202             "user-agent": useragent(),
203             "content-type": "application/x-www-form-urlencoded",
204             "referer": "https://sqg.cydgsx.com/m/s/log/wmonthsmy?date={}".format(d.strftime('%y-%m-%d')),
205             "accept-encoding": "gzip, deflate",
206             "accept-language": "zh-cn,en-us;q=0.9",
207         }
208 
209         data = {
210             "summaryinfo": string,
211             "logimg": "",
212             "newlogimg": "",
213             "smydate": quote(d.strftime('%y/%m/%d'),
214                              'utf-8').replace("%2f0", "%2f") + "+" + quote("22:32:00", 'utf-8'),
215             "summarytype": "月小结",
216         }
217         response = request.post(
218             url="https://sqg.cydgsx.com/m/s/log/savesmyjson",
219             data=data,
220             headers=headers,
221             cookies=cookies,
222             timeout=60,
223             verify=false)
224 
225         for key, value in response.json().items():
226             if value == "成功" and key == "meg":
227                 print("每月小结: ",response.json())
228                 return true
229     return false
230 
231 
232 def getmonthfirstdayandlastday(year=none, month=none):
233     if year:
234         year = int(year)
235     else:
236         year = datetime.date.today().year
237 
238     if month:
239         month = int(month)
240     else:
241         month = datetime.date.today().month
242 
243     firstdayweekday, monthrange = calendar.monthrange(year, month)
244 
245     return [
246         datetime.date(
247             year=year,
248             month=month,
249             day=1),
250         datetime.date(
251             year=year,
252             month=month,
253             day=monthrange)]
254 
255 
256 def main(data=""):
257     def setlog(data):
258         if sys.argv[1] == "day":
259             return day(data + "每日日志")
260         elif sys.argv[1] == "week":
261             return week(data + "每周周报")
262         elif sys.argv[1] == "month":
263             return month(data + "每月小结")
264     if len(sys.argv) > 2:
265         return setlog("".join(sys.argv[2:]))
266     elif len(sys.argv) > 1:
267         return setlog(data)
268     else:
269         return day(data + "每日日志")
270 
271 
272 if __name__ == '__main__':
273     print("##"*20)
274     # index("https://sqg.cydgsx.com/m/s/home/index")
275     if main(d.strftime('%y-%m-%d') + "\n无人值守\n"):
276         print(d.strftime('%y-%m-%d %h:%m:%s') + "\t成功写入日志")
277         print(index("https://sqg.cydgsx.com/m/s/log/index"))
278     else:
279         print(d.strftime('%y-%m-%d %h:%m:%s') + "\n写入日志失败")
280     print("==" * 20 + "\n闯越自动写日志系统(更新版)\tby:卤蛋 \n2019.05.20·05.31\n" + "==" * 20)
281     print("##"*20)

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网