Compare commits
2 Commits
e22941d335
...
9973f46bc5
| Author | SHA1 | Date | |
|---|---|---|---|
| 9973f46bc5 | |||
| 1ccfb6180e |
20
display-all-reports/Dockerfile
Normal file
20
display-all-reports/Dockerfile
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Use the official Python image from the Docker Hub
|
||||
FROM python:3.9-slim
|
||||
|
||||
# Set the working directory in the container
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the requirements file into the container
|
||||
COPY requirements.txt .
|
||||
|
||||
# Install the dependencies
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy the rest of the application code into the container
|
||||
COPY . .
|
||||
|
||||
# Expose the port the app runs on
|
||||
EXPOSE 5000
|
||||
|
||||
# Define the command to run the application
|
||||
CMD ["python", "display-all-reports/display-reports.py"]
|
||||
|
|
@ -1,49 +1,115 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import textwrap
|
||||
import requests
|
||||
from flask import Flask, Response, request
|
||||
import datetime
|
||||
from flask import Flask, Response, request, jsonify
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
USER_TOKEN = ''
|
||||
USER_TOKEN = os.getenv('USER_TOKEN')
|
||||
if not USER_TOKEN:
|
||||
raise EnvironmentError("USER_TOKEN environment variable is not set")
|
||||
|
||||
def get_uploads(user_token, page=1):
|
||||
return requests.get("https://dps.report/getUploads?userToken={}&page={}".format(user_token, page)).json()
|
||||
|
||||
return requests.get("https://dps.report/getUploads?userToken={}&page={}&perPage={}".format(user_token, page, 100)).json()
|
||||
|
||||
@app.route("/")
|
||||
def fetch_and_display_my_reports():
|
||||
if request.args.get('page', ''):
|
||||
uploads = get_uploads(USER_TOKEN, request.args.get('page', ''))
|
||||
else:
|
||||
uploads = get_uploads(USER_TOKEN)
|
||||
# print(uploads)
|
||||
def test():
|
||||
page = request.args.get('page', '1')
|
||||
uploads = get_uploads(USER_TOKEN, page)
|
||||
|
||||
if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
|
||||
return jsonify(uploads)
|
||||
|
||||
upload_links_html = ""
|
||||
for upload in uploads['uploads']:
|
||||
upload_links_html += ' <a href="{url}">{url}</a><br>\n'.format(url=upload['permalink'])
|
||||
for upload in sorted(uploads['uploads'], key=lambda upload: upload['encounterTime'], reverse=True):
|
||||
encounter_time = datetime.datetime.fromtimestamp(upload['encounterTime']).strftime('%Y%m%d-%H%M%S')
|
||||
boss_name = upload['encounter']['boss']
|
||||
bosses = {26712: "Ura",
|
||||
26774: "Decima",
|
||||
26725: "Greer"}
|
||||
if boss_name == "DPS.Report":
|
||||
boss_name = bosses[upload['encounter']['bossId']]
|
||||
print(upload['encounter'])
|
||||
if upload['encounter']['isCm'] and not upload['encounter']['isLegendaryCm']:
|
||||
boss_name = boss_name + ' CM'
|
||||
if upload['encounter']['isLegendaryCm']:
|
||||
boss_name = boss_name + ' LCM'
|
||||
if upload['encounter']['emboldened']:
|
||||
boss_name = boss_name + ' (emboldened)'
|
||||
|
||||
|
||||
|
||||
boss_success = upload['encounter']['success']
|
||||
success = '❌'
|
||||
if boss_success:
|
||||
success = '✅'
|
||||
upload_links_html += ' <a href="{url}">{success} {encounter_time} {boss_name}</a><br>\n'.format(url=upload['permalink'],
|
||||
success=success,
|
||||
encounter_time=encounter_time,
|
||||
boss_name=boss_name)
|
||||
|
||||
older_reports = "<br>Older reports: "
|
||||
if uploads['pages'] > 1:
|
||||
for i in range(uploads['pages']):
|
||||
if request.args.get('page', '') == str(i+1):
|
||||
older_reports += ' <a href="?page={page_number}"><b>{page_number}</b></a> '.format(page_number=i+1)
|
||||
else:
|
||||
older_reports += ' <a href="?page={page_number}">{page_number}</a> '.format(page_number=i+1)
|
||||
for i in range(uploads['pages']):
|
||||
if page == str(i + 1):
|
||||
older_reports += ' <a href="?page={page_number}" style="font-size: 115%;"><b>{page_number}</b></a> '.format(page_number=i + 1)
|
||||
else:
|
||||
older_reports += ' <a href="?page={page_number}">{page_number}</a> '.format(page_number=i + 1)
|
||||
|
||||
else:
|
||||
older_reports = ""
|
||||
response_text = textwrap.dedent('''\
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>lennys dps reports</title>
|
||||
<style>
|
||||
<link href="https://fonts.googleapis.com/css?family=Alegreya+Sans" rel="stylesheet">
|
||||
body {{
|
||||
font-family: 'Alegreya Sans', sans-serif;
|
||||
line-height: 1.25;
|
||||
font-size: 90%;
|
||||
background-color: #333333;
|
||||
}}
|
||||
</style>
|
||||
<script>
|
||||
function loadReports(page) {{
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', '/?page=' + page, true);
|
||||
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
xhr.onload = function() {{
|
||||
if (xhr.status === 200) {{
|
||||
var data = JSON.parse(xhr.responseText);
|
||||
var uploadLinksHtml = '';
|
||||
data.uploads.sort((a, b) => b.encounterTime - a.encounterTime).forEach(upload => {{
|
||||
var encounterTime = new Date(upload.encounterTime * 1000).toISOString().replace('T', ' ').substring(0, 19);
|
||||
var bossName = upload.encounter.boss;
|
||||
if (upload.encounter.isCm) {{
|
||||
bossName += ' CM';
|
||||
}}
|
||||
var success = upload.encounter.success ? '✅' : '❌';
|
||||
uploadLinksHtml += `<a href="${{upload.permalink}}">${{success}} ${{encounterTime}} ${{bossName}}</a><br>`;
|
||||
}});
|
||||
document.getElementById('upload-links').innerHTML = uploadLinksHtml;
|
||||
}}
|
||||
}};
|
||||
xhr.send();
|
||||
}}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
{upload_links}{older_reports}
|
||||
<div id="upload-links">
|
||||
{upload_links_html}
|
||||
</div>
|
||||
<div>
|
||||
{older_reports}
|
||||
</div>
|
||||
</body>
|
||||
</html>'''.format(upload_links=upload_links_html, older_reports=older_reports))
|
||||
<footer style="font-size: 50%; font-family: 'Alegreya Sans', sans-serif;">
|
||||
<br><br>
|
||||
made with ♥ by lenny.2437
|
||||
</footer>
|
||||
</html>'''.format(upload_links_html=upload_links_html, older_reports=older_reports))
|
||||
return Response(response_text, mimetype='text/html')
|
||||
|
||||
def start():
|
||||
app = Flask(__name__)
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
2
display-all-reports/requirements.txt
Normal file
2
display-all-reports/requirements.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Flask==2.3.2
|
||||
requests==2.31.0
|
||||
Loading…
Reference in New Issue
Block a user