代码如下:
com.example.cli.Tool (which contains the main)
com.example.cli.HelperUtils
com.example.cli.CustomEnums
输出:
macraw = []
for user in c.get_users():
macraw.append(user.get('mac'))
count = 0
x = 0
while (count < len(macraw)):
client_list = c.get_client(macraw[x])
raw_tx = float(client_list.get('tx_bytes'))
byte_to_gb = raw_tx / 10**9
byte_to_mb = raw_tx / 10**6
timestamp1 = client_list['first_seen']
timestamp2 = client_list['last_seen']
readable1 = datetime.fromtimestamp(timestamp1)
readable2 = datetime.fromtimestamp(timestamp2)
dailytime = datetime.today() - timedelta(days=1)
if readable2 > dailytime:
if byte_to_gb > 1:
print '<b>%s</b> last seen: <b>%s</b> total download usage --> <b>%s</b> GB' % (client_list.get('hostname'),readable2,round(byte_to_gb, 2))
else:
print '<b>%s</b> last seen: <b>%s</b> total download usage --> <b>%s</b> MB' % (client_list.get('hostname'),readable2,round(byte_to_mb, 2))
else:
pass
count = count + 1
x = x + 1
print '<br/><br/>'
我试图摆脱行之间的所有空白。在实施timedelta的1天之前,还好。每行都正确 彼此接壤。现在,由于我要删除一些不需要的行,因此就好像出于某种原因它们已被替换为空白行。
我只是希望它们消失并在彼此之上打印下一行。
感谢您的任何输入:)
编辑:
下面是删除大于1天的日期时间之前的代码:
History of All Clients Last 24 Hours
HP1972B8 last seen: 2019-03-15 10:20:13 total download usage --> 2.95 MB
LAPTOP-H3D3OG4A last seen: 2019-03-15 10:20:13 total download usage --> 35.62 MB
HPF91643 last seen: 2019-03-15 10:20:55 total download usage --> 0.95 MB
HP823BA5 last seen: 2019-03-15 10:20:55 total download usage --> 10.75 MB
Nevans-iPhone last seen: 2019-03-14 10:38:52 total download usage --> 71.5 GB
Jaymes-iPhone-2 last seen: 2019-03-15 10:20:55 total download usage --> 1.79 MB
Shawns-iPhone last seen: 2019-03-14 12:13:31 total download usage --> 1.91 GB
此部分的输出很好,它将一个接一个地打印出来。
是的,此脚本(CGI)中有一些HTML
答案 0 :(得分:0)
if readable2 > dailytime:
if byte_to_gb > 1:
print '<b>%s</b> last seen: <b>%s</b> total download usage --> <b>%s</b> GB \n' % (client_list.get('hostname'),readable2,round(byte_to_gb, 2))
else:
print '<b>%s</b> last seen: <b>%s</b> total download usage --> <b>%s</b> MB \n' % (client_list.get('hostname'),readable2,round(byte_to_mb, 2))
else:
pass
count = count + 1
x = x + 1
在我看来,最后的打印声明可能是罪魁祸首。您可能想从标准库中检出logging module,我认为它可能会进一步满足您的需求。另外,如果您不熟悉Python,则python 3可能是更好的选择。