Created
April 27, 2018 12:22
-
-
Save tookdes/2784ab1cc55869c64acce52b641099ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding:utf-8 -*- | |
import time | |
import psutil | |
from subprocess import call | |
from subprocess import Popen | |
# 简介 | |
print "Steam Auto Rebooter v1.0" | |
print "" | |
print "Author: [email protected]" | |
print "" | |
# 获取 Steam.exe 的路径 | |
def get_speed(): | |
#统计平均速度的时间 | |
waittime = 60 | |
#获得当前所有网络流量,单位:MByte | |
recv1 = psutil.net_io_counters(pernic=False).bytes_recv/1024.0/1024.0 | |
#在间隔时间后重新统计流量,计算差值以获得平均速度 | |
time.sleep(waittime) | |
recv2 = psutil.net_io_counters(pernic=False).bytes_recv/1024.0/1024.0 | |
speed = (recv2 - recv1)/waittime | |
# 重启 Steam | |
def win_reboot_steam(): | |
for proc in psutil.process_iter(): | |
try: | |
pinfo = proc.as_dict(attrs=['pid', 'name']) | |
except psutil.NoSuchProcess: | |
pass | |
else: | |
if pinfo['name'] == 'Steam.exe': | |
steam_pid = pinfo['pid'] | |
steam_exe = psutil.Process(steam_pid).exe() | |
call('taskkill /F /IM Steam.exe') | |
Popen(steam_exe) | |
# 输入理想的下载速率,单位:MByte/s | |
pf_speed = raw_input("Input a good speed (MBytes/s): ") | |
print "" | |
# 进入主程序循环 | |
print "Running... Please don't close this window until you finish your downloading." | |
while 1: | |
speed = get_speed() | |
if speed < pf_speed: | |
win_reboot_steam() | |
time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment