update flake, add module
This commit is contained in:
parent
1c5b52eab0
commit
7ce1a3ab3a
5 changed files with 172 additions and 48 deletions
87
eintopf-radar-sync.py
Normal file
87
eintopf-radar-sync.py
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
#!/bin/env python
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
print("hello world")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# Eintopf config
|
||||||
|
# Get Authorization token through login request
|
||||||
|
# http://localhost:3333/api/v1/swagger#/auth/login
|
||||||
|
eintopf_url = "https://karlsunruh.project-insanity.org"
|
||||||
|
eintopf_api_endpoint = eintopf_url + "/api/v1/events/"
|
||||||
|
eintopf_headers = {
|
||||||
|
"Authorization": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjJlZTA3MDgzLTVjYzktNGM5MS04ZThkLTFkNjhkNzZhZDc5YiIsIm5iZiI6MTQ0NDQ3ODQwMH0.hDQiwXBpIfEiOLP1QAXb9q8eQeaslIHlLN3CBdkHzQKdH0eZZCViEooIyKdZmoncQ0NQAExaitUbFnn6HcAITy8buBhIep6g0fRrfnTgqYOwelhJCXKySUwLe72sEthElaOfISKhvS9Tss4zd3NkNIfFDBVXMnmtOUXmrmlt7Z-5y9p4IiftqBKRA-Md4Uc6iiylSPi7ZZ0r23p2NrYJMyTiWS7-PfhNUt8GJ7HXjmX08VDTQs2lBnQH4c5n1lLCRkUUGpSgPg_2yBnSWN3z_3gQ_mOBNbvYTI2rc4i5fh6eQMIp4B5iL4Kt4Ebe-ikwQFXQ2INWCmemtQtB2pyVMg",
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Radar config
|
||||||
|
radar_group_id = "436012"
|
||||||
|
radar_api_endpoint = "https://radar.squat.net/api/1.2/search/events.json?fields=title,offline,date_time,body&facets[group][]=" + radar_group_id
|
||||||
|
|
||||||
|
def strip_html_tags(text):
|
||||||
|
soup = BeautifulSoup(text, "html.parser")
|
||||||
|
return soup.get_text()
|
||||||
|
|
||||||
|
def eintopf_post_event(title, location, description, time_start, time_end):
|
||||||
|
payload = {
|
||||||
|
"address": "Karlsruhe",
|
||||||
|
"category": "",
|
||||||
|
"description": strip_html_tags(description),
|
||||||
|
"image": "",
|
||||||
|
"involved": [
|
||||||
|
{
|
||||||
|
"description": "Anonymous",
|
||||||
|
"name": "Anonymous"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"lat": 0,
|
||||||
|
"lng": 0,
|
||||||
|
"location": location,
|
||||||
|
"name": title,
|
||||||
|
"organizers": ["Anonymous"],
|
||||||
|
"ownedBy": ["Anonymous"],
|
||||||
|
"published": True,
|
||||||
|
"start": time_start,
|
||||||
|
"end": time_end,
|
||||||
|
"tags": ["karlsruhe"],
|
||||||
|
"topic": "Veranstaltung"
|
||||||
|
}
|
||||||
|
response = requests.post(eintopf_api_endpoint, json=payload, headers=eintopf_headers)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
response = requests.get(radar_api_endpoint)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
data = response.json()
|
||||||
|
events = data["result"]
|
||||||
|
|
||||||
|
radar_events = []
|
||||||
|
|
||||||
|
for event in events:
|
||||||
|
|
||||||
|
event = events[event]
|
||||||
|
title = event["title"]
|
||||||
|
time_start = event["date_time"][0]["time_start"]
|
||||||
|
time_end = event["date_time"][0]["time_end"]
|
||||||
|
location = event["offline"][0]['title']
|
||||||
|
description = event["body"]['value']
|
||||||
|
|
||||||
|
if eintopf_post_event(title, location, description, time_start, time_end):
|
||||||
|
print("Event successfully added:")
|
||||||
|
print(f"Title: {title}")
|
||||||
|
print(f"Time Start: {time_start}")
|
||||||
|
print(f"Location: {location}")
|
||||||
|
print('-' * 40)
|
||||||
|
else:
|
||||||
|
print("Submitting event failed")
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print(f"Failed to retrieve data. Status code: {response.status_code}")
|
||||||
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
import requests
|
|
||||||
import json
|
|
||||||
|
|
||||||
url = "https://radar.squat.net/api/1.2/search/events.json?fields=title,offline,date_time,body&facets[group][]=436012"
|
|
||||||
response = requests.get(url)
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
|
||||||
data = response.json()
|
|
||||||
events = data["result"]
|
|
||||||
|
|
||||||
radar_events = []
|
|
||||||
|
|
||||||
for event in events:
|
|
||||||
|
|
||||||
event = events[event]
|
|
||||||
title = event["title"]
|
|
||||||
time_start = event["date_time"][0]["time_start"]
|
|
||||||
time_end = event["date_time"][0]["time_end"]
|
|
||||||
location = event["offline"][0]['title']
|
|
||||||
description = event["body"]['value']
|
|
||||||
|
|
||||||
# Print the formatted output
|
|
||||||
print(f"Title: {title}")
|
|
||||||
print(f"Time Start: {time_start}")
|
|
||||||
print(f"Location: {location}")
|
|
||||||
#print(f"Description: {body}")
|
|
||||||
print('-' * 40)
|
|
||||||
else:
|
|
||||||
print(f"Failed to retrieve data. Status code: {response.status_code}")
|
|
||||||
|
|
||||||
14
flake.lock
generated
14
flake.lock
generated
|
|
@ -5,11 +5,11 @@
|
||||||
"systems": "systems"
|
"systems": "systems"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1726560853,
|
"lastModified": 1731533236,
|
||||||
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "flake-utils",
|
"repo": "flake-utils",
|
||||||
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -20,16 +20,16 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1730883749,
|
"lastModified": 1734991663,
|
||||||
"narHash": "sha256-mwrFF0vElHJP8X3pFCByJR365Q2463ATp2qGIrDUdlE=",
|
"narHash": "sha256-8T660guvdaOD+2/Cj970bWlQwAyZLKrrbkhYOFcY1YE=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "dba414932936fde69f0606b4f1d87c5bc0003ede",
|
"rev": "6c90912761c43e22b6fb000025ab96dd31c971ff",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"id": "nixpkgs",
|
"id": "nixpkgs",
|
||||||
"ref": "nixos-24.05",
|
"ref": "nixos-24.11",
|
||||||
"type": "indirect"
|
"type": "indirect"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
39
flake.nix
39
flake.nix
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "nixpkgs/nixos-24.05";
|
nixpkgs.url = "nixpkgs/nixos-24.11";
|
||||||
# Required for multi platform support
|
# Required for multi platform support
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
};
|
};
|
||||||
|
|
@ -9,23 +9,40 @@
|
||||||
flake-utils.lib.eachDefaultSystem (system:
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs { inherit system; };
|
pkgs = import nixpkgs { inherit system; };
|
||||||
|
|
||||||
start =
|
|
||||||
pkgs.writeShellScriptBin "start" ''
|
|
||||||
set -e
|
|
||||||
${pkgs.python3}/bin/python eintopf-sync.py
|
|
||||||
'';
|
|
||||||
in
|
in
|
||||||
{
|
rec {
|
||||||
devShell = pkgs.mkShell {
|
devShell = pkgs.mkShell {
|
||||||
packages = with pkgs; with python3Packages; [
|
packages = with pkgs; with python3Packages; [
|
||||||
python3
|
python
|
||||||
requests
|
requests
|
||||||
|
beautifulsoup4
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
packages = { inherit start; };
|
packages = flake-utils.lib.flattenTree {
|
||||||
defaultPackage = start;
|
eintopf-radar-sync = pkgs.python3Packages.buildPythonApplication {
|
||||||
|
pname = "eintopf-radar-sync";
|
||||||
|
version = "0.0.1";
|
||||||
|
format = "other";
|
||||||
|
|
||||||
|
src = self;
|
||||||
|
|
||||||
|
dependencies = with pkgs.python3Packages; [
|
||||||
|
python
|
||||||
|
requests
|
||||||
|
beautifulsoup4
|
||||||
|
];
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
install -Dm755 ${./eintopf-radar-sync.py} $out/bin/eintopf-radar-sync
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
defaultPackage = packages.eintopf-radar-sync;
|
||||||
|
|
||||||
|
# eintopf-radar-sync service module
|
||||||
|
nixosModule = (import ./module.nix);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
50
module.nix
Normal file
50
module.nix
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
{config, lib, pkgs, ...}:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
cfg = config.services.eintopf-radar-sync;
|
||||||
|
|
||||||
|
in
|
||||||
|
{
|
||||||
|
|
||||||
|
options = {
|
||||||
|
services.eintopf-radar-sync = {
|
||||||
|
|
||||||
|
enable = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Enable eintopf-radar-sync daemon.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
|
systemd.services."eintopf-radar-sync" = {
|
||||||
|
description = "eintopf-radar-sync script";
|
||||||
|
after = [ "network.target" ];
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
environment.PYTHONUNBUFFERED = "1";
|
||||||
|
serviceConfig = {
|
||||||
|
ExecStart = "${pkgs.iwd-autocaptiveauth}/bin/iwd-autocaptiveauth --profileDir ${pkgs.iwd-autocaptiveauth}/profiles";
|
||||||
|
Restart = "on-failure";
|
||||||
|
User = "iwd-autocaptiveauth";
|
||||||
|
RestartSec = 30;
|
||||||
|
WorkingDirectory = ''${pkgs.iwd-autocaptiveauth}/'';
|
||||||
|
};
|
||||||
|
restartIfChanged = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
maintainers = with lib.maintainers; [ onny ];
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue