Skip to content

Commit

Permalink
获取服务器时间. ref #1
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Nov 1, 2013
1 parent f799a7b commit ab47568
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/shanbay.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals
import datetime
import re
try:
from urllib import urlencode
Expand Down Expand Up @@ -192,3 +193,11 @@ def reply_topic(self, topic_id, content):
topic_url = 'http://www.shanbay.com/team/thread/%s/%s/'
topic_url = topic_url % (self.team_url, topic_id)
return response.url == topic_url

def server_date(self):
"""获取扇贝网服务器时间(北京时间)"""
date_str = requests.head('http://www.shanbay.com').headers['date']
date_utc = datetime.datetime.strptime(date_str,
'%a, %d %b %Y %H:%M:%S GMT')
# 北京时间 = UTC + 8 hours
return date_utc + datetime.timedelta(hours=8)
6 changes: 6 additions & 0 deletions tests/test_shanbay.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ def test_reply_topic():
"""小组回帖"""
content = 'reply'
shanbay.reply_topic(250459, content)


def test_server_date():
"""服务器时间"""
print('')
print shanbay.server_date()

0 comments on commit ab47568

Please sign in to comment.