Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple servers support in event; pull event from Discord; event end date #88

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add new "with event" server listing filter
EpocDotFr committed Mar 21, 2024

Verified

This commit was signed with the committer’s verified signature.
pradyunsg Pradyun Gedam
commit e3ed540781e418ce0dc4c4160525fbc050babba3
8 changes: 7 additions & 1 deletion docs/api/resources/servers.apib
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

A Server represent a public multiplayer Running With Rifles game.

## Servers [/servers{?location,map,type,mode,dedicated,official,not_empty,not_full,limit}]
## Servers [/servers{?location,map,type,mode,dedicated,official,not_empty,not_full,with_event,limit}]

+ Parameters
+ `location`: `continent:eu` (optional)
@@ -132,6 +132,12 @@ A Server represent a public multiplayer Running With Rifles game.
+ `1`
+ `false`
+ `0`
+ `with_event`: `true` (enum[string, number], optional) - Whether to filter servers with event only. `true` or `1` to enable this filter. `false` or `0` will be ignored and thus disable this filter.
+ Members
+ `true`
+ `1`
+ `false`
+ `0`
+ `limit`: `10` (number, optional) - Return the _n_ first servers of the filtered list.

### Get the list of Servers [GET]
4 changes: 4 additions & 0 deletions rwr/scraper.py
Original file line number Diff line number Diff line change
@@ -321,6 +321,7 @@ def _filter_server(server, filters):
ranked = filters.get('ranked')
not_empty = filters.get('not_empty')
not_full = filters.get('not_full')
with_event = filters.get('with_event')
database = filters.get('database')
username = filters.get('username')

@@ -383,6 +384,9 @@ def _filter_server(server, filters):
if not_full == 'yes' and server.players.free == 0:
return False

if with_event == 'yes' and not server.event:
return False

return True

servers = [server for server in get_servers() if _filter_server(server, filters)]
1 change: 1 addition & 0 deletions rwrs/api/routes.py
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ def get(self):
ServersResource.replace_true_by_yes(args, 'official')
ServersResource.replace_true_by_yes(args, 'not_empty')
ServersResource.replace_true_by_yes(args, 'not_full')
ServersResource.replace_true_by_yes(args, 'with_event')

servers = rwr.scraper.filter_servers(**args)
else:
1 change: 1 addition & 0 deletions rwrs/api/validators.py
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@ def username(value):
get_servers_list.add_argument('official', location='args', type=inputs.boolean)
get_servers_list.add_argument('not_empty', location='args', type=inputs.boolean)
get_servers_list.add_argument('not_full', location='args', type=inputs.boolean)
get_servers_list.add_argument('with_event', location='args', type=inputs.boolean)
get_servers_list.add_argument('limit', location='args', type=inputs.positive)

