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.
Merge branch 'master' of github.com:LevPasha/Instagram-API-python int…
…o delete_media
- Loading branch information
Showing
8 changed files
with
251 additions
and
11 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Use text editor to edit the script and type in valid Instagram username/password | ||
|
||
import subprocess | ||
|
||
from InstagramAPI import InstagramAPI | ||
|
||
USERNAME = '' | ||
PASSWORD = '' | ||
FILE_PATH = '/path/to/video/file' | ||
PUBLISH_TO_LIVE_FEED = False | ||
SEND_NOTIFICATIONS = False | ||
|
||
api = InstagramAPI(USERNAME, PASSWORD, debug=False) | ||
assert api.login() | ||
|
||
# first you have to create a broadcast - you will receive a broadcast id and an upload url here | ||
assert api.createBroadcast() | ||
broadcast_id = api.LastJson['broadcast_id'] | ||
upload_url = api.LastJson['upload_url'] | ||
|
||
# we now start a boradcast - it will now appear in the live-feed of users | ||
assert api.startBroadcast(broadcast_id, sendNotification=SEND_NOTIFICATIONS) | ||
|
||
ffmpeg_cmd = "ffmpeg -rtbufsize 256M -re -i '{file}' -acodec libmp3lame -ar 44100 -b:a 128k -pix_fmt yuv420p -profile:v baseline -s 720x1280 -bufsize 6000k -vb 400k -maxrate 1500k -deinterlace -vcodec libx264 -preset veryfast -g 30 -r 30 -f flv '{stream_url}'".format( | ||
file=FILE_PATH, | ||
stream_url=upload_url.replace(':443', ':80', ).replace('rtmps://', 'rtmp://'), | ||
) | ||
|
||
print("Hit Ctrl+C to stop broadcast") | ||
try: | ||
subprocess.call(ffmpeg_cmd, shell=True) | ||
except KeyboardInterrupt: | ||
print('Stop Broadcasting') | ||
|
||
assert api.stopBroadcast(broadcast_id) | ||
|
||
print('Finished Broadcast') | ||
|
||
if PUBLISH_TO_LIVE_FEED: | ||
api.addBroadcastToLive(broadcast_id) | ||
print('Added Broadcast to LiveFeed') |
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
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