diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..306f32a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + # Check for updates to GitHub Actions every weekday + interval: "daily" \ No newline at end of file diff --git a/.github/workflows/updateNodes.yml b/.github/workflows/updateNodes.yml new file mode 100644 index 0000000..4e72246 --- /dev/null +++ b/.github/workflows/updateNodes.yml @@ -0,0 +1,43 @@ +name: Update nodes Count +on: + schedule: + - cron: '0 5 * * *' + workflow_dispatch: + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token + fetch-depth: 0 # otherwise, you will failed to push refs to dest repo + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.9 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install requests + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + + - name: Create local changes + run: sh ./updateFreifunkAPI.sh + + - name: Commit files + run: | + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git add essen.json + git commit -m "updated number of nodes" + + - name: Push changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c625c7a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*-results.json \ No newline at end of file diff --git a/cities_to_nodes_urls.json b/cities_to_nodes_urls.json new file mode 100644 index 0000000..a19f8c5 --- /dev/null +++ b/cities_to_nodes_urls.json @@ -0,0 +1,3 @@ +{ + "essen": "https://map.freifunk-essen.de/data/meshviewer.json" +} \ No newline at end of file diff --git a/essen.json b/essen.json index e33dc5b..7e68ffe 100644 --- a/essen.json +++ b/essen.json @@ -1,110 +1,112 @@ { - "name": "Freifunk Essen", - "url": "https://freifunk-essen.de", - "nodeMaps" : [ - { - "technicalType" : "ffmap", - "interval" : "1min", - "mapType" : "geographical", - "url" : "https://map.freifunk-essen.de/" - }, - { - "technicalType" : "ffmap", - "interval": "1min", - "mapType" : "list/status", - "url" : "https://map.freifunk-essen.de/data/nodelist.json" - } - ], - "location": { - "city": "Essen", - "country": "DE", - "lat": 51.45764372910066, - "lon": 7.011251449584961, - "address": { - "Name": "Freifunk Essen e. V.", - "Street": "Viehofer Str. 31", - "Zipcode": "45127" - } - }, - "contact": { - "email": "kontakt@freifunk-essen.de", - "facebook": "https://www.facebook.com/freifunk.essen", - "twitter": "@ffessen" - }, - "state": { - "nodes": 244, - "focus": [ - "infrastructure/backbone", - "Public Free Wifi", - "Social Community Building", - "Local services and content", - "Free internet access" - ], - "lastchange": "2021-05-18T19:01:00.496Z" - }, - "feeds": [ - { - "name": "EventsFeed", - "category": "others", - "type": "xml", - "url": "https://freifunk-rheinland.net/?plugin=all-in-one-event-calendar&controller=ai1ec_exporter_controller&action=export_events&cb=113863465" - } - ], - "support": { - "club": { - "name": "Freifunk Rheinland e.V.", - "url": "https://freifunk-rheinland.net" - }, - "donations": { - "campaigns": [ + "name": "Freifunk Essen", + "url": "https://freifunk-essen.de", + "nodeMaps": [ { - "provider": "boost", - "projectid": "2774" + "technicalType": "ffmap", + "interval": "1min", + "mapType": "geographical", + "url": "https://map.freifunk-essen.de/" }, { - "provider": "betterplace", - "projectid": "16049" + "technicalType": "ffmap", + "interval": "1min", + "mapType": "list/status", + "url": "https://map.freifunk-essen.de/data/nodelist.json" + } + ], + "location": { + "city": "Essen", + "country": "DE", + "address": { + "name": "Freifunk Essen e. V.", + "street": "Viehofer Str. 31", + "zipcode": "45127" + }, + "geoCode": { + "lat": 51.45764372910066, + "lon": 7.011251449584961 } - ] - } - }, - "techDetails": { - "firmware": { - "name": "gluon", - "url": "https://images.freifunk-essen.de/stable/factory/", - "docs": "https://freifunk-essen.de/anleitung#einrichten" }, - "networks" : { - "ipv6" : [ - { - "network" : "2a03:2260:1005::/64" - } - ], - "ipv4" : [ - { - "network" : "10.228.0.0/16" - } - ] + "contact": { + "email": "kontakt@freifunk-essen.de", + "facebook": "https://www.facebook.com/freifunk.essen", + "twitter": "@ffessen" }, - "dns" : [ - { - "nameserver" : [ - "2a03:2260:1005::8", - "2a03:2260:1005::16", - "2a03:2260:1005::32" - ], - "domainname" : "ffe" - } - ], - "routing": [ - "batman-adv" - ], - "updatemode": [ - "autoupdate" + "state": { + "nodes": 126, + "focus": [ + "infrastructure/backbone", + "Public Free Wifi", + "Social Community Building", + "Local services and content", + "Free internet access" + ], + "lastchange": "2024-02-18T23:54:42+00:00" + }, + "feeds": [ + { + "name": "EventsFeed", + "category": "others", + "type": "xml", + "url": "https://freifunk-rheinland.net/?plugin=all-in-one-event-calendar&controller=ai1ec_exporter_controller&action=export_events&cb=113863465" + } ], - "legals": [ - "institutions" - ] - }, - "api": "0.4.16" -} + "support": { + "club": { + "name": "Freifunk Rheinland e.V.", + "url": "https://freifunk-rheinland.net" + }, + "donations": { + "campaigns": [ + { + "provider": "boost", + "projectid": "2774" + }, + { + "provider": "betterplace", + "projectid": "16049" + } + ] + } + }, + "techDetails": { + "firmware": { + "name": "gluon", + "url": "https://images.freifunk-essen.de/stable/factory/", + "docs": "https://freifunk-essen.de/anleitung#einrichten" + }, + "networks": { + "ipv6": [ + { + "network": "2a03:2260:1005::/64" + } + ], + "ipv4": [ + { + "network": "10.228.0.0/16" + } + ] + }, + "dns": [ + { + "nameserver": [ + "2a03:2260:1005::8", + "2a03:2260:1005::16", + "2a03:2260:1005::32" + ], + "domainname": "ffe" + } + ], + "routing": [ + "batman-adv" + ], + "updatemode": [ + "autoupdate" + ], + "legals": [ + "institutions" + ] + }, + "api": "0.5.2" +} \ No newline at end of file diff --git a/freifunkAPIupdater.py b/freifunkAPIupdater.py new file mode 100644 index 0000000..ca3aab4 --- /dev/null +++ b/freifunkAPIupdater.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +import sys +import json +from datetime import datetime + + +file_path = "cities_to_nodes_urls.json" + +# Das Dictionary aus der JSON-Datei laden +with open(file_path, "r") as file: + cities_to_urls = json.load(file) + +for city, url in cities_to_urls.items(): + #Load API json + filenamecity = f"{city}.json" + with open(filenamecity, encoding="utf8") as json_data: + data = json.load(json_data) + json_data.close() + + #Load Results json for Update + filename_result = f"{city}-results.json" + with open(filename_result, encoding="utf8") as json_resultdata: + updatedata = json.load(json_resultdata) + json_resultdata.close() + + nodes = updatedata["online_nodes"] + + data["state"]["lastchange"] = datetime.now().astimezone().replace(microsecond=0).isoformat() + data["state"]["nodes"] = int(nodes) + print(city) + print(data["state"]["lastchange"]) + print(data["state"]["nodes"]) + try: + with open(filenamecity, 'w', encoding="utf8") as fn: + json.dump(data, fn, indent=4, ensure_ascii=False) + fn.close() + except OSError as ex: + sys.exit(ex) \ No newline at end of file diff --git a/node_stats.py b/node_stats.py new file mode 100644 index 0000000..279d905 --- /dev/null +++ b/node_stats.py @@ -0,0 +1,52 @@ +from datetime import datetime +from requests import get as rget +import sys +import json + +# Dateipfad zur JSON-Datei mit dem Dictionary +file_path = "cities_to_nodes_urls.json" + +# Das Dictionary aus der JSON-Datei laden +with open(file_path, "r") as file: + cities_to_urls = json.load(file) + + +def scrape(url): + '''returns remote json''' + try: + return rget(url, timeout=10).json() + except Exception as ex: + print(f"Error: {ex}") + +def save_to_json(filename, data): + try: + with open(filename, 'w', encoding="utf8") as fn: + json.dump(data, fn, indent=4, ensure_ascii=False) + except OSError as ex: + sys.exit(ex) + + + +# Durch das Dictionary von Stadt/Ort und URL iterieren +for city, url in cities_to_urls.items(): + nodes = scrape(url) + + if nodes: + ONLINE = 0 + NONCLIENT = 0 + for node in nodes['nodes']: + if node['is_online']: + ONLINE += 1 + if node['is_gateway']: + NONCLIENT += 1 + + now = datetime.now().strftime('%H:%M %d.%m.%Y') + ONLINE_NONCLIENT = ONLINE - NONCLIENT + result = { + "online": ONLINE, + "router": NONCLIENT, + "online_nodes": ONLINE_NONCLIENT, + "timestamp": now + } + filename = f"{city}-results.json" + save_to_json(filename, result) \ No newline at end of file diff --git a/updateFreifunkAPI.sh b/updateFreifunkAPI.sh new file mode 100755 index 0000000..23b639c --- /dev/null +++ b/updateFreifunkAPI.sh @@ -0,0 +1,3 @@ +#!/bin/bash +python node_stats.py +python freifunkAPIupdater.py \ No newline at end of file