Добавил класс Users для сбора логинов и паролей из папки data

This commit is contained in:
Noretsa 2020-06-17 17:39:58 +03:00
parent 4545cce5be
commit 62b927a5c0
7 changed files with 50 additions and 13 deletions

0
classes/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

26
classes/users.py Normal file
View File

@ -0,0 +1,26 @@
import os
class Users:
def __init__(self):
self.data = []
self.path = os.path.join(os.path.abspath('.'), 'data')
def get_users(self):
self.logins = []
main_dir = os.walk(self.path)
for d, dirs, files in main_dir:
self.logins.append(dirs)
return self.logins[0]
def get_passwords(self):
if not os.path.exists(self.path):
return "Папка data не существует. Создайте папку с необходимыми параметрами и запустите программу снова!"
self.emails = self.get_users()
for user in self.emails:
with open(os.path.join(self.path, user, 'pass.txt'), 'r') as f:
log_pass = {'email': user, 'password': f.readline().split('\n')[0]}
self.data.append(log_pass)
return self.data

View File

@ -0,0 +1 @@
kn2001

View File

@ -0,0 +1 @@
kn9172

View File

@ -3,6 +3,8 @@ import random
import string import string
import json import json
import time import time
from classes.users import Users
# anwer_text = '{"question_chains":[{"id":6145,"questions":[{"id":6559,"question_components":[{"id":18850,"answer":[80634165],"answer_status":null,"end_time":1591866979,"start_time":1591866978},{"id":18851,"answer":{"location":[56.439337,36.557897]},"answer_status":null,"start_time":1591866873,"end_time":1591867165},{"id":18852,"answer":"1","answer_status":null,"start_time":1591867063,"end_time":1591867063}]}]},{"id":6147,"questions":[{"id":6561,"question_components":[{"id":18856,"answer":77,"answer_status":null,"end_time":1591867067,"start_time":1591867067},{"id":18857,"answer":[80639138],"answer_status":null,"end_time":1591867186,"start_time":1591867185}]}]},{"id":6147,"questions":[{"id":6561,"question_components":[{"id":18856,"answer":77,"answer_status":null,"end_time":1591867200,"start_time":1591867200},{"id":18857,"answer":[80639640],"answer_status":null,"end_time":1591867206,"start_time":1591867205}]}]},{"id":6147,"questions":[{"id":6561,"question_components":[{"id":18856,"answer":77,"answer_status":null,"end_time":1591867211,"start_time":1591867211},{"id":18857,"answer":[80640010],"answer_status":null,"end_time":1591867220,"start_time":1591867219}]}]},{"id":6147,"questions":[{"id":6561,"question_components":[{"id":18856,"answer":77,"answer_status":null,"end_time":1591867223,"start_time":1591867223},{"id":18857,"answer":[80640333],"answer_status":null,"end_time":1591867233,"start_time":1591867232}]}]}]}' # anwer_text = '{"question_chains":[{"id":6145,"questions":[{"id":6559,"question_components":[{"id":18850,"answer":[80634165],"answer_status":null,"end_time":1591866979,"start_time":1591866978},{"id":18851,"answer":{"location":[56.439337,36.557897]},"answer_status":null,"start_time":1591866873,"end_time":1591867165},{"id":18852,"answer":"1","answer_status":null,"start_time":1591867063,"end_time":1591867063}]}]},{"id":6147,"questions":[{"id":6561,"question_components":[{"id":18856,"answer":77,"answer_status":null,"end_time":1591867067,"start_time":1591867067},{"id":18857,"answer":[80639138],"answer_status":null,"end_time":1591867186,"start_time":1591867185}]}]},{"id":6147,"questions":[{"id":6561,"question_components":[{"id":18856,"answer":77,"answer_status":null,"end_time":1591867200,"start_time":1591867200},{"id":18857,"answer":[80639640],"answer_status":null,"end_time":1591867206,"start_time":1591867205}]}]},{"id":6147,"questions":[{"id":6561,"question_components":[{"id":18856,"answer":77,"answer_status":null,"end_time":1591867211,"start_time":1591867211},{"id":18857,"answer":[80640010],"answer_status":null,"end_time":1591867220,"start_time":1591867219}]}]},{"id":6147,"questions":[{"id":6561,"question_components":[{"id":18856,"answer":77,"answer_status":null,"end_time":1591867223,"start_time":1591867223},{"id":18857,"answer":[80640333],"answer_status":null,"end_time":1591867233,"start_time":1591867232}]}]}]}'
@ -90,19 +92,26 @@ def get_task(session, headers):
def main(): def main():
session = requests.Session() users = Users()
login = { logins = users.get_passwords()
'email': 'domreshetnikovo@gmail.com', if isinstance(logins, list):
'password': 'kn2001' url = 'https://knd.mosreg.ru//api/v1/auth/sign_in'
} for user in logins:
url = 'https://knd.mosreg.ru//api/v1/auth/sign_in' session = requests.Session()
response = session.post(url, data=login) login = {
headers = { 'email': user['email'],
'client': response.headers.get('client'), 'password': user['password']
'Access-token': response.headers.get('Access-token'), }
'uid': response.headers.get('uid'), response = session.post(url, data=login)
} headers = {
get_task(session, headers) 'client': response.headers.get('client'),
'Access-token': response.headers.get('Access-token'),
'uid': response.headers.get('uid'),
}
print(headers)
time.sleep(1)
else:
print(users.get_passwords())
if __name__ == "__main__": if __name__ == "__main__":