-
Notifications
You must be signed in to change notification settings - Fork 1
/
SakitoScrap.py
108 lines (96 loc) · 3.84 KB
/
SakitoScrap.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
# File name : SakitoScrap.py
# Author : Hayato Doi
# Outline : Sakitoの自動化を行うクラス
# license : MIT
# Copyright (c) 2017, Hayato Doi
import requests
from bs4 import BeautifulSoup
import re
class SakitoScrap:
def __init__(self, email:str, password:str):
self.email = email
self.password = password
self.__session = self.__login()
def __login(self):
s = requests.Session()
# get authenticity_token
response = s.get('https://sakito.cirkit.jp/user/sign_in')
soup = BeautifulSoup(response.text, 'html.parser')
authenticity_token = soup.body.findAll('form')[0].find(attrs={'name':'authenticity_token'})['value']
# login
login_payload = {
'utf8': '✓',
'authenticity_token': authenticity_token,
'user[email]': self.email,
'user[password]': self.password,
'user[remember_me]': '0',
'commit': 'ログイン'
}
s.post('https://sakito.cirkit.jp/user/sign_in', data=login_payload)
return s
def getPoint(self):
s = self.__session
response = s.get('https://sakito.cirkit.jp/user')
soup = BeautifulSoup(response.text, 'html.parser')
return int(soup.body.findAll('h1')[0].string)
def getExchangePoint(self):
s = self.__session
response = s.get('https://sakito.cirkit.jp/user/prizes')
soup = BeautifulSoup(response.text, 'html.parser')
pointsPer4 = soup.body.findAll('h4')[-1].string
points = re.match(r"\d{1,}", pointsPer4).group(0)
return int(points)
def getBonusPoint(self):
s = self.__session
response = s.get('https://sakito.cirkit.jp/user')
soup = BeautifulSoup(response.text, 'html.parser')
return int(soup.body.findAll('h1')[1].string)
def checkNewQuestion(self):
s = self.__session
response = s.get('https://sakito.cirkit.jp/surveys')
soup = BeautifulSoup(response.text, 'html.parser')
newQuestionList = []
for row in soup.body.findAll(attrs={'class':'panel-success'}):
if( row.find(attrs={'class':'panel-footer'}).text == '回答する' ):
newQuestionList.append( row.find(attrs={'class':'panel-heading'}).text )
return newQuestionList
def gacha(self):
s = self.__session
response = s.get('https://sakito.cirkit.jp/user/point/new')
soup = BeautifulSoup(response.text, 'html.parser')
authenticity_token = soup.head.find(attrs={'name':'csrf-token'})['content']
gacha_payload = {
'_method': 'post',
'authenticity_token': authenticity_token,
}
response = s.post('https://sakito.cirkit.jp/user/point', data=gacha_payload)
def prizeGacha(self):
s = self.__session
response = s.get('https://sakito.cirkit.jp/user/prizes/new')
soup = BeautifulSoup(response.text, 'html.parser')
authenticity_token = soup.head.find(attrs={'name':'csrf-token'})['content']
gacha_payload = {
'_method': 'post',
'authenticity_token': authenticity_token,
}
response = s.post('https://sakito.cirkit.jp/user/prizes', data=gacha_payload)
def bonusGacha(self):
s = self.__session
response = s.get('https://sakito.cirkit.jp/user/bonus_point/new')
soup = BeautifulSoup(response.text, 'html.parser')
authenticity_token = soup.head.find(attrs={'name':'csrf-token'})['content']
gacha_payload = {
'_method': 'post',
'authenticity_token': authenticity_token,
}
response = s.post('https://sakito.cirkit.jp/user/bonus_point', data=gacha_payload)
def prizeExchange(self):
s = self.__session
response = s.get('https://sakito.cirkit.jp/user/prizes')
soup = BeautifulSoup(response.text, 'html.parser')
authenticity_token = soup.head.find(attrs={'name':'csrf-token'})['content']
gacha_payload = {
'_method': 'put',
'authenticity_token': authenticity_token,
}
response = s.post('https://sakito.cirkit.jp/user/prizes/exchange', data=gacha_payload)