Skip to content

Commit

Permalink
Merge pull request #227 from Glas42/main
Browse files Browse the repository at this point in the history
Update server.py
  • Loading branch information
Glas42 authored Feb 24, 2024
2 parents 5b3a074 + 16b7585 commit 6316903
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""This file is used to communicate with the main app server. The file will not be used without consent from the user."""
import requests
import json
import time
import os
import src.settings as settings
from src.translator import Translate
import src.variables as var
Expand Down Expand Up @@ -102,8 +104,31 @@ def GetUserCount():
def Ping():
"""Will send a ping to the server, doesn't send any data."""
try:
url = 'https://crash.tumppi066.fi/ping'
requests.get(url, timeout=1)
print("Ping!")
if os.path.exists(var.PATH + f'/last_ping.txt'):
with open(var.PATH + f'/last_ping.txt', 'r') as file:
file_content = file.read().strip()
if file_content != "":
last_ping = float(file_content)
else:
last_ping = 0
file.close()
else:
with open(var.PATH + f'/last_ping.txt', 'w') as file:
file.seek(0)
file.truncate()
file.write(str(0))
file.close()
last_ping = 0
if last_ping + 59 < time.time():
url = 'https://crash.tumppi066.fi/ping'
requests.get(url, timeout=1)
print("Ping!")
with open(var.PATH + f'/last_ping.txt', 'w') as file:
file.seek(0)
file.truncate()
file.write(str(time.time()))
file.close()
else:
print("Last ping was less than 60 seconds ago.")
except:
pass

0 comments on commit 6316903

Please sign in to comment.