Advertisement
aveBHS

Autostatus VK - Server uptime

Feb 27th, 2020
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. import time
  2. import vk_api
  3. import os
  4.  
  5. def get_uptime():
  6.     try:
  7.         f = open( "/proc/uptime" )
  8.         contents = f.read().split()
  9.         f.close()
  10.     except:
  11.         return "Cannot open uptime file: /proc/uptime"
  12.  
  13.     total_seconds = float(contents[0])
  14.  
  15.     # Helper vars:
  16.     MINUTE  = 60
  17.     HOUR    = MINUTE * 60
  18.     DAY     = HOUR * 24
  19.  
  20.     # Get the days, hours, etc:
  21.     days    = int( total_seconds / DAY )
  22.     hours   = int( ( total_seconds % DAY ) / HOUR )
  23.     minutes = int( ( total_seconds % HOUR ) / MINUTE )
  24.     seconds = int( total_seconds % MINUTE )
  25.  
  26.     # Build up the pretty string (like this: "N days, N hours, N minutes, N seconds")
  27.     string = ""
  28.     if days > 0:
  29.         string += str(days) + " " + (days == 1 and "day" or "days" ) + ", "
  30.     if len(string) > 0 or hours > 0:
  31.         string += str(hours) + " " + (hours == 1 and "hour" or "hours" ) + ", "
  32.     if len(string) > 0 or minutes > 0:
  33.         string += str(minutes) + " " + (minutes == 1 and "minute" or "minutes" )
  34.     #string += str(seconds) + " " + (seconds == 1 and "second" or "seconds" )
  35.  
  36.     return string
  37.  
  38. API = vk_api.VkApi(token='')
  39.  
  40. while True:
  41.     try:
  42.         uptime = get_uptime()
  43.         API.method('status.set', {'text': f'💻 Server uptime: {uptime} | BHS Studio'})
  44.         print('Seted, sleep')
  45.         time.sleep(60)
  46.     except Exception as err:
  47.         print(err)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement