Explorar o código

Prevent casting '' to int

Foppe Hemminga %!s(int64=6) %!d(string=hai) anos
pai
achega
2e8bf424e2
Modificáronse 1 ficheiros con 6 adicións e 2 borrados
  1. 6 2
      model.py

+ 6 - 2
model.py

@@ -40,8 +40,12 @@ def get_timestamp_stored():
     :return timestamp:
     """
     with open('timestamp.txt', 'r') as f:
-        this_timestamp_stored = f.read()
-    return int(this_timestamp_stored)
+        this_timestamp_stored_string = f.read()
+    if this_timestamp_stored_string.replace('.','',1).isdigit():
+        this_timestamp_stored = int(this_timestamp_stored_string)
+    else:
+        this_timestamp_stored = 0
+    return this_timestamp_stored
 
 
 def put_timestamp_stored(this_timestamp):