Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Trevor Cappallo
TE4bot
Commits
63ecac56
Commit
63ecac56
authored
Nov 05, 2021
by
Trevor Cappallo
Browse files
change approach to be less fragile
parent
7e5bed53
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
21 deletions
+21
-21
te4.py
te4.py
+21
-21
No files found.
te4.py
View file @
63ecac56
...
...
@@ -15,7 +15,7 @@ reSummary = re.compile('^\s*(.*)\*\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA
'([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+MG\-on.*$'
,
re
.
MULTILINE
)
oldGames
=
[]
newG
ames
=
[]
g
ames
=
[]
recentlySaid
=
[]
lastData
=
""
currentGames
=
{}
...
...
@@ -88,43 +88,42 @@ async def on_ready():
@
tasks
.
loop
(
seconds
=
15.0
)
async
def
status_task
():
global
oldGames
,
newG
ames
,
cnt
,
currentGames
,
recentlySaid
global
oldGames
,
g
ames
,
cnt
,
currentGames
,
recentlySaid
data
=
requests
.
get
(
"https://www.managames.com/tennis/online/TE4_ServerList.php?Poll=1"
)
# if cnt==0:
# info = parse_server_poll('0 10E1 "POLAND vs TennisStar" B180D41 12C 6AC 96 "" "6/3 4/6 7/6" 510 2 46 617DAC94 * 1 0 0 34 1ED48 0 MG-on'.replace('\n',' '))
# else:
info
=
parse_server_poll
(
data
.
text
.
replace
(
'
\n
'
,
' '
))
newGames
=
[{
k
:
v
for
(
k
,
v
)
in
x
.
items
()
if
k
!=
'score'
}
for
x
in
info
[
'games'
]]
newGames
=
[
x
for
x
in
newGames
if
sorted
([
str
(
y
)
for
y
in
x
.
values
()])
not
in
oldGames
]
# newGames = [{k:v for (k,v) in x.items() if k!= 'score'} for x in info['games']]
games
=
info
[
'games'
]
# newGames = [x for x in newGames if x['score'] == '...' and sorted([str(y) for y in x.values()]) not in oldGames]
out
=
[]
nix
=
[]
for
game
in
info
[
'games'
]:
if
"..."
not
in
game
[
'score'
]
and
" -- "
not
in
game
[
'score'
]
and
game
[
'name'
]
in
currentGames
.
keys
():
out
+=
[
f
"The
{
game
[
'name'
]
}
game is finished. The final score was
{
game
[
'score'
]
}
."
]
del
currentGames
[
game
[
'name'
]]
# for game in info['games']:
# if "..." not in game['score'] and " -- " not in game['score'] and game['name'] in currentGames.keys():
# out += [f"The {game['name']} game is finished. The final score was {game['score']}."]
# pprint.pprint(currentGames)
# del currentGames[game['name']]
for
ongoing
in
currentGames
.
keys
():
if
ongoing
not
in
[
x
[
'name'
]
for
x
in
info
[
'
games
'
]
]:
if
ongoing
not
in
[
x
[
'name'
]
for
x
in
games
]:
out
+=
[
f
"The
{
ongoing
}
game is finished. Final score:
{
currentGames
[
ongoing
][
'score'
]
}
"
]
nix
+=
[
ongoing
]
for
xin
in
nix
:
del
currentGames
[
xin
]
if
len
(
newGames
)
>
0
or
len
(
out
)
>
0
:
for
game
in
newGames
:
if
game
[
'ip'
]
==
'0'
and
' -- '
in
game
[
'score'
]:
if
' vs '
not
in
game
[
'name'
]:
continue
else
:
if
len
(
games
)
>
0
or
len
(
out
)
>
0
:
for
game
in
games
:
s
=
""
if
game
[
'ip'
]
==
'0'
and
' vs '
in
game
[
'name'
]:
if
game
[
'name'
]
not
in
currentGames
.
keys
():
s
=
f
"The
{
game
[
'name'
]
}
match has begun."
filt
=
tuple
(
filter
(
lambda
x
:
x
[
'name'
]
==
game
[
'name'
],
info
[
'games'
]))[
0
]
# currentGames[game['name']] = [v for (k,v) if k==game['name'] in x.items() for x in info['games'] ][0]
currentGames
[
game
[
'name'
]]
=
filt
currentGames
[
game
[
'name'
]]
=
game
else
:
s
=
f
"
{
game
[
'name'
]
}
(elo:
{
game
[
'elo'
]
}
, rep:
{
game
[
'reputation'
]
}
%) wants to play a
{
game
[
'game_info'
][
'nb_set'
]
}
-set match."
if
len
(
game
[
'tagline'
])
>
0
:
s
+=
f
" Comment:
{
game
[
'tagline'
]
}
"
if
s
not
in
recentlySaid
:
if
s
!=
""
and
s
not
in
recentlySaid
:
out
+=
[
s
]
recentlySaid
.
append
(
s
)
if
len
(
recentlySaid
)
>
5
:
...
...
@@ -133,12 +132,13 @@ async def status_task():
if
len
(
out
)
>
0
:
pprint
.
pprint
(
out
)
await
ch
.
send
(
"
\n
"
.
join
(
out
))
oldGames
=
[
sorted
([
str
(
y
)
for
y
in
x
.
values
()])
for
x
in
newG
ames
]
oldGames
=
[
sorted
([
str
(
y
)
for
y
in
x
.
values
()])
for
x
in
g
ames
]
# oldGames += newGames
# oldGames =
# if (len(oldGames)>10):
# oldGames=oldGames[-10:]
else
:
if
len
(
games
)
==
0
:
recentlySaid
=
[]
cnt
+=
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment