An automatic sign in system.
Clone to local directory, and create a new file app.py
in it.
from main import SigninX
sx = SigninX(database='data.db')
sx.add('siteName', {
'method': 'get',
'url': 'https://example.com/signin',
'result': 'res.json()',
'data': {
'data1': 'value1',
'data2': 'value2',
...
},
'params': {
'param1': 'value1',
'param2': 'value2',
...
},
'login': {
'method': 'post',
'url': 'https://example.com/login',
'data': {
...
},
'params': {
...
}
}
})
sx.start()
print(sx.schedule)
Create a new file custom.py
in the same directory.
from base import *
class SX_siteName(BaseSignin):
def __init__(self, name, args, sx=None, maxRetry=10):
super().__init__(name, args, sx, maxRetry)
def beforeSI(self):
# Do something before signin
self.args['data']['param3'] = 'value3'
def login():
# M1
from requests import post
res = post(...)
# M2
self.args['login']['data3'] = 'value3'
res = self.req(self.args['login'])
# After login successfully, call these to save cookies
self.setCookies(res)
self.save()
# Or
self.args['login']['data3'] = 'value3'
super().login()
def verify(self, rzt):
from time import localtime
if localtime().tm_hour < 8:
raise NotTimeYet
if isinstance(rzt, str):
raise NotLogin
and in app.py
, add parameter custom:
sx = SigninX(database='data.db', custom='custom')