get_players_list = limit_parser.copy()
7 changes: 4 additions & 3 deletions static/api_doc.html
Original file line number Diff line number Diff line change
@@ -82,13 +82,13 @@ <h3 id="header-server-error-(5xx)">Server error (5xx) <a class="permalink" href=
"<span class="hljs-attribute">message</span>": <span class="hljs-value"><span class="hljs-string">"Error creating this thing: IndexError: out of bounds"</span>
</span>}</code></pre>
<section id="servers" class="resource-group"><h2 class="group-heading">Servers <a href="#servers" class="permalink">&para;</a></h2><p>A Server represent a public multiplayer Running With Rifles game.</p>
<div id="servers-servers" class="resource"><h3 class="resource-heading">Servers <a href="#servers-servers" class="permalink">&nbsp;&para;</a></h3><div id="servers-servers-get" class="action get"><h4 class="action-heading"><div class="name">Get the list of Servers</div><a href="#servers-servers-get" class="method get">GET</a><code class="uri">/servers{?location,map,type,mode,dedicated,official,not_empty,not_full,limit}</code></h4><p>Return the list of Servers. The list may be optionally filtered by several criteria. These last are taken into account
<div id="servers-servers" class="resource"><h3 class="resource-heading">Servers <a href="#servers-servers" class="permalink">&nbsp;&para;</a></h3><div id="servers-servers-get" class="action get"><h4 class="action-heading"><div class="name">Get the list of Servers</div><a href="#servers-servers-get" class="method get">GET</a><code class="uri">/servers{?location,map,type,mode,dedicated,official,not_empty,not_full,with_event,limit}</code></h4><p>Return the list of Servers. The list may be optionally filtered by several criteria. These last are taken into account
<strong>only</strong> if it they are present in the query string.</p>
<div class="note">
<h4 id="header-server-side-caching">Server-side caching <a class="permalink" href="#header-server-side-caching" aria-hidden="true">¶</a></h4>
<p>This resource has a cache lifetime of <strong>1 minute</strong>.</p>
</div>
<h4>Example URI</h4><div class="definition"><span class="method get">GET</span>&nbsp;<span class="uri"><span class="hostname">https://rwrstats.com/api</span>/servers?<span class="hljs-attribute">location=</span><span class="hljs-literal">continent:eu</span>&<span class="hljs-attribute">map=</span><span class="hljs-literal">map10</span>&<span class="hljs-attribute">type=</span><span class="hljs-literal">vanilla</span>&<span class="hljs-attribute">mode=</span><span class="hljs-literal">COOP</span>&<span class="hljs-attribute">dedicated=</span><span class="hljs-literal">true</span>&<span class="hljs-attribute">official=</span><span class="hljs-literal">true</span>&<span class="hljs-attribute">not_empty=</span><span class="hljs-literal">true</span>&<span class="hljs-attribute">not_full=</span><span class="hljs-literal">true</span>&<span class="hljs-attribute">limit=</span><span class="hljs-literal">10</span></span></div><div class="title"><strong>URI Parameters</strong><div class="collapse-button show"><span class="close">Hide</span><span class="open">Show</span></div></div><div class="collapse-content"><dl class="inner"><dt>location</dt><dd><code>string</code>&nbsp;<span>(optional)</span>&nbsp;<span class="text-info default"><strong>Default:&nbsp;</strong><span>any</span></span>&nbsp;<span class="text-muted example"><strong>Example:&nbsp;</strong><span>continent:eu</span></span><p>Servers country or continent of residence. This criterion format is either:</p>
<h4>Example URI</h4><div class="definition"><span class="method get">GET</span>&nbsp;<span class="uri"><span class="hostname">https://rwrstats.com/api</span>/servers?<span class="hljs-attribute">location=</span><span class="hljs-literal">continent:eu</span>&<span class="hljs-attribute">map=</span><span class="hljs-literal">map10</span>&<span class="hljs-attribute">type=</span><span class="hljs-literal">vanilla</span>&<span class="hljs-attribute">mode=</span><span class="hljs-literal">COOP</span>&<span class="hljs-attribute">dedicated=</span><span class="hljs-literal">true</span>&<span class="hljs-attribute">official=</span><span class="hljs-literal">true</span>&<span class="hljs-attribute">not_empty=</span><span class="hljs-literal">true</span>&<span class="hljs-attribute">not_full=</span><span class="hljs-literal">true</span>&<span class="hljs-attribute">with_event=</span><span class="hljs-literal">true</span>&<span class="hljs-attribute">limit=</span><span class="hljs-literal">10</span></span></div><div class="title"><strong>URI Parameters</strong><div class="collapse-button show"><span class="close">Hide</span><span class="open">Show</span></div></div><div class="collapse-content"><dl class="inner"><dt>location</dt><dd><code>string</code>&nbsp;<span>(optional)</span>&nbsp;<span class="text-info default"><strong>Default:&nbsp;</strong><span>any</span></span>&nbsp;<span class="text-muted example"><strong>Example:&nbsp;</strong><span>continent:eu</span></span><p>Servers country or continent of residence. This criterion format is either:</p>
<ul>
<li>
<p>A concatenation of a <strong>location type</strong> and a <strong>location code</strong>, separated by a colon, OR</p>
@@ -203,6 +203,7 @@ <h4>Example URI</h4><div class="definition"><span class="method get">GET</span>&
<p class="choices"><strong>Choices:&nbsp;</strong><code>true</code> <code>1</code> <code>false</code> <code>0</code> </p></dd><dt>official</dt><dd><code>string, number</code>&nbsp;<span>(optional)</span>&nbsp;<span class="text-muted example"><strong>Example:&nbsp;</strong><span>true</span></span><p>Whether to filter official servers only. <code>true</code> or <code>1</code> to enable this filter. <code>false</code> or <code>0</code> will be ignored and thus disable this filter.</p>
<p class="choices"><strong>Choices:&nbsp;</strong><code>true</code> <code>1</code> <code>false</code> <code>0</code> </p></dd><dt>not_empty</dt><dd><code>string, number</code>&nbsp;<span>(optional)</span>&nbsp;<span class="text-muted example"><strong>Example:&nbsp;</strong><span>true</span></span><p>Whether to filter non-empty servers only. <code>true</code> or <code>1</code> to enable this filter. <code>false</code> or <code>0</code> will be ignored and thus disable this filter.</p>
<p class="choices"><strong>Choices:&nbsp;</strong><code>true</code> <code>1</code> <code>false</code> <code>0</code> </p></dd><dt>not_full</dt><dd><code>string, number</code>&nbsp;<span>(optional)</span>&nbsp;<span class="text-muted example"><strong>Example:&nbsp;</strong><span>true</span></span><p>Whether to filter non-full servers only. <code>true</code> or <code>1</code> to enable this filter. <code>false</code> or <code>0</code> will be ignored and thus disable this filter.</p>
<p class="choices"><strong>Choices:&nbsp;</strong><code>true</code> <code>1</code> <code>false</code> <code>0</code> </p></dd><dt>with_event</dt><dd><code>string, number</code>&nbsp;<span>(optional)</span>&nbsp;<span class="text-muted example"><strong>Example:&nbsp;</strong><span>true</span></span><p>Whether to filter servers with event only. <code>true</code> or <code>1</code> to enable this filter. <code>false</code> or <code>0</code> will be ignored and thus disable this filter.</p>
<p class="choices"><strong>Choices:&nbsp;</strong><code>true</code> <code>1</code> <code>false</code> <code>0</code> </p></dd><dt>limit</dt><dd><code>number</code>&nbsp;<span>(optional)</span>&nbsp;<span class="text-muted example"><strong>Example:&nbsp;</strong><span>10</span></span><p>Return the <em>n</em> first servers of the filtered list.</p>
</dd></dl></div><div class="title"><strong>Request</strong><div class="collapse-button"><span class="close">Hide</span><span class="open">Show</span></div></div><div class="collapse-content"><div class="inner"><h5>Headers</h5><pre><code><span class="hljs-attribute">Authorization</span>: <span class="hljs-string">Token {Your Personal Access Token}</span></code></pre><div style="height: 1px;"></div></div></div><div class="title"><strong>Response&nbsp;&nbsp;<code>200</code></strong><div class="collapse-button"><span class="close">Hide</span><span class="open">Show</span></div></div><div class="collapse-content"><div class="inner"><div class="description"><p>An empty list is returned if no Servers were found.</p>
</div><h5>Headers</h5><pre><code><span class="hljs-attribute">Content-Type</span>: <span class="hljs-string">application/json</span></code></pre><div style="height: 1px;"></div><h5>Body</h5><pre><code>[
@@ -3941,7 +3942,7 @@ <h4>Example URI</h4><div class="definition"><span class="method get">GET</span>&
<span class="hljs-string">"message"</span>
]</span>,
"<span class="hljs-attribute">additionalProperties</span>": <span class="hljs-value"><span class="hljs-literal">false</span>
</span>}</code></pre><div style="height: 1px;"></div></div></div></div></div></section></div></div></div><p style="text-align: center;" class="text-muted">Generated by&nbsp;<a href="https://github.com/danielgtaylor/aglio" class="aglio">aglio</a>&nbsp;on 11 Oct 2023</p><script>/* eslint-env browser */
</span>}</code></pre><div style="height: 1px;"></div></div></div></div></div></section></div></div></div><p style="text-align: center;" class="text-muted">Generated by&nbsp;<a href="https://github.com/danielgtaylor/aglio" class="aglio">aglio</a>&nbsp;on 12 Nov 2023</p><script>/* eslint-env browser */
/* eslint quotes: [2, "single"] */
'use strict';

1 change: 1 addition & 0 deletions templates/servers/list.html
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@
{{ macros.checkbox('official', 'Official') }}
{{ macros.checkbox('not_empty', 'Not empty') }}
{{ macros.checkbox('not_full', 'Not full') }}
{{ macros.checkbox('with_event', 'With event') }}
</div>

{% if 'view' in request.args -%}