Beispiel #1
0
def main():
    import time
    from InstagramAPI.InstagramAPI import InstagramAPI
    username = input("Give username: \t")
    password = input("Give password: \t")
    hashtag = input("Give hashtag: \t")

    api = InstagramAPI(username, password)
    api.login()

    feed = api.getHashtagFeed(hashtag, maxid='')
    results = api.LastJson

    while True:
        try:
            next_max_id = results["next_max_id"]
        except:
            next_max_id = None
        for r in results["items"]:
            like = api.like(r["id"])
        if next_max_id:
            feed = api.getHashtagFeed(hashtag, maxid=next_max_id)
            results = api.LastJson
        else:
            print("All Images liked. Bye!")
            quit()
def index(request):
    api = InstagramAPI("jayabal.al", "jayabal9890@insta")
    if (api.login()):
        api.getSelfUserFeed()
        return JsonResponse(api.LastJson)

    return JsonResponse({})
Beispiel #3
0
def hope(bot, update):
    global likes_no
    global post_links
    global likes
    a = update.message.text
    username = a[1:a.find(",")]
    range = int(a[a.find(",") + 1:])
    req = requests.get("{}{}".format(instagram_link, username))
    if '200' not in str(req.status_code):
        bot.send_message(chat_id=update.message.chat_id, text="There is no Username with @{} on Instagram".format(username))
    elif "is_private\":true" in str(req.content):
        bot.send_message(chat_id=update.message.chat_id, text="{} is private! @{}".format(msg['text'][1:], msg["from"]["username"]))
    elif not(range <= 9 and range >= 0):
        bot.send_message(chat_id=update.message.chat_id, text="Please use Numbers between 1 to 9")
    else:
        bot.send_message(chat_id=update.message.chat_id, text="Recevied @{} from @{}".format(username, update.message.from_user["username"]))
        API = InstagramAPI(USERNAME, PASSWORD)
        API.login()

        API.searchUsername(username)
        username_id = API.LastJson["user"]["pk"]
        l = API.getTotalUserFeed(username_id)

        ii = 0
        while ii < len(l):
            likes_no.update({str(l[ii]["like_count"]): int(ii)})
            likes.append(l[int(ii)]["like_count"])
            ii = ii + 1

        tt = 0
        while tt < range:
            max_like = max(likes)
            max_liked_no = likes_no[str(max_like)]
            post_links.update({"https://www.instagram.com/p/{}".format((l[max_liked_no])["code"]): max_like})
            likes.remove(max_like)
            tt = tt + 1

        for b in post_links:
            like = post_links[b]
            bot.sendMessage(chat_id=update.message.chat_id, text="Post Link: {}\nLikes: {}".format(b, like), disable_web_page_preview=True)

        API.logout()
        likes_no.clear()
        post_links.clear()
        likes.clear()
        print("Logout success!")
Beispiel #4
0
def top_post(bot, update, args):
    likes_no = {}
    post_links = {}
    likes = []

    # Google sheets for Storing the Chat ID of every new Telegram user who press start
    scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
    credentials = ServiceAccountCredentials.from_json_keyfile_name("toppostbot.json", scope)
    gc = gspread.authorize(credentials)
    wks = gc.open("test2").worksheet("Subscribed Users")

    chat_id = update.message.chat_id
    a = args

    if str(chat_id) in wks.col_values(1) or int(chat_id) in admins and len(args) == 2:
        username = (a[0].replace(',','')).replace('@',"")
        range = int(a[1].replace(',',''))
        print("{}{}".format(instagram_link, username))
        req = requests.get("{}{}".format(instagram_link, username))
        if '200' not in str(req.status_code):
            bot.send_message(chat_id=update.message.chat_id, text="There is no Username with @{} on Instagram".format(username))
        elif "is_private\":true" in str(req.content):
            bot.send_message(chat_id=update.message.chat_id, text="{} is private! @{}".format(username, update.message.from_user["username"]))
        elif not(range <= 25 and range >= 1):
            bot.send_message(chat_id=update.message.chat_id, text="Please use Numbers between 1 to 25")
        else:
            bot.send_message(chat_id=update.message.chat_id, text="Recevied @{} from @{}".format(username, update.message.from_user["username"]))
            API = InstagramAPI(USERNAME, PASSWORD)
            API.login()

            API.searchUsername(username)
            username_id = API.LastJson["user"]["pk"]
            l = API.getTotalUserFeed(username_id)

            ii = 0
            while ii < len(l):
                likes_no.update({str(l[ii]["like_count"]): int(ii)})
                likes.append(l[int(ii)]["like_count"])
                ii = ii + 1

            tt = 0
            while tt < range:
                max_like = max(likes)
                max_liked_no = likes_no[str(max_like)]
                post_links.update({"https://www.instagram.com/p/{}".format((l[max_liked_no])["code"]): max_like})
                likes.remove(max_like)
                tt = tt + 1

            for b in post_links:
                like = post_links[b]
                bot.send_message(chat_id=update.message.chat_id, text="Post Link: {}\nLikes: {}".format(b, like), disable_web_page_preview=True)

            API.logout()
            likes_no.clear()
            post_links.clear()
            likes.clear()
            print("Logout success!")
    elif str(chat_id) in wks.col_values(1) or int(chat_id) in admins and len(args) != 2:
        update.message.reply_text("Your format seems to be wrong use /help to know the right format")
    elif str(chat_id) not in wks.col_values(1) or int(chat_id) not in str(admins):
        update.message.reply_text("Use this bot to get the Top Posts by an Instagram user!!\nContact @mentalgain for more...")
Beispiel #5
0
def date_insta_top_posts(bot, update, args):
    likes_no = []
    post_links = []
    likes = []
    timestamps = [] #np.array([])
    level = {}

    # Google sheets for Storing the Chat ID of every new Telegram user who press start
    scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
    credentials = ServiceAccountCredentials.from_json_keyfile_name("toppostbot.json", scope)
    gc = gspread.authorize(credentials)
    wks = gc.open("test2").worksheet("Subscribed Users")

    chat_id = update.message.chat_id
    a = args

    if str(chat_id) in wks.col_values(1) or int(chat_id) in admins and len(a) == 4:
        username = (a[0].replace(',','')).replace('@',"")
        range = int(a[1].replace(',',''))
        date1 = (str(a[2]).replace(',','')).replace(" ","")
        date2 = (str(a[3]).replace(',','')).replace(" ","")
        A = int(time.mktime(datetime.datetime.strptime(date1, "%d/%m/%Y").timetuple()))
        B = int(time.mktime(datetime.datetime.strptime(date2, "%d/%m/%Y").timetuple()))
        # primary == smallest
        # secondary == biggest
        print("{}{}".format(instagram_link, username))
        req = requests.get("{}{}".format(instagram_link, username))
        # if "{} {}".format(a[2],a[3]).count("/") == 4:
        if date_validation(date1) == False:
            update.message.reply_text(text="Your First date isn't in Right Format or is not a Valid Date\nDate Format: `DD/MM/YYYY`", parse_mode='MARKDOWN')
        elif date_validation(date2) == False:
            update.message.reply_text(text="Your second date isn't in Right Format or is not a Valid Date\nDate Format: `DD/MM/YYYY`", parse_mode='MARKDOWN')
        elif A == B:
            update.message.reply_text(text="Both of your date are same.\nPlease put two different date")
        elif "{} {}".format(a[2],a[3]).count("/") != 4:
            update.message.reply_text(text="Your date format is wrong\nDate Format: `DD/MM/YYYY`", parse_mode='MARKDOWN')
        elif '200' not in str(req.status_code):
            bot.send_message(chat_id=update.message.chat_id, text="There is no Username with @{} on Instagram".format(username))
        elif "is_private\":true" in str(req.content):
            bot.send_message(chat_id=update.message.chat_id, text="{} is private! @{}".format(a, update.message.from_user["username"]))
        elif not(range <= 25 and range >= 1):
            bot.send_message(chat_id=update.message.chat_id, text="Please use Numbers between 1 to 9")
        else:
            if A > B:
                primary = B
                secondary = A
            elif A < B:
                primary = A
                secondary = B
            bot.send_message(chat_id=update.message.chat_id, text="Recevied @{} from @{}".format(username, update.message.from_user["username"]))
            API = InstagramAPI(USERNAME, PASSWORD)
            API.login()

            API.searchUsername(username)
            username_id = API.LastJson["user"]["pk"]
            l = API.getTotalUserFeed(username_id)

            ii = 0
            while ii < len(l):
                # np.append(timestamps, l[ii]["taken_at"])
                timestamps.append(l[ii]["taken_at"])
                ii = ii + 1

            secondy = timestamps.index((min(timestamps, key=lambda x:abs(x-primary))))
            first = timestamps.index((min(timestamps, key=lambda x:abs(x-secondary))))

            tt = int(first)
            while tt < secondy:
                # likes_no.update({str(l[tt]["like_count"]): int(tt)})
                likes_no.append([str(l[tt]["like_count"]), int(tt)])
                # print(str(l[tt]["like_count"]))
                likes.append(l[int(tt)]["like_count"])
                
                tt = tt + 1
            print(likes)

            bot.send_message(chat_id=update.message.chat_id, text="From {} to {} there are only {} posts out of {} posts".format(date1, date2, len(likes), len(timestamps)))

            if range > len(likes):
                range = len(likes)

            ss = 0
            while ss < range:
                max_like = str(max(likes))
                maxed_like = likes.index(int(max_like))
                max_liked_no = likes_no[int(maxed_like)][1]
                post_links.append(["https://www.instagram.com/p/{}".format((l[max_liked_no])["code"]), max_like])
                likes.pop(maxed_like)
                likes_no.pop(maxed_like)
                ss = ss + 1

            for b in post_links:
                like = b[1]
                post_linked = b[0]
                bot.sendMessage(chat_id=update.message.chat_id, text="Post Link: {}\nLikes: {}".format(post_linked, like), disable_web_page_preview=True)
                # print("Post Link: {}\nLikes: {}".format(b[0], like))

            API.logout()
            likes_no.clear
            post_links.clear
            likes.clear
            timestamps.clear #np.array([])
            level.clear
            print("Logout success!")
    elif str(chat_id) in wks.col_values(1) or int(chat_id) in admins and len(a) != 4:
        update.message.reply_text("Your format seems to be wrong use /help to know the right format")
    elif str(chat_id) not in wks.col_values(1) or int(chat_id) not in admins:
        update.message.reply_text("Use this bot to get the Top Posts by an Instagram user!!\nContact @mentalgain for more...")
