Skip to content

Commit

Permalink
Merge pull request #68 from edoardottt/devel
Browse files Browse the repository at this point in the history
v0.2
  • Loading branch information
edoardottt authored Feb 26, 2023
2 parents 023de34 + 055fc42 commit 0465415
Show file tree
Hide file tree
Showing 21 changed files with 533 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ name: "CodeQL"

on:
push:
branches: [ main ]
branches: [ main, devel ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
branches: [ main, devel ]
schedule:
- cron: '28 1 * * 4'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Python application

on:
push:
branches: [ main ]
branches: [ main, devel ]
pull_request:
branches: [ main ]
branches: [ main, devel ]

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion output.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import sys
import datetime

version_str = "0.1.8"
version_str = "0.2"


def version():
Expand Down
47 changes: 26 additions & 21 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ def user_dashboard():
)


@app.route('/api/docs')
def get_docs():
return render_template('swaggerui.html')


# ---------------------------------------------------------
# ------------------------ API ----------------------------
# ---------------------------------------------------------
Expand All @@ -137,7 +142,7 @@ def api_health():
"""
for thread in threading.enumerate():
if thread.getName() == "bot" and not thread.is_alive():
return "error"
return "error", 500
return "ok"


Expand All @@ -147,13 +152,13 @@ def api_user_tweets(user):
Total tweets for user <user>.
"""
if not user_ok(user):
return "ERROR: Invalid username."
return "ERROR: Invalid username.", 404

# if user ok ->
conn = db.conn_db()
values = db.user_stats(conn, user)
if values is None:
return "ERROR: No data for this user."
return "ERROR: No data for this user.", 404
else:
result = 0
for i in range(0, len(values)):
Expand All @@ -167,13 +172,13 @@ def api_user_likes(user):
Total likes for user <user>.
"""
if not user_ok(user):
return "ERROR: Invalid username."
return "ERROR: Invalid username.", 404

# if user ok ->
conn = db.conn_db()
values = db.user_stats(conn, user)
if values is None:
return "ERROR: No data for this user."
return "ERROR: No data for this user.", 404
else:
result = 0
for i in range(0, len(values)):
Expand All @@ -187,13 +192,13 @@ def api_user_retweets(user):
Total retweets for user <user>.
"""
if not user_ok(user):
return "ERROR: Invalid username."
return "ERROR: Invalid username.", 404

# if user ok ->
conn = db.conn_db()
values = db.user_stats(conn, user)
if values is None:
return "ERROR: No data for this user."
return "ERROR: No data for this user.", 404
else:
result = 0
for i in range(0, len(values)):
Expand All @@ -207,13 +212,13 @@ def api_user_followers(user):
Latest follower count for user <user>.
"""
if not user_ok(user):
return "ERROR: Invalid username."
return "ERROR: Invalid username.", 404

# if user ok ->
conn = db.conn_db()
values = db.user_stats(conn, user)
if values is None:
return "ERROR: No data for this user."
return "ERROR: No data for this user.", 404
else:
result = values[len(values) - 1][5]
return str(result)
Expand All @@ -240,14 +245,14 @@ def api_user_date_tweets(user, date):
Date format: YYYY-MM-DD.
"""
if not user_ok(user):
return "ERROR: Invalid username."
return "ERROR: Invalid username.", 404
if string_to_date(date) == "":
return "ERROR: Invalid date."
return "ERROR: Invalid date.", 400
# if checks ok ->
conn = db.conn_db()
values = db.user_date_stats(conn, user, date)
if values is None or len(values) == 0:
return "ERROR: No data for this user on this day."
return "ERROR: No data for this user on this day.", 404
else:
result = values[0][2]
return str(result)
Expand All @@ -260,14 +265,14 @@ def api_user_date_likes(user, date):
Date format: YYYY-MM-DD.
"""
if not user_ok(user):
return "ERROR: Invalid username."
return "ERROR: Invalid username.", 404
if string_to_date(date) == "":
return "ERROR: Invalid date."
return "ERROR: Invalid date.", 400
# if checks ok ->
conn = db.conn_db()
values = db.user_date_stats(conn, user, date)
if values is None or len(values) == 0:
return "ERROR: No data for this user on this day."
return "ERROR: No data for this user on this day.", 404
else:
result = values[0][3]
return str(result)
Expand All @@ -280,14 +285,14 @@ def api_user_date_retweets(user, date):
Date format: YYYY-MM-DD.
"""
if not user_ok(user):
return "ERROR: Invalid username."
return "ERROR: Invalid username.", 404
if string_to_date(date) == "":
return "ERROR: Invalid date."
return "ERROR: Invalid date.", 400
# if checks ok ->
conn = db.conn_db()
values = db.user_date_stats(conn, user, date)
if values is None or len(values) == 0:
return "ERROR: No data for this user on this day."
return "ERROR: No data for this user on this day.", 404
else:
result = values[0][4]
return str(result)
Expand All @@ -300,14 +305,14 @@ def api_user_date_followers(user, date):
Date format: YYYY-MM-DD.
"""
if not user_ok(user):
return "ERROR: Invalid username."
return "ERROR: Invalid username.", 404
if string_to_date(date) == "":
return "ERROR: Invalid date."
return "ERROR: Invalid date.", 400
# if checks ok ->
conn = db.conn_db()
values = db.user_date_stats(conn, user, date)
if values is None or len(values) == 0:
return "ERROR: No data for this user on this day."
return "ERROR: No data for this user on this day.", 404
else:
result = values[0][5]
return str(result)
Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions static/css/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}

*,
*:before,
*:after {
box-sizing: inherit;
}

body {
margin: 0;
background: #fafafa;
}
3 changes: 3 additions & 0 deletions static/css/swagger-ui.css

Large diffs are not rendered by default.

Binary file added static/img/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
20 changes: 20 additions & 0 deletions static/js/swagger-initializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
window.onload = function () {
//<editor-fold desc="Changeable Configuration Block">

// the following lines will be replaced by docker/configurator, when it runs in a docker-container
window.ui = SwaggerUIBundle({
url: "/static/openapi.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});

//</editor-fold>
};
3 changes: 3 additions & 0 deletions static/js/swagger-ui-bundle.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions static/js/swagger-ui-standalone-preset.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions static/js/swagger-ui.js

Large diffs are not rendered by default.

File renamed without changes.
Loading

0 comments on commit 0465415

Please sign in to comment.