-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
118 lines (97 loc) · 3.34 KB
/
main.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
112
113
114
115
116
117
118
import dash
from dash.dependencies import Output, Input
from dash import dcc
from dash import html
import plotly
from selenium import webdriver
import threading
from bs4 import BeautifulSoup
import plotly.graph_objs as go
statistics = {"NaN":0}
def runi():
global statistics
driver = webdriver.Edge()
driver.get('https://www.pottersschool.org/gp7/#/login')
length = 0
tmp = 0
html = driver.page_source
# Parse HTML with BeautifulSoup
soup = BeautifulSoup(html, 'html.parser')
# Find all divs with class 'PUBLIC ng-star-inserted'
divs = soup.find_all('div', {'class': 'l-chat-history'})
while len(divs)==0:
html = driver.page_source
# Parse HTML with BeautifulSoup
soup = BeautifulSoup(html, 'html.parser')
divs = soup.find_all('div', {'class': 'l-chat-history'})
while True:
# Get page source
html = driver.page_source
# Parse HTML with BeautifulSoup
soup = BeautifulSoup(html, 'html.parser')
# Find all divs with class 'PUBLIC ng-star-inserted'
divs = soup.find_all('div', {'class': 'PUBLIC ng-star-inserted'})
length = len(divs)
if tmp != length:
try:
div = divs[length]
except:
div = divs[length - 1]
# Find spans within div
user_span = div.find('span', {'class': 'chat-msg-from ng-star-inserted'})
text_span = div.find('span', {'class': 'chat-msg-text'})
# Check if both spans are found
if user_span and text_span:
# Record username and message text
username = user_span.text.strip()
message_text = text_span.text.strip()
statistics[username.replace(":", "").split(" ")[0]] += 1
tmp = length
app = dash.Dash(__name__)
app.layout = html.Div(
[
dcc.Graph(id='live-graph', animate=True),
dcc.Interval(
id='graph-update',
interval=1000,
n_intervals=0
),
]
)
@app.callback(
Output('live-graph', 'figure'),
[Input('graph-update', 'n_intervals')]
)
def update_graph_scatter(n):
# Get page source
X = list(statistics.keys())
Y = list(statistics.values())
data = plotly.graph_objs.Bar(
x=list(statistics.keys()),
y=list(statistics.values()),
name="Messages Sent"
)
return {'data': [data],
'layout': go.Layout(xaxis=dict(range=[0, len(X)]), yaxis=dict(range=[0, max(Y, default=0)]), )}
if __name__ == '__main__':
choice1 = input("Do you want to load a student list file? [Y/n]")
if choice1.lower() == 'n':
print("Please enter your students' firstname one at a line. Please also enter your first name. Then, press Enter two times.")
while True:
n = input()
if n == "":
break
statistics[n] = 0
choice = input("Do you want to save this student list into a file? [Y/n]")
if choice.lower() == 'y':
name = input("Filename:")
open(name, 'w').writelines(list(statistics.keys()))
else:
name = input("Filename:")
students = open(name, 'r').readlines()
for x in students:
statistics[x.replace("\n","")] = 0
t=threading.Thread(target=runi)
t.start()
app.run_server()
t.join()