Skip to content

Commit

Permalink
Basic working version
Browse files Browse the repository at this point in the history
  • Loading branch information
nikdoof committed Nov 29, 2023
1 parent 7f86756 commit 82ad14a
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 15 deletions.
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
6 changes: 6 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
]
}
32 changes: 32 additions & 0 deletions .github/workflows/build-container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build Container

"on":
push:
branches:
- main
tags:
- "[0-9]+.[0-9]+.[0-9]+"

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/user-tweaker:${{ github.ref_name }}
ghcr.io/${{ github.repository_owner }}/user-tweaker:latest
22 changes: 22 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Run Tests

on:
push:
branches:
- "main"

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Lint with ruff
run: |
make lint
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM python:3.11.5-alpine3.18 AS base

FROM base AS builder

ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=false \
PATH="$PATH:/runtime/bin" \
PYTHONPATH="$PYTHONPATH:/runtime/lib/python3.11/site-packages" \
# Versions:
POETRY_VERSION=1.7.0

# System deps:
RUN apk add build-base unzip wget python3-dev libffi-dev
RUN pip install "poetry==$POETRY_VERSION"

WORKDIR /src

# Generate requirements and install *all* dependencies.
COPY pyproject.toml poetry.lock /src/
RUN poetry export --dev --without-hashes --no-interaction --no-ansi -f requirements.txt -o requirements.txt
RUN pip install --prefix=/runtime --force-reinstall -r requirements.txt

FROM base AS runtime
COPY --from=builder /runtime /usr/local
COPY . /app
WORKDIR /app
CMD ["/usr/local/bin/gunicorn", "local_spaces.app:create_app()", "--bind", "0.0.0.0:80"]
3 changes: 2 additions & 1 deletion local_spaces/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ def create_app():
"SECRET_KEY": secrets.token_hex(64),
"TESTING": False,
"DEBUG": False,
"TEMPLATES_AUTO_RELOAD": True,
"LOCALSPACES_SPACEAPI_ENDPOINT": "https://api.spaceapi.io",
"LOCALSPACES_LOCAL_ENDPOINT": "https://api.leighhack.org/space.json",
"LOCALSPACES_DISTANCE": 300,
"LOCALSPACES_DISTANCE": 450,
}
)
app.config.from_prefixed_env()
Expand Down
4 changes: 3 additions & 1 deletion local_spaces/local.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask import Blueprint, render_template, current_app
from math import radians, cos, sin, asin, sqrt
import requests
from cachetools.func import ttl_cache

local = Blueprint(
"local", __name__, template_folder="templates", static_folder="static"
Expand All @@ -27,6 +28,7 @@ def index():


@local.route("/local_spaces.json")
@ttl_cache(ttl=1800)
def spaces():
# Get the local hackspace Space JSON
resp = requests.get(current_app.config.get("LOCALSPACES_LOCAL_ENDPOINT"))
Expand Down Expand Up @@ -63,4 +65,4 @@ def spaces():
space['distance'] = distance
spaces.append(space)

return spaces
return sorted(spaces, key=lambda d: d['distance'])
23 changes: 17 additions & 6 deletions local_spaces/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
<style>

img#space-logo {
max-height: 200px;
max-height: 75px;
}
div.space-box {
min-height: 300px;
min-height: 250px;
}
</style>
</head>
Expand All @@ -26,9 +26,12 @@
<template id="space-block">
<div class="column is-one-quarter">
<div class="box space-box">
<h4 id="space-name"></h3>
<img id="space-logo" class="is-centered" src="">
<p>Distance: <span id="space-distance"></span>km</p>
<p><b id="space-name"></b></p>
<!--<figure class="image is-inline-block">
<img id="space-logo" src="https://unsplash.it/64"/>
</figure>-->
<p id="space-status"></p>
<p>Distance: <b id="space-distance"></b> km</p>
</div>
</div>
</template>
Expand All @@ -45,8 +48,16 @@ <h1>Other Local Hackspaces</h1>
spaces.forEach(function (val, indx) {
var obj = $($("template#space-block").html());
obj.find('#space-name').html(val['data']['space']);
obj.find('#space-distance').html(val['distance']);
obj.find('#space-distance').html(Math.round(val['distance'] * 100) / 100);

let status = 'Closed';
if (val['data']['state']['open']) {
status = 'Open';
}
obj.find('#space-status').html(status);

obj.find('#space-logo').attr('src', val['data']['logo']);
obj.fin
$('div#spaces').append(obj);
});
});
Expand Down
14 changes: 13 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ python = "^3.11"
Flask = "^3.0.0"
requests = "^2.31.0"
prometheus-flask-exporter = "^0.23.0"
cachetools = "^5.3.2"


[build-system]
Expand Down
6 changes: 0 additions & 6 deletions renovate.json

This file was deleted.

0 comments on commit 82ad14a

Please sign in to comment.