Skip to content

Commit

Permalink
Add ruff as a formatter and linter
Browse files Browse the repository at this point in the history
  • Loading branch information
flofriday committed Feb 12, 2024
1 parent b4b5e5b commit ceee620
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.venv/
__pycache__/
.pytest_cache/
.ruff_cache/
node_modules/
app/static/style.css
bettercal.db*
Expand Down
13 changes: 7 additions & 6 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import json
from flask import Flask, render_template, send_from_directory, request, g
import requests
import sqlite3

import requests
from flask import Flask, g, render_template, request, send_from_directory

import app.tiss as tiss
from app.format import improve_calendar
from app.monitoring import get_statistics, add_usage, get_chart_data
from app.monitoring import add_usage, get_chart_data, get_statistics

app = Flask(__name__)

Expand Down Expand Up @@ -86,7 +87,7 @@ def verify():
return "Could not contact TISS. Maybe TISS is down?", 400
except ValueError:
return "TISS didn't return an ical file, did you paste the correct url?", 400
except:
except Exception:
return "Somthing unexpected went wrong, maybe create an GitHub issue?", 500

return "Ok"
Expand All @@ -102,8 +103,8 @@ def icalendar():
if locale is None:
return "No locale provided", 400

is_google = "google" in request.args.keys()
use_shorthand = "noshorthand" not in request.args.keys()
is_google = "google" in request.args
use_shorthand = "noshorthand" not in request.args

url = f"https://tiss.tuwien.ac.at/events/rest/calendar/personal?token={token}&locale={locale}"
cal = tiss.get_calendar(url)
Expand Down
5 changes: 3 additions & 2 deletions app/format.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import csv
import html
from icalendar import Calendar
import re
from dataclasses import dataclass
from functools import cache
import re

from icalendar import Calendar

summary_regex = re.compile("([0-9A-Z]{3}\\.[0-9A-Z]{3}) ([A-Z]{2}) (.*)")

Expand Down
2 changes: 1 addition & 1 deletion app/monitoring.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import hashlib
from dataclasses import dataclass
from sqlite3 import Connection
import hashlib
from typing import Tuple


Expand Down
3 changes: 2 additions & 1 deletion app/resources/generate_rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# It does this automatically by the room UI from tiss and extracting the information from there.
# To run this you first need to: pip install selenium
import csv

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait


def main():
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ testpaths = ["tests"]
[tool.coverage.run]
branch = true
source = ["app"]

[tool.ruff.lint]
select = ["F", "UP", "B", "SIM", "I"]
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pytest-mock==3.12.0
python-dateutil==2.8.2
pytz==2024.1
requests==2.31.0
ruff==0.2.1
six==1.16.0
urllib3==2.2.0
Werkzeug==3.0.1
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

from app import app as backendapp


Expand Down
3 changes: 2 additions & 1 deletion tests/test_request.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re

from flask.testing import FlaskClient
from icalendar import Calendar
import re


def get_test_calendar(lang: str = "de"):
Expand Down

0 comments on commit ceee620

Please sign in to comment.