Page Menu
Home
Miraheze
Search
Configure Global Search
Log In
Paste
P384
resp_time.py
Active
Public
Actions
Authored by
Paladox
on Feb 9 2021, 23:17.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Flag For Later
Award Token
Tags
None
Referenced Files
F1391153: resp_time.py
Feb 9 2021, 23:17
2021-02-09 23:17:10 (UTC+0)
Subscribers
None
#! /usr/bin/python3
import
requests
,
time
,
re
,
sqlite3
,
datetime
start
=
time
.
perf_counter
()
response
=
requests
.
get
(
'http://localhost:8085/wiki/Miraheze'
,
headers
=
{
'Host'
:
'meta.miraheze.org'
})
end
=
time
.
perf_counter
()
total_elapsed
=
round
((
end
-
start
)
*
1000
)
if
response
.
status_code
==
200
:
rematch
=
re
.
search
(
r"\"
wgBackendResponseTime
\
":\d+"
,
response
.
text
)
mediawiki_elapsed
=
int
(
rematch
.
group
(
0
)
.
split
(
':'
)[
1
])
try
:
sqlite3conn
=
sqlite3
.
connect
(
'/home/southparkfan/resp_time.db'
,
detect_types
=
sqlite3
.
PARSE_DECLTYPES
|
sqlite3
.
PARSE_COLNAMES
)
cursor
=
sqlite3conn
.
cursor
()
sqlite_insert
=
"""INSERT INTO 'resp_time' ('timestamp', 'mediawiki_elapsed', 'total_elapsed') VALUES (?, ?, ?);"""
data_tuple
=
(
datetime
.
datetime
.
now
(),
mediawiki_elapsed
,
total_elapsed
)
cursor
.
execute
(
sqlite_insert
,
data_tuple
)
sqlite3conn
.
commit
()
except
sqlite3
.
Error
as
error
:
print
(
"Error while working with SQlite: {}"
.
format
(
error
))
finally
:
if
sqlite3conn
:
sqlite3conn
.
close
()
Event Timeline
Paladox
created this paste.
Feb 9 2021, 23:17
2021-02-09 23:17:10 (UTC+0)
Log In to Comment