forked from tmhlsky/Instagram-API-python
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
Empty file.
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,30 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Use text editor to edit the script and type in valid Instagram username/password | ||
|
||
from InstagramAPI import InstagramAPI | ||
from examples.evaluation.evaluation_log import EvaluationLog | ||
from examples.user_followers import getTotalFollowers | ||
|
||
|
||
def evaluate_method(function, parameters, function_name=None): | ||
evaluation_log = EvaluationLog() | ||
evaluation_log.start_log(function_name) | ||
response = function(*parameters) | ||
evaluation_log.end_log(function_name) | ||
|
||
print('response size:', len(response)) | ||
print('number of unique users:', len(set([user['username'] for user in response]))) | ||
print() | ||
|
||
|
||
if __name__ == "__main__": | ||
api = InstagramAPI("username", "password") | ||
api.login() | ||
|
||
# For a user with over 22k followers, use: user_id = '1461295173' | ||
user_id = api.username_id | ||
|
||
evaluate_method(api.getTotalFollowers, [user_id], 'api.getTotalFollowers') | ||
evaluate_method(getTotalFollowers, [api, user_id], 'getTotalFollowers') |
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,37 @@ | ||
from time import time, process_time, strftime, localtime | ||
from datetime import timedelta | ||
|
||
|
||
def time_to_str(elapsed=None): | ||
if elapsed is None: | ||
return strftime("%Y-%m-%d %H:%M:%S", localtime()) | ||
else: | ||
return str(timedelta(seconds=elapsed)) | ||
|
||
|
||
class EvaluationLog(): | ||
|
||
def start_log(self, s="Start Program"): | ||
self.start = time() | ||
self.cpu_start = process_time() | ||
self.log(s) | ||
|
||
def end_log(self, s="End Program"): | ||
self.end = time() | ||
self.cpu_end = process_time() | ||
elapsed_time = self.end - self.start | ||
cpu_time = self.cpu_end - self.cpu_start | ||
self.log(s, time_to_str(elapsed_time), time_to_str(cpu_time)) | ||
|
||
@staticmethod | ||
def log(s, elapsed_time=None, cpu_time=None): | ||
line = "=" * 40 | ||
print(line) | ||
print(time_to_str(), '-', s) | ||
|
||
if elapsed_time: | ||
print("Elapsed time:", elapsed_time) | ||
if cpu_time: | ||
print("CPU time:", cpu_time) | ||
|
||
print(line) |
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