Skip to content

Commit

Permalink
Merge pull request #36 from edoardottt/devel
Browse files Browse the repository at this point in the history
Add last 50 logs to dashboard
  • Loading branch information
edoardottt authored Oct 17, 2021
2 parents 8534be3 + 6005873 commit 50058b2
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
20 changes: 20 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ def user_dashboard():
if values is None:
return render_template("error.html", errormsg="No data for this user.")

# render last 50 logs
logs_line = 50
logs = []
render_logs = 1
try:
with open("twitterbot2.log", "r") as f:
text = f.read().split("\n")
if len(text) > logs_line:
start = len(text) - logs_line - 1
else:
start = 0
for line in text[start:]:
if line.strip() != "":
logs.append(line)
except Exception:
render_logs = 0

if not today_show:
(
tweet_count,
Expand All @@ -87,6 +104,9 @@ def user_dashboard():
followers=followers_count,
values=values,
today_show=today_show,
len=len(logs),
logs=logs,
render_logs=render_logs,
)


Expand Down
14 changes: 11 additions & 3 deletions static/all.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
html,body {
width: 100%;
height:100%;
margin: 0;
padding: 0;
}

/* change the background color */
Expand Down Expand Up @@ -75,10 +77,16 @@ html,body {
color: #009879;
}

html, body{
margin: 0;
padding: 0;
.logs {
width: 100%;
list-style-type: none; /* Remove bullets */
padding: 0; /* Remove padding */
margin: 0; /* Remove margins */
margin-left: 0;
text-align: left;
}


footer{
width: 100%;
min-height: 30px;
Expand Down
44 changes: 43 additions & 1 deletion templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
<body>
{% include 'navbar.html' %}

<br>

<!-- HEADER -->
<div class="container" id="content">
<br>
<div class="row">
Expand All @@ -28,6 +30,10 @@ <h3>Real time statistics for <a href="https://twitter.com/{{ user }}">{{ user }}
</div>
</div>

<br>
<br>

<!-- TODAY DATA -->
{% if today_show %}
<div class="container-fluid">
<div>
Expand Down Expand Up @@ -55,6 +61,9 @@ <h4>Today's data</h4>
{% endif %}

<br>
<br>

<!-- CHART -->
<div class="container-fluid justify-content-center text-center">
<h4>Statistics over time</h4>
<div class="row align-items-center justify-content-center text-center">
Expand All @@ -70,9 +79,42 @@ <h4>Statistics over time</h4>

<script src="{{ url_for('static', filename='values.js')}}"></script>

<a href="/">Back to home</a>

</div>

<br>
<br>

<!-- LOGS -->
{% if render_logs %}
<div class="container-fluid">
<div>
<div class="container justify-content-center text-center">
<h4>Last {{len}} logs</h4>
</div>
<ul class="logs">
{%for i in range(0, len)%}
<li>{{logs[i]}}</li>
{%endfor%}
</ul>
</div>
</div>
{% endif %}

<br>
<br>

<!-- BACK TO HOME -->
<div class="container-fluid">
<div>
<div class="container justify-content-center text-center">
<a href="/">Back to home</a>
</div>
</div>
</div>

<br>


{% include 'footer.html' %}

Expand Down

0 comments on commit 50058b2

Please sign in to comment.