Simple: Python_ Automatic body temperature clock

I'm cooking 2021-11-25 09:48:25
simple python_ python automatic body

Because the school has to clock in the temperature every day , Filling the body temperature also limits the time period ,0|==|_, So the top of the hour py coordination linux Of crontab, Realize automatic clock in ;
1, Caught analysis
It is found that automatic clock in requires login , Just type in your account and password ;

Grab the package analysis on the login page and find that post How to submit data , also cookie The field carries the account number ,JSESSIONID Etc :
 Insert picture description here

After successful login, three temperature fields are found , And check the time of filling in the body temperature :
 Insert picture description here
Click Submit button , Grab the bag again to analyze :
It is found that the packet contains the same... As the login packet cookie Information , And take post Mode submission json Formatted data , The data contains three main body temperature data morTem,noonTem,eveTem and Time of submission of the report reporttime;
 Insert picture description here If the packet is correct , After successful submission, return 200, And prompt that the modification is successful :
 Insert picture description here
Code implementation logic :
1, Just log in to cookie Value and in the logged in packet cookie Value consistent , You can go to py The login step is omitted from the code ;
2, Three body temperature variables correspond to three time periods , Use linux Of crontab Set three scheduled tasks to achieve ;
3,reporttime Fill in the temperature date for the day , year - month - Japan , Use py As a function of time ;

The implementation code is as follows ( For reference only py Use ):

#coding=utf-8
import requests
import json
import random
import time
# ==== cookie Raw data ; Global variables ==== 
cookie = [
"studentCode=11111( account number ); IDNo=1( password )",
"studentCode=22222; IDNo=3",
"studentCode=33333; IDNo=2"
]
studentCode = ''
IDNo = ''
JSESSIONID = 'djfasjfoijaoifjisajfirs'
# ==== Simple data processing ; Withdrawal account , password ====
def get_data(cookie):
global studentCode,IDNo
cookie = cookie.split(';')
studentCode = cookie[0].split('=')[1]
IDNo = cookie[1].split('=')[1]
#JSESSIONID = cookie[2].split('=')[1]
#print(studentCode,IDNo,JSESSIONID)
#=== Test login : This module can be omitted ===
def login():
url = " land URL"
headers = {

"Host": "www.xxx.com",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0",
"Accept": "*/*",
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
"Accept-Encoding": "gzip, deflate",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest",
"Content-Length": "40",
"Origin": "https://www.xxx.com",
"Connection": "close",
"Referer": "https://www.xxx.com/xxx/xxx",
"cookie": "studentCode=1111; IDNo=1; JSESSIONID=adljasijfdoijasfoi"
}
data = "studentCode=111&IDNo=1"
response = requests.post(url,data=data,headers=headers)
print(response.text)
#login()
#=== Fill in the temperature ====
def inp(studentCode,IDNo,JSESSIONID):
# Fill in the temperature URL
url2 = "https://www.xxx.com/xxx"
# http Packet header information , contain cookie Login free steps 
headers = {

"Host": "www.xxx.com",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0",
"Accept": "*/*",
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
"Accept-Encoding": "gzip, deflate",
"Content-Type": "application/json",
"X-Requested-With": "XMLHttpRequest",
"Content-Length": "499",
"Origin": "https://www.xxx.com",
"Connection": "close",
"Referer": "https://www.xxx.com/xxx",
"cookie": "studentCode={0}; IDNo={1}; JSESSIONID={2}".format(studentCode,IDNo,JSESSIONID)
}
# === Randomly generated body temperature ====
e = 36
d = int(random.uniform(0.4,0.7) * 10) /10
#print(a,b,c)
# === Get the time of the day ====
times = time.strftime("%Y-%m-%d",time.localtime())
print(times)
# http Packet request body , Fill in the temperature 
data = {
"studentCode":"{}".format(studentCode),
"classNo":"xxx",
"departmentCode":"02",
"depName":"xxx",
"acaID":"1",
"bodystatus":" normal ",
"animalHeat": None,
"address":"xxx School ",
"isContactHubeiBack":"0",
"isContactPatient":"0",
"othercase":"",
"reporttime":"{}".format(times),
"noonTem":"%s"%str(e+d),
"illsymptom": None,
"quarantine": None,
"quarantinePlace": None,
"outStartTime": None,
"outEndTime": None,
"vehicle": None,
"trainNumAndseatNum": None
}
# send out post request , The body of the request is json Format data 
response = requests.post(url2,headers=headers,json=data)
# Returns the data content encoding 
response.encoding = response.apparent_encoding
# printout 
print(response.text)
# Batch punch in 
for i in cookie:
get_data(i)
#print(studentCode,IDNo,JSESSIONID)
inp(studentCode,IDNo,JSESSIONID)

