Skip to content

Commit

Permalink
Fix the bug.
Browse files Browse the repository at this point in the history
add update node to Mode2
add timeout to requests.get
  • Loading branch information
wuyingren committed Sep 4, 2017
1 parent 91c4848 commit 8f1befc
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,4 @@ dump.rdb
settings.py
.node_number.json
.topics_tester.json
rsync_vps.sh
14 changes: 7 additions & 7 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ def __init__(self):
self.SQ.open_datebase()
self.redis_conn=Redis()
self.load_config()

def Mode1(self):
logging.info('start mode1')
#start
#base
self.load_json()
# self.update_cookies()
try:
self.update_nodes()
except APIError as e:
pass

def Mode1(self):
logging.info('start mode1')
#start
self.get_rss()
self.tasker()
self.topic_ids_enqueue()
Expand All @@ -56,8 +57,7 @@ def Mode1(self):
def Mode2(self):
logging.info('start mode2')
#start
self.load_json()
# self.update_cookies()

self.get_rss()
self.topic_ids_enqueue()
self.tester_tasker()
Expand Down Expand Up @@ -128,7 +128,7 @@ def update_nodes(self):
if not nodes_time_status:
logging.info('update nodes')
try:
resp=self.s.get('https://www.v2ex.com/api/nodes/all.json')
resp=self.s.get('https://www.v2ex.com/api/nodes/all.json', timeout=10)
except requests.exceptions.RequestException as e:
logging.error('update_node failed.')
logging.error('proxy_status: %s' % settings.i_proxy_enable)
Expand Down
4 changes: 2 additions & 2 deletions v2ex_base/log_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def log_in(self,try_time):
raise LogError('try time too much.')
#1
try:
r1=self.s.get('https://www.v2ex.com/signin')
r1=self.s.get('https://www.v2ex.com/signin', timeout=10)
except requests.exceptions.RequestException as e:
logging.error('log in error')
logging.error(try_time)
Expand Down Expand Up @@ -82,7 +82,7 @@ def log_in(self,try_time):

def save_cookies(self):
logging.debug('start save_cookies')
resp=self.s.get('https://www.v2ex.com/go/flamewar')
resp=self.s.get('https://www.v2ex.com/go/flamewar', timeout=10)
if '登录' in resp.text:
raise LogError('log failed.')
with open('.cookies.json','w') as f:
Expand Down
2 changes: 1 addition & 1 deletion v2ex_spider/base_spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self,url,sleep_time):
def spider(self):
logging.debug('start spider.')
try:
resp=self.s.get(self.url)
resp=self.s.get(self.url, timeout=10)
except requests.exceptions.RequestException as e:
logging.error('spider failed.')
logging.error('proxy_status: %s' % settings.proxy_enable)
Expand Down
2 changes: 1 addition & 1 deletion v2ex_spider/rss_spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def latest_and_hot(self):
logging.debug('start latest_and_hot')
for url in self.latest_hot_api:
try:
resp=self.s.get(url)
resp=self.s.get(url, timeout=10)
except requests.exceptions.RequestException as e:
logging.error('latest_and_hot error')
logging.error('proxy_status: %s' % self.proxy_enable)
Expand Down
6 changes: 3 additions & 3 deletions v2ex_tester/topic_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def web_test(self,t_id,status):
url='https://www.v2ex.com/t/%s' % str(t_id)
n_time=int(time.time())
try:
resp=self.s.get(url)
resp=self.s.get(url, timeout=10)
except requests.exceptions.RequestException as e:
logging.error('web_test failed.')
logging.error('proxy_status: %s' % settings.proxy_enable)
Expand Down Expand Up @@ -85,7 +85,7 @@ def api_test(self,t_id,status):
url='https://www.v2ex.com/api/topics/show.json?id=%s' % str(t_id)
n_time=int(time.time())
try:
resp=self.s_a.get(url)
resp=self.s_a.get(url, timeout=10)
except requests.exceptions.RequestException as e:
logging.error('api_test failed.')
logging.error('proxy_status: %s' % settings.proxy_enable)
Expand Down Expand Up @@ -126,5 +126,5 @@ def start(t_id,sleep_time):

if __name__ == '__main__':
# start(1,5)
start(367743,5)
start(375807,5)
print('finish!')

0 comments on commit 8f1befc

Please sign in to comment.