Skip to content
This repository has been archived by the owner on Mar 14, 2022. It is now read-only.

Commit

Permalink
Reformat code and add Codacy badge
Browse files Browse the repository at this point in the history
  • Loading branch information
M0NsTeRRR committed Aug 6, 2019
1 parent 6055cee commit 191ff72
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/00b415afa9d64866a9bb0781499257c9)](https://www.codacy.com/app/M0NsTeRRR/Dynhost?utm_source=github.com&utm_medium=referral&utm_content=M0NsTeRRR/Dynhost&utm_campaign=Badge_Grade)
![Docker Automated build](https://img.shields.io/docker/cloud/automated/monsterrr/dynhost?style=flat-square)
![Docker Build Status](https://img.shields.io/docker/cloud/build/monsterrr/dynhost?style=flat-square)

Expand Down
18 changes: 10 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
import logging
from os import environ
from json import load
from sys import exit
from datetime import datetime
from sys import sys_exit
from time import sleep
from requests import get

Expand All @@ -66,7 +65,7 @@ def getIP(url):
if r.status_code == 200:
return r.text.strip()
else:
raise Exception('Can\'t get IP from : {url}'.format(url))
raise Exception('Can\'t get IP from : {url}'.format(url=url))

def updateDyndns(hostname, ip, username, password):
"""
Expand All @@ -83,10 +82,10 @@ def updateDyndns(hostname, ip, username, password):
config = {
"delay": int(environ.get("DYNHOST_DELAY", "1800")),
"dyndns": [
{
{
"hostname": environ.get("DYNHOST_HOSTANAME", ""),
"username": environ.get("DYNHOST_USERNAME", ""),
"password": environ.get("DYNHOST_PASSWORD", "")
"username": environ.get("DYNHOST_USERNAME", ""),
"password": environ.get("DYNHOST_PASSWORD", "")
}
]
}
Expand All @@ -95,8 +94,11 @@ def updateDyndns(hostname, ip, username, password):
try:
with open('config.json') as json_data_file:
config.update(load(json_data_file))
except Exception as e:
except FileNotFoundError:
pass
except Exception as e:
logger.error("{error}".format(error=e))
sys_exit(1)

try:
if "delay" not in config or 60 <= config["delay"] >= 3600:
Expand All @@ -107,7 +109,7 @@ def updateDyndns(hostname, ip, username, password):
raise Exception("config.json not filled properly")
except Exception as e:
logger.error("{error}".format(error=e))
exit(1)
sys_exit(1)

logger.info('Dynhost started')

Expand Down

0 comments on commit 191ff72

Please sign in to comment.