#!/usr/bin/env python3 
#coding=utf-8

import os.path
import time, glob


dnes = str(time.strftime("%Y-%m-%d", time.localtime()))
dnessouc = str(time.strftime("%Y-%m-%d-%H-%M", time.localtime()))


        
#if os.path.isfile("/tmp/" + dnes + "-10-00.txt"):
soubory = glob.glob("/tmp/" + dnes + "-*")
while len(soubory) > 0:

  f3="{apikey:'591de95f4624eb625f31da8021eff934'}"
  soub = soubory.pop()
  if soub == "/tmp/" + dnessouc + ".txt":
    break
  #vyst = os.popen("curl -k -F \"upload_file=@/tmp/" + dnes + "-10-00.txt\" \"https://emon.solareco.cz/synchrolog.php?test=5&pridat=1&apikey=160803bce09c3822d7505f89ede55323\"").read()
  vyst = os.popen("curl -k -F \"upload_file=@" + soub + "\" \"http://kemon.solareco.cz/synchrolog.php?test=5&pridat=1&apikey=591de95f4624eb625f31da8021eff934\"").read()
  #print vyst
  if vyst != "0":
    os.system("rm " + soub)
