-
Notifications
You must be signed in to change notification settings - Fork 0
/
classspider.py
executable file
·111 lines (85 loc) · 3.77 KB
/
classspider.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# !/usr/bin/env python
# -*- coding: utf-8 -*-
from config import ClassConfig
from selenium import webdriver
from pyvirtualdisplay import Display
class ClassSpider(object):
def __init__(self, account):
"""Конструктор класса подключает библиотеку Firefox и подключает модуль
парсинга конфига"""
self.account = account
self.config = ClassConfig(account)
self.vdisplay = Display(visible=0, size=(1680, 1050))
self.vdisplay.start()
self.driver = webdriver.Firefox()
self.base_url = "http://aori.ru/"
def __del__(self):
"""Деструктор класса закрывает вкладку браузера"""
self.driver.close()
self.vdisplay.stop()
def foo_login(self):
"""Метод логина"""
self.driver.get(self.base_url + 'mainpage1/login/?')
self.driver.switch_to.frame('auth_frame')
elem_login = self.driver.find_element_by_id('login')
elem_login.send_keys(self.config.settings()['login'])
elem_pass = self.driver.find_element_by_id('password')
elem_pass.send_keys(self.config.settings()['password'])
self.driver.find_element_by_css_selector('button.buttonOrange').click()
self.driver.switch_to.default_content()
cookie = {'name': 'foo', 'value': 'bar'}
self.driver.add_cookie(cookie)
def foo_balance(self):
"""Метод получения баланса аккаунта"""
self.driver.get_cookies()
self.driver.get(self.base_url + 'app/#/balance/payment')
self.driver.implicitly_wait(10)
monye_account = self.driver.find_element_by_xpath(
'/html/body/div[3]/div[1]/div[2]/div/div/div/div[2]/div[1]/div/span').text
monye_loose = self.driver.find_element_by_xpath(
'/html/body/div[3]/div[1]/div[2]/div/div/div/div[2]/div[3]/span').text
self.driver.get(self.base_url + 'app/#/campaigns')
self.driver.implicitly_wait(10)
acting = self.driver.find_element_by_xpath(
'/html/body/div[3]/div[1]/div[2]/div/div/div/div[1]/div[1]/span[1]').text
inacting = self.driver.find_element_by_xpath(
'/html/body/div[3]/div[1]/div[2]/div/div/div/div[1]/div[1]/span[2]').text
with open(self.config.path() + 'report.txt', 'a') as f:
f.write(
'''<strong>{0}</strong><br>\n
<span style="color:rgb(50,144,209);font-family:Arial;font-size:28px">{1} RUB</span>/
<span style="color:rgb(36,113,182);font-size:28px;line-height:normal">{2} RUB</span><br>
{3}/{4}<br><br\n'''.format(
self.config.settings()['login'], monye_account, monye_loose, acting, inacting))
f.close()
self.driver.delete_all_cookies()
def foo_account(self):
a = list(self.config.accounts().keys())
return a
def test_login():
"""Метод тестирования логина"""
c = ClassSpider(account='account_imperiasky')
c.foo_login()
def test_balance():
"""Метод тестирования баланса"""
c = ClassSpider(account='account_imperiasky')
c.foo_login()
c.foo_balance()
def test_account():
"""Метод тестирования функции account"""
c = ClassSpider(account='account_imperiasky')
c.foo_login()
c.foo_account()
def start_bot():
config = ClassConfig(account='')
c = ClassSpider(account='')
list_accounts = c.foo_account()
with open(config.path() + 'report.txt', 'w') as f:
pass
f.close()
for account in list_accounts:
c = ClassSpider(account)
print(account)
c.foo_login()
c.foo_balance()
start_bot()