linux crontab Set timing task :
crontab -l -u root【 Or user name 】 # Lists scheduled tasks for the specified user
crontab -e # Set the scheduled task of the current user
Remember to restart every time the scheduled task is set crontab
systemctl restart cron

# The corresponding meaning of each parameter
# .---------------- branch (0 - 59)
# | .------------- when (0 - 23)
# | | .---------- God (1 - 31)
# | | | .------- month (1-12)
# | | | | .---- Zhou 1-7
# | | | | |
* * * * * Commands to perform tasks /command

take py Three copies of the code , Change the names of three body temperature variables , Set up three scheduled tasks , Use py3 Can run ( Be careful linux Time zone problem ,date Check the time zone , The general time zone is CST);
 Insert picture description here

版权声明
本文为[I'm cooking]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/11/20211109005248960A.html

  1. Python regular expression select Characters
  2. Object oriented composition of Python
  3. Python Software Development Directory
  4. Python package
  5. Python module
  6. Python is process oriented and functional
  7. Python generator
  8. Python iterator
  9. Python decorator
  10. Python function closure
  11. Python namespace and scope
  12. Python function
  13. Python file processing
  14. Python data type
  15. Process control of Python
  16. Garbage collection mechanism of Python
  17. Python: the field notes of dtype = 'object' can also be arranged in ascending and descending order
  18. . value in pandas_ Usage of counts()
  19. 202111 | some hands-on practice of Python time function
  20. 202111 | in Python, timestamp, time string and real date time are converted to each other
  21. Pandas draws line chart, bar chart and bar chart
  22. Exploration and practice of easy transformation between various data structures in Python
  23. A simple practice of Python list generation
  24. Use Python to guess the number of machines and judge the number of guesses
  25. Question about Python: did you learn Python
  26. 20210928 | Python case: building tax calculation function
  27. Python basic syntax collation
  28. Some small accumulation of writing programs in python (4)
  29. Some small accumulation of writing programs in python (3)
  30. Python leak detection tips (3)
  31. Python leak detection tips (2)
  32. Python leak detection tips (1)
  33. Python foundation and MySQL Foundation
  34. Some small accumulation of writing programs in python (2)
  35. Some small accumulation of writing programs in Python
  36. Python 3.7.3 + cuda9.2 installing Python
  37. Python knowledge used to write programs
  38. Python installation + vscode configuration Python environment
  39. Some small problems during Python installation
  40. Answer and Q & A of Python practice introduction course
  41. Sorting out the learning route for Python beginners
  42. The 6-line Python code uses the pdf2docx module converter object to convert PDF into docx file
  43. Batch compression of picture files using Python
  44. Using Python to write djikstra algorithm for robot path planning
  45. python实现手机号获取短信验证码 | 对接打码平台
  46. Detailed explanation of Euler Rodriguez code in Python
  47. Prove that angular displacement is not a vector with Python
  48. Using Python program to deeply understand homogeneous transfer matrix t
  49. Triple product formula of vector and its proof (with Python code)
  50. Derivation of differential formula of DH matrix using Python
  51. Python openpyxl operation on Excel (get the total number of columns, get the value of a row, get the value of a column, and set the cell value)
  52. Realizing Excel data filtering and data matching with Python
  53. Python reads and writes files
  54. Four scenarios of processing Excel files with Python
  55. Python converts dictionary to excel
  56. Python implements file reading and writing
  57. Basic Python syntax -- functions
  58. Python learning thinking
  59. Basic Python syntax -- lists, dictionaries
  60. Python basic syntax -- conditional judgment, input ()