-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from niuware/development
Add 'comments' example
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from sys import argv | ||
from context import Instpector, endpoints | ||
|
||
def get_timeline(**options): | ||
instpector = Instpector() | ||
if not instpector.login(user=options.get("user"), password=options.get("password")): | ||
return | ||
|
||
timeline = endpoints.factory.create("timeline", instpector) | ||
comments = endpoints.factory.create("comments", instpector) | ||
|
||
for post in timeline.of_user(options.get("target_user_id")): | ||
print(post) | ||
for comment in comments.of_post(post): | ||
print(comment) | ||
### Like a comment: | ||
# comments.like(comment) | ||
### Unlike a comment: | ||
# comments.unlike(comment) | ||
if comment.thread_count > 0: | ||
for thread_comment in comments.of_comment(comment): | ||
print(thread_comment) | ||
|
||
instpector.logout() | ||
|
||
if __name__ == '__main__': | ||
if len(argv) < 6: | ||
print(( | ||
"Missing arguments: " | ||
"--user {user} " | ||
"--password {password} " | ||
"--target_user_id {user_id}" | ||
)) | ||
exit(1) | ||
get_timeline( | ||
user=argv[2], | ||
password=argv[4], | ||
target_user_id=argv[6] | ||
) |