Skip to content

Commit

Permalink
get_data uses Python3 due to some problems with previous script
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavouk106 committed Apr 4, 2023
1 parent 4b9c267 commit 05512d9
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions get_data.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/python
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import serial, time, os.path, urllib, re
#from urllib import urlopen
from urllib.request import urlopen

debug = False
debug = True

path_to_files = '/tmp/'

Expand Down Expand Up @@ -114,7 +114,7 @@ def debug_print(text):
# Udaje z bazenu/meteobudky
meteo_file = open(path_to_files + 'meteo', 'w')
try:
data = urllib.urlopen("http://meteo.pavoukovo.cz/meteo").read().decode() # Otevrit soubor
data = urlopen("http://meteo.pavoukovo.cz/meteo", data=None, timeout=3).read().decode() # Otevrit soubor
if data.find("html") == -1:
meteo_file.write(data)
lines = data.splitlines()
Expand All @@ -126,7 +126,7 @@ def debug_print(text):
else:
for i in range(0, 7):
meteo_file.write("%s\n" % u"---") # Kdyz se nepodari otevrit soubor, zapsat ---
debug_print("DEBUG: " + time.strftime("%H:%M:%S") + " HTTP meteo read failed, remote file not found")
debug_print("DEBUG: " + time.strftime("%H:%M:%S") + " HTTP meteo read failed, remote file not found")
except:
for i in range(0, 7):
meteo_file.write("%s\n" % u"---") # Kdyz se nepodari otevrit soubor, zapsat ---
Expand All @@ -141,7 +141,7 @@ def debug_print(text):
# Teploty z kotelny
temps_file = open(path_to_files + 'temps', 'w')
try:
data = urllib.urlopen("http://control.pavoukovo.cz/temps").read().decode() # Otevrit soubor
data = urlopen("http://control.pavoukovo.cz/temps", data=None, timeout=3).read().decode() # Otevrit soubor
if data.find("html") == -1:
temps_file.write(data)
debug_print("DEBUG: HTTP temps read ok")
Expand All @@ -158,20 +158,20 @@ def debug_print(text):
# Rychlost vetru
wind_file = open(path_to_files + 'wind', 'w')
try:
debug_print("Wind start")
data = urllib.urlopen("http://wind.pavoukovo.cz/wind").read().decode() # Otevrit soubor
debug_print("Wind opened")
debug_print("DEBUG: Wind start")
data = urlopen("http://wind.pavoukovo.cz/wind", data=None, timeout=3).read().decode() # Otevrit soubor
debug_print("DEBUG: Wind opened")
if data.find("html") == -1:
debug_print("Wind HTML found")
debug_print("DEBUG: Wind HTML found")
wind_file.write(data)
debug_print("DEBUG: HTTP wind read ok")
else:
debug_print("Wind bad reply")
debug_print("DEBUG: Wind bad reply")
for i in range(0, 5):
wind_file.write("%s\n" % u"---") # Kdyz se nepodari otevrit soubor, zapsat ---
debug_print("DEBUG: " + time.strftime("%H:%M:%S") + " HTTP wind read failed, remote file not found")
except:
debug_print("Wind open failed")
debug_print("DEBUG: Wind open failed")
for i in range(0, 5):
wind_file.write("%s\n" % u"---") # Kdyz se nepodari otevrit soubor, zapsat ---
debug_print("DEBUG: " + time.strftime("%H:%M:%S") + " HTTP wind read failed")
Expand Down

0 comments on commit 05512d9

Please sign in to comment.