Beispiel #6
0
def instagram_api(request):
  api = InstagramAPI(request.GET.get('username','yogalola22'), request.GET.get('password','yoga12345'))
  api.login()
  return api
Beispiel #7
0
# -*- coding: utf-8 -*-
#
# Use text editor to edit the script and type in valid Instagram username/password

from InstagramAPI.InstagramAPI import InstagramAPI
import time
from datetime import datetime

media_id = '1477006830906870775_19343908'

# stop conditions, the script will end when first of them will be true
until_date = '2017-03-31'
count = 100

API = InstagramAPI("jayabal.al", "jayabal9890@insta")
API.login()
API.getUsernameInfo()
has_more_comments = True
max_id = ''
comments = []

while has_more_comments:
    _ = API.getMediaComments(media_id, max_id=max_id)
    # comments' page come from older to newer, lets preserve desc order in full list
    for c in reversed(API.LastJson['comments']):
        comments.append(c)
    has_more_comments = API.LastJson.get('has_more_comments', False)
    # evaluate stop conditions
    if count and len(comments) >= count:
        comments = comments[:count]
        # stop loop
Beispiel #8
0
def main():

    # choose post dictionary
    post_dictionary = dictionaries.choose_dictionary()

    # acquire all new content from dictionary, fill queue for posting
    xx.acquire_all(post_dictionary['dict'])

    # login to session throigh instagram api
    print('input username')
    IGUSER = input()
    #
    #
    print('input password')
    # # PASSWD = input()
    PASSWD = getpass.getpass()

    # call to api
    igapi = InstagramAPI(IGUSER, PASSWD)

    # start the mongo client, access the posts database
    client = pymongo.MongoClient()
    db = client.post_database
    posts = db.posts

    # print('test printing post')
    # pprint.pprint(posts.find_one())

    # q = fill_queue(q)
    with open("post_map", "r") as f:
        map_content = f.readlines()

    # print(map_content)
    for x in map_content:
        # print('x : ', x)
        # y = x.clone()
        y = copy.copy(x)
        y = y.replace("\n", "")
        q.put(ObjectId(y))
        post_queue.put(posts.find_one(ObjectId(y)))
        # print(q.get())

    i = 0
    igapi.login()  # login

    while not post_queue.empty():
        # print(q.get())
        # print(post_queue.get())

        entry_filter = str(q.get())

        # remove the dequeued() entry from the list
        map_content.remove(entry_filter + "\n")  # XXX
        # open the post_map file, and write back the remaining entries
        with open("post_map", "w") as f:  # XXX
            for x in map_content:  # XXX
                f.write(x)  # XXX

        p = post_queue.get()

        print('posting next, #' + str(i))

        tag_lst_builder = []
        i = 0
        while i < len(post_dictionary['tags']):
            tag_lst_builder.append('#' + post_dictionary['tags'][i])
            i += 1

        tags = ' '.join(tag_lst_builder)

        try:
            igapi.uploadPhoto(
                p['image_path'],
                " ∴ " + "Source : @" + p['username'] + " ∴ " + tags)
        except AttributeError:
            print('ig uploading error, probably a video')
            pass

        time.sleep(time_between_posts)

        i += 1

    igapi.logout()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Use text editor to edit the script and type in valid Instagram username/password

from InstagramAPI.InstagramAPI import InstagramAPI

api = InstagramAPI("jayabal.al", "jayabal9890@insta")
if (api.login()):
    api.getSelfUserFeed()  # get self user feed
    print(api.LastJson)  # print last response JSON
    print("Login succes!")
else:
    print("Can't login!")