Skip to content

Commit 2f7bbca

Browse files
committed
Fix #3, handle cannot comment within 10 minutes after downloaded
1 parent d347b67 commit 2f7bbca

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 0.0.6 (2016-07-27)
4+
5+
* 自动处理刚刚下载完需要等待 10 分钟才能评论的情况。
6+
37
### 0.0.5 (2016-07-26)
48

59
* 实现根据当前评星打分,不对资源评分造成不良影响。

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525

2626
### 已实现特性
2727

28-
1. 一次登录,评论所有待评论资源。
28+
- [x] 一次登录,评论所有待评论资源。
2929

30-
2. 适应 CSDN 两个资源评价至少间隔 60S 的规则。
30+
- [x] 适应 CSDN 两个资源评价至少间隔 60S 的规则。
3131

32-
3. 根据现有评星打分,并根据打分选择对应的评语(目前都是一个英文短句),不会对资源的评星产生不良影响。
32+
- [x] 根据现有评星打分,并根据打分选择对应的评语(目前都是一个英文短句),不会对资源的评星产生不良影响。
33+
34+
- [x] 自动处理刚刚下载完需要等待 10 分钟才能评论的情况。
3335

3436
```
3537
Author : Zhuang Ma

csdncommenter/csdncommenter.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ def getSourceItems(self):
8181
pattern = re.compile(r'/detail/([^/]+)/(\d+)#comment')
8282

8383
for n in range(1, pagecount + 1):
84+
if n == 1:
85+
self.waitUncommentableSourceIfNecessary()
8486
url = 'http://download.csdn.net/my/downloads/%d' % n
8587
html = self.getUrlContent(self.sess, url)
8688
if html is None:
8789
continue
8890
soup = BeautifulSoup(html)
8991
sourcelist = soup.findAll('a', attrs={'class' : 'btn-comment'})
90-
if sourcelist is None:
92+
if sourcelist is None or len(sourcelist) == 0:
9193
continue
9294
for source in sourcelist:
9395
href = source.get('href', None)
@@ -98,6 +100,22 @@ def getSourceItems(self):
98100

99101
return len(self.sourceitems) > 0
100102

103+
def waitUncommentableSourceIfNecessary(self):
104+
"""souce cannot comment within 10 minutes after download"""
105+
url = 'http://download.csdn.net/my/downloads/1'
106+
maxMinutes = 11
107+
for i in range(0, maxMinutes):
108+
html = self.getUrlContent(self.sess, url)
109+
if html is None:
110+
break
111+
soup = BeautifulSoup(html)
112+
sourcelist = soup.findAll('span', attrs={'class' : 'btn-comment'})
113+
if sourcelist is None or len(sourcelist) == 0:
114+
print('None uncommentable source now!')
115+
break
116+
print('Waiting for uncommentable source count down %d minutes.' % (maxMinutes-i))
117+
time.sleep(60)
118+
101119
def getPageCount(self):
102120
"""get downloaded resources page count"""
103121
url = 'http://download.csdn.net/my/downloads'
@@ -108,7 +126,7 @@ def getPageCount(self):
108126
soup = BeautifulSoup(html)
109127

110128
pagelist = soup.findAll('a', attrs={'class' : 'pageliststy'})
111-
if pagelist is None:
129+
if pagelist is None or len(pagelist) == 0:
112130
return 0
113131

114132
lasthref = pagelist[len(pagelist) - 1].get('href', None)
@@ -157,7 +175,7 @@ def getSourceRating(self, sourceid):
157175

158176
soup = BeautifulSoup(html)
159177
ratingspan = soup.findAll('span', attrs={'class': 'star-yellow'})
160-
if ratingspan is None:
178+
if ratingspan is None or len(ratingspan) == 0:
161179
return rating
162180

163181
ratingstyle = ratingspan[0].get('style', None)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name='csdncommenter',
9-
version='0.0.5',
9+
version='0.0.6',
1010
description='CSDN 已下载资源自动批量评论脚本',
1111
long_description=open('README.md').read(),
1212
url='https://github.com/mzlogin/csdncommenter',

0 commit comments

Comments
 (0)