Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrocan committed Sep 7, 2023
0 parents commit 727bad6
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: 2
updates:
- package-ecosystem: "docker"
directory: "web_server/"
schedule:
interval: "daily"
31 changes: 31 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Linting

on: # yamllint disable-line rule:truthy
push:
branches-ignore:
- master

workflow_dispatch:

permissions: read-all

jobs:
check:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.CUSTOM_PTA }}

- name: Lint Code Base with MegaLinter
uses: oxsecurity/megalinter/flavors/python@beta
env:
VALIDATE_ALL_CODEBASE: true
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
megalinter-reports/
.ruff_cache
api.txt
15 changes: 15 additions & 0 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
DISABLE_LINTERS:
- SPELL_CSPELL
SHOW_ELAPSED_TIME: true
ENABLE_LINTERS:
- YAML_YAMLLINT
- MARKDOWN_MARKDOWNLINT
- PYTHON_PYLINT
- PYTHON_BLACK
- PYTHON_FLAKE8
- DOCKERFILE_HADOLINT
ANSIBLE_DIRECTORY: .
PRE_COMMANDS:
- command: pip install requests
venv: requests
35 changes: 35 additions & 0 deletions fronius.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Importing data from the Fronius device.
"""
import requests # pylint: disable=import-error
from requests.exceptions import HTTPError # pylint: disable=import-error

with open("api.txt", "r", encoding="utf8") as file:
URL = file.read().rstrip()

# URL = "http://localhost:8080/GetPowerFlowRealtimeData.fcgi"


def check_values():
"""
Actual logic of getting the JSON file with data and analyzing parts of it.
"""
try:
response = requests.get(URL, timeout=5)
response.raise_for_status()
jsondata = response.json()

print("Timestamp:", jsondata["Head"]["Timestamp"])
print("Currently:", jsondata["Body"]["Data"]["Site"]["P_PV"])
print("Day:", jsondata["Body"]["Data"]["Site"]["E_Day"])
print("Year:", jsondata["Body"]["Data"]["Site"]["E_Year"])
print("Total:", jsondata["Body"]["Data"]["Site"]["E_Total"])

except HTTPError as http_err:
print(f"HTTP error occurred: {http_err}")
except Exception as err: # pylint: disable=broad-except
print(f"Other error occurred: {err}")


if __name__ == "__main__":
check_values()
9 changes: 9 additions & 0 deletions web_server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM nginx:1.25.2

HEALTHCHECK CMD curl --fail http://localhost:80 || exit 1

LABEL testing-service="Mocking Fronius Inverter"
USER nginx

COPY GetPowerFlowRealtimeData.fcgi /usr/share/nginx/html/GetPowerFlowRealtimeData.fcgi

38 changes: 38 additions & 0 deletions web_server/GetPowerFlowRealtimeData.fcgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"Body" : {
"Data" : {
"Inverters" : {
"1" : {
"DT" : 110,
"E_Day" : 5961,
"E_Total" : 236993,
"E_Year" : 236993.109375,
"P" : 1091
}
},
"Site" : {
"E_Day" : 5961,
"E_Total" : 236993,
"E_Year" : 236993.109375,
"Meter_Location" : "unknown",
"Mode" : "produce-only",
"P_Akku" : null,
"P_Grid" : null,
"P_Load" : null,
"P_PV" : 1091,
"rel_Autonomy" : null,
"rel_SelfConsumption" : null
},
"Version" : "12"
}
},
"Head" : {
"RequestArguments" : {},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2021-05-06T14:54:37+03:00"
}
}

0 comments on commit 727bad6

Please sign in to comment.