import requests
# import json
import time
import uptime
from configparser import ConfigParser

tasks_dir = "C:\\GAPS\\Portal\\Tasks"


def ping():
    current_uptime = int(uptime.boottime().timestamp())
    kunde = findName()
    result = requests.get(f'http://localhost:5000/ping/{kunde}?uptime={current_uptime}')
    print(result.content)
    # print(json.dumps(json.loads(result.content), indent=2))


def findName():
    config = ConfigParser()
    with open(tasks_dir + '\\GAPS.ini', 'r') as stream:
        config.read_string('[default]\n' + stream.read())
        return config['default']['KUNDE'][1:-1]


while True:
    ping()
    time.sleep(60 * 60)


# from crontab import CronTab

# def ping():
#     cron = CronTab(user='root')
#     job = cron.new(command='python C:\\Projekte\\Python\\request.py')
#     job.hour.every(1)
#     cron.write()
