Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Armory Dashboard
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anton Sarukhanov
Armory Dashboard
Commits
3ab5fab7
Commit
3ab5fab7
authored
8 years ago
by
Anton Sarukhanov
Browse files
Options
Downloads
Patches
Plain Diff
Convert to web-app
parent
f0a8b7c8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app.py
+24
-0
24 additions, 0 deletions
app.py
scrape.py
+57
-48
57 additions, 48 deletions
scrape.py
templates/index.html
+39
-0
39 additions, 0 deletions
templates/index.html
with
120 additions
and
48 deletions
app.py
0 → 100644
+
24
−
0
View file @
3ab5fab7
from
urllib.parse
import
urlparse
,
urljoin
import
re
from
flask
import
Flask
,
render_template
from
lxml
import
html
import
requests
from
scrape
import
scrape
app
=
Flask
(
__name__
)
@app.after_request
def
add_header
(
response
):
response
.
cache_control
.
max_age
=
300
return
response
@app.route
(
"
/
"
)
def
index
():
tournament_name
,
tournament_details
,
events
=
scrape
()
return
render_template
(
'
index.html
'
,
tournament_name
=
tournament_name
,
tournament_details
=
tournament_details
,
events
=
events
)
if
__name__
==
"
__main__
"
:
app
.
run
()
This diff is collapsed.
Click to expand it.
scrape.py
+
57
−
48
View file @
3ab5fab7
...
...
@@ -3,52 +3,61 @@ import requests
import
re
from
urllib.parse
import
urlparse
,
urljoin
results_url
=
"
http://www.escrimeresults.com/cobra/index.htm
"
results
=
requests
.
get
(
results_url
)
results_tree
=
html
.
fromstring
(
results
.
content
)
try
:
event_urls
=
results_tree
.
xpath
(
'
//div[@id=
"
schedule
"
]/table/tr/td/a[text()=
"
View
"
]/@href
'
)
except
IndexError
:
print
(
"
No event schedule found
"
)
exit
()
tournament_name
=
results_tree
.
xpath
(
'
//span[@class=
"
tournName
"
]/text()
'
)[
0
]
tournament_details
=
results_tree
.
xpath
(
'
//span[@class=
"
tournDetails
"
]/text()
'
)[
0
]
print
(
tournament_name
)
print
(
tournament_details
)
print
(
"
{0} Events
\n
"
.
format
(
len
(
event_urls
)))
events
=
{}
for
event_url
in
event_urls
:
if
not
urlparse
(
event_url
).
netloc
:
event_url
=
urljoin
(
results_url
,
event_url
)
event
=
requests
.
get
(
event_url
)
event_tree
=
html
.
fromstring
(
event
.
content
)
event_details
=
event_tree
.
xpath
(
def
scrape
():
results_url
=
"
http://www.escrimeresults.com/cobra/index.htm
"
results
=
requests
.
get
(
results_url
)
results_tree
=
html
.
fromstring
(
results
.
content
)
try
:
event_urls
=
results_tree
.
xpath
(
'
//div[@id=
"
schedule
"
]/table/tr/td/a[text()=
"
View
"
]/@href
'
)
except
IndexError
:
return
"
No event schedule found
"
tournament_name
=
results_tree
.
xpath
(
'
//span[@class=
"
tournName
"
]/text()
'
)[
0
]
tournament_details
=
results_tree
.
xpath
(
'
//span[@class=
"
tournDetails
"
]/text()
'
)[
0
]
print
(
"
\n\n
{0}
"
.
format
(
event_details
))
if
event_tree
.
xpath
(
'
//a[text()=
"
Final Results
"
]
'
):
fencers
=
event_tree
.
xpath
(
'
//div[@id=
"
finalResults
"
]/table/tr/td[2]/text()
'
)
print
(
"
Event Closed ({0} fencers)
"
.
format
(
len
(
fencers
)))
elif
event_tree
.
xpath
(
'
//a[text()=
"
Check-In Status
"
]
'
):
checkin_summary
=
event_tree
.
xpath
(
'
normalize-space(//div[@class=
"
checkInSummary
"
]/text())
'
)
print
(
checkin_summary
)
fencers
=
event_tree
.
xpath
(
'
//div[@id=
"
checkIn
"
]/table/tr/td[2]/text()
'
)
events
[
event_details
]
=
[]
prior_events
=
{}
for
fencer
in
fencers
:
events
[
event_details
].
append
(
fencer
.
strip
())
for
e
in
events
:
if
e
==
event_details
:
continue
if
fencer
.
strip
()
in
events
[
e
]:
if
e
in
prior_events
:
prior_events
[
e
]
+=
1
else
:
prior_events
[
e
]
=
1
break
for
e
in
prior_events
:
print
(
"
{0} Fencers previously fenced in {1}
"
.
format
(
prior_events
[
e
],
e
))
# TODO: Tally fencers who have checked in
events
=
[]
for
event_url
in
event_urls
:
if
not
urlparse
(
event_url
).
netloc
:
event_url
=
urljoin
(
results_url
,
event_url
)
event
=
requests
.
get
(
event_url
)
event_tree
=
html
.
fromstring
(
event
.
content
)
event_details
=
event_tree
.
xpath
(
'
//span[@class=
"
tournDetails
"
]/text()
'
)[
0
]
if
event_tree
.
xpath
(
'
//a[text()=
"
Final Results
"
]
'
):
fencers
=
event_tree
.
xpath
(
'
//div[@id=
"
finalResults
"
]/table/tr/td[2]/text()
'
)
event_status
=
"
Event Closed ({0} fencers)
"
.
format
(
len
(
fencers
))
elif
event_tree
.
xpath
(
'
//a[text()=
"
Seeding
"
]
'
):
fencers
=
event_tree
.
xpath
(
'
//div[@id=
"
Round1Seeding
"
]/table/tr/td[2]/text()
'
)
event_status
=
"
Event is Ongoing ({0} fencers)
"
.
format
(
len
(
fencers
))
elif
event_tree
.
xpath
(
'
//a[text()=
"
Check-In Status
"
]
'
):
event_status
=
event_tree
.
xpath
(
'
normalize-space(//div[@class=
"
checkInSummary
"
]/text())
'
)
fencers
=
event_tree
.
xpath
(
'
//div[@id=
"
checkIn
"
]/table/tr/td[2]/text()
'
)
try
:
del
this_event
except
:
pass
this_event
=
{
'
name
'
:
event_details
,
'
status
'
:
event_status
,
'
fencers
'
:
[],
'
previously_fenced
'
:
{},
'
previous_total
'
:
0
}
for
fencer
in
fencers
:
this_event
[
'
fencers
'
].
append
(
fencer
.
strip
())
for
e
in
events
:
if
e
[
'
name
'
]
==
event_details
:
continue
if
fencer
.
strip
()
in
e
[
'
fencers
'
]:
if
e
[
'
name
'
]
in
this_event
[
'
previously_fenced
'
]:
this_event
[
'
previously_fenced
'
][
e
[
'
name
'
]]
+=
1
else
:
this_event
[
'
previously_fenced
'
][
e
[
'
name
'
]]
=
1
this_event
[
'
previous_total
'
]
+=
1
break
events
.
append
(
this_event
)
# TODO: Tally fencers who have checked in
return
(
tournament_name
,
tournament_details
,
events
)
This diff is collapsed.
Click to expand it.
templates/index.html
0 → 100644
+
39
−
0
View file @
3ab5fab7
<!doctype html>
<html
lang=
"en"
>
<head>
<meta
charset=
"utf-8"
>
<title>
Armory Dashboard
</title>
<style>
body
{
font
:
14px
sans-serif
;
}
section
{
border-bottom
:
2px
solid
#aaa
;
}
p
{
margin
:
.25em
0
;
}
</style>
</head>
<body>
<h1>
{{tournament_name}}
</h1>
<h2>
{{tournament_details}}
</h2>
<h2>
{{events|length}} Events
</h2>
<hr>
{% for e in events %}
<section>
<a
name=
"{{e['name']}}"
>
<h3><a
href=
"#{{e['name']}}"
>
{{e['name']}}
</a></h3>
<p>
{{e['status']}}
</p>
{% if e['previously_fenced'] %}
<p>
{{e['previous_total']}} fencers have previously checked in:
</p>
<ul>
{% for pe in e['previously_fenced'] %}
<li>
{{pe}} - {{e['previously_fenced'][pe]}} fencers
</li>
{% endfor %}
</ul>
{% endif %}
</section>
{% endfor %}
</body>
</html>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment