Skip to content

Commit

Permalink
Merge pull request #1 from T0biii/add-autoupdate
Browse files Browse the repository at this point in the history
add AutoUpdate for Nodes via Github Actions (bump API to 0.5.2)
  • Loading branch information
czerwonk authored Feb 19, 2024
2 parents 94be9f5 + 2d8e8df commit ebbc37c
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 102 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
43 changes: 43 additions & 0 deletions .github/workflows/updateNodes.yml
Original file line number Diff line number Diff line change
@@ -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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*-results.json
3 changes: 3 additions & 0 deletions cities_to_nodes_urls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"essen": "https://map.freifunk-essen.de/data/meshviewer.json"
}
206 changes: 104 additions & 102 deletions essen.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"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": "[email protected]",
"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"
}
38 changes: 38 additions & 0 deletions freifunkAPIupdater.py
Original file line number Diff line number Diff line change
@@ -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)
52 changes: 52 additions & 0 deletions node_stats.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions updateFreifunkAPI.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
python node_stats.py
python freifunkAPIupdater.py

0 comments on commit ebbc37c

Please sign in to comment.