Skip to content
This repository has been archived by the owner on Apr 28, 2024. It is now read-only.

Commit

Permalink
MOD: 引入 flake8 和 pylint 检查,让代码看起来更 Pythonic
Browse files Browse the repository at this point in the history
  • Loading branch information
whusnoopy committed Oct 7, 2018
1 parent 60ec28a commit 5aa565c
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 172 deletions.
8 changes: 8 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[MASTER]

[MESSAGE CONTROL]
disable=missing-docstring,
invalid-name

[FORMAT]
max-line-length=100
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ name = "pypi"
[dev-packages]
pylint = "*"
ipython = "*"
flake8 = "*"
"autopep8" = "*"

[packages]
requests = "*"
Expand Down
124 changes: 65 additions & 59 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions crawl/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ def get_album_summary(album_id, uid=crawler.uid):
photo_list = layer['list']
photo_count = len(photo_list)
for idx, p in enumerate(photo_list):
id = int(p['id'])
pid = int(p['id'])
date_str = p['date'] if config.py3 else p['date'].encode('utf8')
photo = {
'id': id,
'id': pid,
'uid': uid,
'album_id': album_id,
'pos': idx,
Expand All @@ -66,17 +66,17 @@ def get_album_summary(album_id, uid=crawler.uid):
'src': get_image(p['large']),
'comment': p['commentCount'],
'share': p['shareCount'],
'like': get_likes(id, 'photo'),
'like': get_likes(pid, 'photo'),
'view': p['viewCount']
}
Photo.insert(**photo).on_conflict('replace').execute()
if photo['comment']:
get_comments(id, 'photo', owner=uid)
get_comments(pid, 'photo', owner=uid)
if photo['comment'] or photo['share']:
get_comments(id, 'photo', global_comment=True, owner=uid)
get_comments(pid, 'photo', global_comment=True, owner=uid)

print(u' photo {id}: {title}, {comment}/{share}/{like}/{view}'.format(
id=id,
print(u' photo {pid}: {title}, {comment}/{share}/{like}/{view}'.format(
pid=pid,
title=p['title'][:24],
comment=photo['comment'],
share=photo['share'],
Expand All @@ -90,20 +90,20 @@ def get_album_summary(album_id, uid=crawler.uid):
def get_album_list_page(page, uid=crawler.uid):
param = {
'offset': page*config.ITEMS_PER_PAGE,
'limit': config.ITEMS_PER_PAGE
'limit': config.ITEMS_PER_PAGE
}
resp = crawler.get_url(config.ALBUM_LIST_URL.format(uid=uid), param)
albums = json.loads(re.findall(r"'albumList': (\[.*\]),", resp.text)[0])

for a in albums:
id = int(a['albumId'])
print(u' album {id}: {name}, has {count} photos'.format(
id=id,
aid = int(a['albumId'])
print(u' album {aid}: {name}, has {count} photos'.format(
aid=aid,
name=a['albumName'],
count=a['photoCount']
))
if a["photoCount"]:
get_album_summary(id, uid)
get_album_summary(aid, uid)

count = len(albums)
print(' get {count} albums on list page {page}'.format(count=count, page=page))
Expand Down
21 changes: 10 additions & 11 deletions crawl/blog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# coding: utf8

from datetime import datetime
import json

from config import config
from models import Blog
Expand All @@ -25,9 +24,9 @@ def load_blog_list(page, uid=crawler.uid):
r = crawler.get_json(config.BLOG_LIST_URL.format(uid=uid), {'curpage': page})

for b in r['data']:
id = int(b['id'])
bid = int(b['id'])
blog = {
'id': id,
'id': bid,
'uid': uid,
't': datetime.strptime(b['createTime'], "%y-%m-%d %H:%M:%S"),
'category': b['category'],
Expand All @@ -39,27 +38,27 @@ def load_blog_list(page, uid=crawler.uid):
'read': b['readCount']
}

blog['content'] = load_blog_content(id, uid)
blog['content'] = load_blog_content(bid, uid)

Blog.insert(**blog).on_conflict('replace').execute()

total_comment = 0
if blog['comment']:
get_comments(id, 'blog', owner=uid)
get_comments(bid, 'blog', owner=uid)
if blog['comment'] or blog['share']:
total_comment = get_comments(id, 'blog', global_comment=True, owner=uid)
total_comment = get_comments(bid, 'blog', global_comment=True, owner=uid)
if blog['like']:
get_likes(id, 'blog')
get_likes(bid, 'blog')

print(u' crawled blog {id} {title} with {comment}/{share}/{like}/{read}, and {total_comment}'.format(
id=id,
print(u' crawled blog {bid} {title} with {comment}/{share}/{like}/{read}'.format(
bid=bid,
title=blog['title'],
comment=blog['comment'],
share=blog['share'],
like=blog['like'],
read=blog['read'],
total_comment=total_comment
read=blog['read']
))
print(u' and total comments {total_comment}'.format(total_comment=total_comment))

return r['count']

Expand Down
Loading

0 comments on commit 5aa565c

Please sign in to comment.