mozillazg / python-shanbay-team-assistant

扇贝网 (www.shanbay.com) 小组管理助手
MIT License
18 stars 2 forks source link

只有达到特定时间才执行踢人相关的操作 #1

Closed mozillazg closed 10 years ago

mozillazg commented 11 years ago

时间格式: hh:mm

postblogera commented 11 years ago

北京时间 23:00以后。时间获取方式?系统时间还是网络获取?因为考虑到软件使用者可能是海外用户。

mozillazg commented 10 years ago

可以通过 response header 获取服务器时间:

$curl -I www.shanbay.com
HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Mon, 21 Oct 2013 04:35:18 GMT    # 这里就是服务器时间
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Vary: Accept-Language, Cookie
Content-Language: zh-cn
Set-Cookie: username=; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/
Set-Cookie: csrftoken=1946d1b1cd94e23344907e59fd8b3bac; Domain=shanbay.com; expires=Mon, 20-Oct-2014
 04:35:18 GMT; Max-Age=31449600; Path=/
Set-Cookie: userid=; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/

需要将这个 Date 由 GMT 转化为北京时间

In [5]: requests.head('http://www.shanbay.com').headers['date']
Out[5]: 'Mon, 21 Oct 2013 04:37:55 GMT'
In [6]: # 转换为北京时间
mozillazg commented 10 years ago

close via 98cb18bc